Skip to content

Commit a68f3d6

Browse files
committed
Fix Mac Tests
1 parent e11aeee commit a68f3d6

17 files changed

Lines changed: 200 additions & 69 deletions

cpp/src/arrow/flight/sql/example/sqlite_tables_schema_batch_reader.cc

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,43 @@ Status SqliteTablesWithSchemaBatchReader::ReadNext(std::shared_ptr<RecordBatch>*
6565

6666
auto* string_array = reinterpret_cast<StringArray*>(table_name_array.get());
6767

68-
std::vector<std::shared_ptr<Field>> column_fields;
68+
std::map<std::string, std::vector<std::shared_ptr<Field>>> table_columns_map;
6969
for (int i = 0; i < table_name_array->length(); i++) {
7070
const std::string& table_name = string_array->GetString(i);
71+
table_columns_map[table_name];
72+
}
7173

72-
while (sqlite3_step(schema_statement->GetSqlite3Stmt()) == SQLITE_ROW) {
73-
std::string sqlite_table_name = std::string(reinterpret_cast<const char*>(
74-
sqlite3_column_text(schema_statement->GetSqlite3Stmt(), 0)));
75-
if (sqlite_table_name == table_name) {
76-
const char* column_name = reinterpret_cast<const char*>(
77-
sqlite3_column_text(schema_statement->GetSqlite3Stmt(), 1));
78-
const char* column_type = reinterpret_cast<const char*>(
79-
sqlite3_column_text(schema_statement->GetSqlite3Stmt(), 2));
80-
int nullable = sqlite3_column_int(schema_statement->GetSqlite3Stmt(), 3);
81-
82-
const ColumnMetadata& column_metadata = GetColumnMetadata(
83-
GetSqlTypeFromTypeName(column_type), sqlite_table_name.c_str());
84-
std::shared_ptr<DataType> arrow_type;
85-
auto status = GetArrowType(column_type).Value(&arrow_type);
86-
if (!status.ok()) {
87-
return Status::NotImplemented("Unknown SQLite type '", column_type,
88-
"' for column '", column_name, "' in table '",
89-
table_name, "': ", status);
90-
}
91-
column_fields.push_back(arrow::field(column_name, arrow_type, nullable == 0,
92-
column_metadata.metadata_map()));
74+
while (sqlite3_step(schema_statement->GetSqlite3Stmt()) == SQLITE_ROW) {
75+
std::string table_name = std::string(reinterpret_cast<const char*>(
76+
sqlite3_column_text(schema_statement->GetSqlite3Stmt(), 0)));
77+
78+
if (table_columns_map.contains(table_name)) {
79+
const char* column_name = reinterpret_cast<const char*>(
80+
sqlite3_column_text(schema_statement->GetSqlite3Stmt(), 1));
81+
const char* column_type = reinterpret_cast<const char*>(
82+
sqlite3_column_text(schema_statement->GetSqlite3Stmt(), 2));
83+
int nullable = sqlite3_column_int(schema_statement->GetSqlite3Stmt(), 3);
84+
85+
const ColumnMetadata& column_metadata =
86+
GetColumnMetadata(GetSqlTypeFromTypeName(column_type), table_name.c_str());
87+
88+
std::shared_ptr<DataType> arrow_type;
89+
auto status = GetArrowType(column_type).Value(&arrow_type);
90+
if (!status.ok()) {
91+
return Status::NotImplemented("Unknown SQLite type '", column_type,
92+
"' for column '", column_name, "' in table '",
93+
table_name, "': ", status);
9394
}
95+
table_columns_map[table_name].push_back(arrow::field(
96+
column_name, arrow_type, nullable == 0, column_metadata.metadata_map()));
9497
}
98+
}
99+
100+
std::vector<std::shared_ptr<Field>> column_fields;
101+
for (int i = 0; i < table_name_array->length(); i++) {
102+
const std::string& table_name = string_array->GetString(i);
103+
column_fields = table_columns_map[table_name];
104+
95105
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> schema_buffer,
96106
ipc::SerializeSchema(*arrow::schema(column_fields)));
97107

cpp/src/arrow/flight/sql/odbc/odbc_impl/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ add_library(arrow_odbc_spi_impl
104104
spi/result_set.h
105105
spi/result_set_metadata.h
106106
spi/statement.h
107+
system_dsn.cc
108+
system_dsn.h
107109
system_trust_store.cc
108110
system_trust_store.h
109111
types.h
@@ -125,9 +127,7 @@ if(WIN32)
125127
ui/dsn_configuration_window.h
126128
ui/window.cc
127129
ui/window.h
128-
win_system_dsn.cc
129-
system_dsn.cc
130-
system_dsn.h)
130+
win_system_dsn.cc)
131131
endif()
132132

133133
if(APPLE)

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ void ODBCStatement::SetStmtAttr(SQLINTEGER statement_attribute, SQLPOINTER value
554554
switch (statement_attribute) {
555555
case SQL_ATTR_APP_PARAM_DESC: {
556556
ODBCDescriptor* desc = static_cast<ODBCDescriptor*>(value);
557-
if (current_apd_ != desc) {
557+
if (desc && current_apd_ != desc) {
558558
if (current_apd_ != built_in_apd_.get()) {
559559
current_apd_->DetachFromStatement(this, true);
560560
}
@@ -567,7 +567,7 @@ void ODBCStatement::SetStmtAttr(SQLINTEGER statement_attribute, SQLPOINTER value
567567
}
568568
case SQL_ATTR_APP_ROW_DESC: {
569569
ODBCDescriptor* desc = static_cast<ODBCDescriptor*>(value);
570-
if (current_ard_ != desc) {
570+
if (desc && current_ard_ != desc) {
571571
if (current_ard_ != built_in_ard_.get()) {
572572
current_ard_->DetachFromStatement(this, false);
573573
}

cpp/src/arrow/flight/sql/odbc/odbc_impl/system_dsn.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@
1717

1818
#include "arrow/flight/sql/odbc/odbc_impl/system_dsn.h"
1919

20-
#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
21-
#include "arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.h"
22-
#include "arrow/flight/sql/odbc/odbc_impl/ui/dsn_configuration_window.h"
23-
#include "arrow/flight/sql/odbc/odbc_impl/ui/window.h"
24-
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
2520
#include "arrow/result.h"
2621
#include "arrow/util/utf8.h"
2722

28-
#include <odbcinst.h>
2923
#include <sstream>
3024

3125
namespace arrow::flight::sql::odbc {
3226

3327
using config::Configuration;
3428

35-
void PostError(DWORD error_code, LPCWSTR error_msg) {
29+
void PostError(DWORD error_code, LPWSTR error_msg) {
30+
#if defined _WIN32
3631
MessageBox(NULL, error_msg, L"Error!", MB_ICONEXCLAMATION | MB_OK);
32+
#endif // _WIN32
3733
SQLPostInstallerError(error_code, error_msg);
3834
}
3935

@@ -42,7 +38,7 @@ void PostArrowUtilError(arrow::Status error_status) {
4238
std::wstring werror_msg = arrow::util::UTF8ToWideString(error_msg).ValueOr(
4339
L"Error during utf8 to wide string conversion");
4440

45-
PostError(ODBC_ERROR_GENERAL_ERR, werror_msg.c_str());
41+
PostError(ODBC_ERROR_GENERAL_ERR, (LPWSTR)werror_msg.c_str());
4642
}
4743

4844
void PostLastInstallerError() {
@@ -55,7 +51,7 @@ void PostLastInstallerError() {
5551
buf << L"Message: \"" << msg << L"\", Code: " << code;
5652
std::wstring error_msg = buf.str();
5753

58-
PostError(code, error_msg.c_str());
54+
PostError(code, (LPWSTR)error_msg.c_str());
5955
}
6056

6157
/**

cpp/src/arrow/flight/sql/odbc/odbc_impl/system_dsn.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
2020

2121
#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
22+
#include "arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.h"
2223
#include "arrow/status.h"
2324

25+
#include <odbcinst.h>
26+
2427
namespace arrow::flight::sql::odbc {
2528

2629
#if defined _WIN32
@@ -64,7 +67,7 @@ bool RegisterDsn(const config::Configuration& config, LPCWSTR driver);
6467
*/
6568
bool UnregisterDsn(const std::wstring& dsn);
6669

67-
void PostError(DWORD error_code, LPCWSTR error_msg);
70+
void PostError(DWORD error_code, LPWSTR error_msg);
6871

6972
void PostArrowUtilError(arrow::Status error_status);
7073
} // namespace arrow::flight::sql::odbc

cpp/src/arrow/flight/sql/odbc/odbc_impl/win_system_dsn.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ BOOL INSTAPI ConfigDSNW(HWND hwnd_parent, WORD req, LPCWSTR wdriver,
144144
std::wstring werror_msg =
145145
arrow::util::UTF8ToWideString(error_msg).ValueOr(L"Error during DSN load");
146146

147-
PostError(err.GetNativeError(), werror_msg.c_str());
147+
PostError(err.GetNativeError(), (LPWSTR)werror_msg.c_str());
148148
return FALSE;
149149
}
150150

cpp/src/arrow/flight/sql/odbc/tests/columns_test.cc

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <gtest/gtest.h>
2626

27+
// Many tests are disabled for MacOS due to iODBC limitations.
28+
2729
namespace arrow::flight::sql::odbc {
2830

2931
template <typename T>
@@ -237,6 +239,7 @@ void CheckSQLColAttribute(SQLHSTMT stmt, SQLUSMALLINT idx,
237239
EXPECT_EQ(expected_unsigned_column, unsigned_col);
238240
}
239241

242+
#ifndef __APPLE__
240243
void CheckSQLColAttributes(SQLHSTMT stmt, SQLUSMALLINT idx,
241244
const std::wstring& expected_column_name,
242245
SQLLEN expected_data_type, SQLLEN expected_display_size,
@@ -306,6 +309,7 @@ void CheckSQLColAttributes(SQLHSTMT stmt, SQLUSMALLINT idx,
306309
EXPECT_EQ(expected_searchable, searchable);
307310
EXPECT_EQ(expected_unsigned_column, unsigned_col);
308311
}
312+
#endif // __APPLE__
309313

310314
void GetSQLColAttributeString(SQLHSTMT stmt, const std::wstring& wsql, SQLUSMALLINT idx,
311315
SQLUSMALLINT field_identifier, std::wstring& value) {
@@ -364,6 +368,7 @@ void GetSQLColAttributeNumeric(SQLHSTMT stmt, const std::wstring& wsql, SQLUSMAL
364368
SQLColAttribute(stmt, idx, field_identifier, 0, 0, nullptr, value));
365369
}
366370

371+
#ifndef __APPLE__
367372
void GetSQLColAttributesNumeric(SQLHSTMT stmt, const std::wstring& wsql, SQLUSMALLINT idx,
368373
SQLUSMALLINT field_identifier, SQLLEN* value) {
369374
// Execute query and check SQLColAttribute numeric attribute
@@ -377,7 +382,7 @@ void GetSQLColAttributesNumeric(SQLHSTMT stmt, const std::wstring& wsql, SQLUSMA
377382
ASSERT_EQ(SQL_SUCCESS,
378383
SQLColAttributes(stmt, idx, field_identifier, 0, 0, nullptr, value));
379384
}
380-
385+
#endif // __APPLE__
381386
} // namespace
382387

383388
TYPED_TEST(ColumnsTest, SQLColumnsTestInputData) {
@@ -1387,7 +1392,9 @@ TEST_F(ColumnsMockTest, TestSQLColAttributeAllTypes) {
13871392
SQL_FALSE); // expected_unsigned_column
13881393
}
13891394

1390-
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesAllTypesODBCVer2) {
1395+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
1396+
#ifndef __APPLE__
1397+
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesAllTypes) {
13911398
// Tests ODBC 2.0 API SQLColAttributes
13921399
this->CreateTableAllDataType();
13931400

@@ -1446,6 +1453,7 @@ TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesAllTypesODBCVer2) {
14461453
SQL_PRED_NONE, // expected_searchable
14471454
SQL_FALSE); // expected_unsigned_column
14481455
}
1456+
#endif // __APPLE__
14491457

14501458
TEST_F(ColumnsRemoteTest, TestSQLColAttributeAllTypes) {
14511459
// Test assumes there is a table $scratch.ODBCTest in remote server
@@ -1612,7 +1620,9 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeAllTypes) {
16121620
SQL_TRUE); // expected_unsigned_column
16131621
}
16141622

1615-
TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributeAllTypesODBCVer2) {
1623+
// iODBC does not support SQLColAttribute in ODBC 2.0 mode.
1624+
#ifndef __APPLE__
1625+
TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributeAllTypes) {
16161626
// Test assumes there is a table $scratch.ODBCTest in remote server
16171627
std::wstring wsql = L"SELECT * from $scratch.ODBCTest;";
16181628
std::vector<SQLWCHAR> sql0(wsql.begin(), wsql.end());
@@ -1776,7 +1786,8 @@ TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributeAllTypesODBCVer2) {
17761786
SQL_TRUE); // expected_unsigned_column
17771787
}
17781788

1779-
TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesAllTypesODBCVer2) {
1789+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
1790+
TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesAllTypes) {
17801791
// Tests ODBC 2.0 API SQLColAttributes
17811792
// Test assumes there is a table $scratch.ODBCTest in remote server
17821793
std::wstring wsql = L"SELECT * from $scratch.ODBCTest;";
@@ -1895,6 +1906,7 @@ TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesAllTypesODBCVer2) {
18951906
SQL_SEARCHABLE, // expected_searchable
18961907
SQL_TRUE); // expected_unsigned_column
18971908
}
1909+
#endif // __APPLE__
18981910

18991911
TYPED_TEST(ColumnsTest, TestSQLColAttributeCaseSensitive) {
19001912
// Arrow limitation: returns SQL_FALSE for case sensitive column
@@ -1910,6 +1922,8 @@ TYPED_TEST(ColumnsTest, TestSQLColAttributeCaseSensitive) {
19101922
ASSERT_EQ(SQL_FALSE, value);
19111923
}
19121924

1925+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
1926+
#ifndef __APPLE__
19131927
TYPED_TEST(ColumnsOdbcV2Test, TestSQLColAttributesCaseSensitive) {
19141928
// Arrow limitation: returns SQL_FALSE for case sensitive column
19151929
// Tests ODBC 2.0 API SQLColAttributes
@@ -1924,6 +1938,7 @@ TYPED_TEST(ColumnsOdbcV2Test, TestSQLColAttributesCaseSensitive) {
19241938
GetSQLColAttributesNumeric(this->stmt, wsql, 28, SQL_COLUMN_CASE_SENSITIVE, &value);
19251939
ASSERT_EQ(SQL_FALSE, value);
19261940
}
1941+
#endif // __APPLE__
19271942

19281943
TEST_F(ColumnsMockTest, TestSQLColAttributeUniqueValue) {
19291944
// Mock server limitation: returns false for auto-increment column
@@ -1935,6 +1950,8 @@ TEST_F(ColumnsMockTest, TestSQLColAttributeUniqueValue) {
19351950
ASSERT_EQ(SQL_FALSE, value);
19361951
}
19371952

1953+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
1954+
#ifndef __APPLE__
19381955
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesAutoIncrement) {
19391956
// Tests ODBC 2.0 API SQLColAttributes
19401957
// Mock server limitation: returns false for auto-increment column
@@ -1945,6 +1962,7 @@ TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesAutoIncrement) {
19451962
GetSQLColAttributeNumeric(this->stmt, wsql, 1, SQL_COLUMN_AUTO_INCREMENT, &value);
19461963
ASSERT_EQ(SQL_FALSE, value);
19471964
}
1965+
#endif // __APPLE__
19481966

19491967
TEST_F(ColumnsMockTest, TestSQLColAttributeBaseTableName) {
19501968
this->CreateTableAllDataType();
@@ -1955,6 +1973,8 @@ TEST_F(ColumnsMockTest, TestSQLColAttributeBaseTableName) {
19551973
ASSERT_EQ(std::wstring(L"AllTypesTable"), value);
19561974
}
19571975

1976+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
1977+
#ifndef __APPLE__
19581978
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesTableName) {
19591979
// Tests ODBC 2.0 API SQLColAttributes
19601980
this->CreateTableAllDataType();
@@ -1964,6 +1984,7 @@ TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesTableName) {
19641984
GetSQLColAttributesString(this->stmt, wsql, 1, SQL_COLUMN_TABLE_NAME, value);
19651985
ASSERT_EQ(std::wstring(L"AllTypesTable"), value);
19661986
}
1987+
#endif // __APPLE__
19671988

19681989
TEST_F(ColumnsMockTest, TestSQLColAttributeCatalogName) {
19691990
// Mock server limitattion: mock doesn't return catalog for result metadata,
@@ -1985,6 +2006,8 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeCatalogName) {
19852006
ASSERT_EQ(std::wstring(L""), value);
19862007
}
19872008

2009+
// iODBC does not support SQLColAttribute in ODBC 2.0 mode.
2010+
#ifndef __APPLE__
19882011
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesQualifierName) {
19892012
// Mock server limitattion: mock doesn't return catalog for result metadata,
19902013
// and the defautl catalog should be 'main'
@@ -2005,6 +2028,7 @@ TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesQualifierName) {
20052028
GetSQLColAttributeString(this->stmt, wsql, 1, SQL_COLUMN_QUALIFIER_NAME, value);
20062029
ASSERT_EQ(std::wstring(L""), value);
20072030
}
2031+
#endif // __APPLE__
20082032

20092033
TYPED_TEST(ColumnsTest, TestSQLColAttributeCount) {
20102034
std::wstring wsql = this->GetQueryAllDataTypes();
@@ -2050,6 +2074,8 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeSchemaName) {
20502074
ASSERT_EQ(std::wstring(L""), value);
20512075
}
20522076

2077+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
2078+
#ifndef __APPLE__
20532079
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesOwnerName) {
20542080
// Tests ODBC 2.0 API SQLColAttributes
20552081
this->CreateTableAllDataType();
@@ -2071,6 +2097,7 @@ TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesOwnerName) {
20712097
GetSQLColAttributesString(this->stmt, wsql, 1, SQL_COLUMN_OWNER_NAME, value);
20722098
ASSERT_EQ(std::wstring(L""), value);
20732099
}
2100+
#endif // __APPLE__
20742101

20752102
TEST_F(ColumnsMockTest, TestSQLColAttributeTableName) {
20762103
this->CreateTableAllDataType();
@@ -2119,6 +2146,8 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeTypeName) {
21192146
ASSERT_EQ(std::wstring(L"TIMESTAMP"), value);
21202147
}
21212148

2149+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
2150+
#ifndef __APPLE__
21222151
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesTypeName) {
21232152
// Tests ODBC 2.0 API SQLColAttributes
21242153
this->CreateTableAllDataType();
@@ -2159,6 +2188,7 @@ TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesTypeName) {
21592188
GetSQLColAttributesString(this->stmt, L"", 9, SQL_COLUMN_TYPE_NAME, value);
21602189
ASSERT_EQ(std::wstring(L"TIMESTAMP"), value);
21612190
}
2191+
#endif // __APPLE__
21622192

21632193
TYPED_TEST(ColumnsTest, TestSQLColAttributeUnnamed) {
21642194
std::wstring wsql = this->GetQueryAllDataTypes();
@@ -2175,6 +2205,8 @@ TYPED_TEST(ColumnsTest, TestSQLColAttributeUpdatable) {
21752205
ASSERT_EQ(SQL_ATTR_READWRITE_UNKNOWN, value);
21762206
}
21772207

2208+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
2209+
#ifndef __APPLE__
21782210
TYPED_TEST(ColumnsOdbcV2Test, TestSQLColAttributesUpdatable) {
21792211
// Tests ODBC 2.0 API SQLColAttributes
21802212
std::wstring wsql = this->GetQueryAllDataTypes();
@@ -2183,6 +2215,7 @@ TYPED_TEST(ColumnsOdbcV2Test, TestSQLColAttributesUpdatable) {
21832215
GetSQLColAttributesNumeric(this->stmt, wsql, 1, SQL_COLUMN_UPDATABLE, &value);
21842216
ASSERT_EQ(SQL_ATTR_READWRITE_UNKNOWN, value);
21852217
}
2218+
#endif // __APPLE__
21862219

21872220
TEST_F(ColumnsMockTest, SQLDescribeColValidateInput) {
21882221
this->CreateTestTables();

0 commit comments

Comments
 (0)