Skip to content

Commit 3556804

Browse files
committed
Fix tests on Mac
fixes
1 parent 2fba6a7 commit 3556804

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

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/tests/columns_test.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424

2525
#include <gtest/gtest.h>
2626

27-
// Many tests are disabled for MacOS due to iODBC limitations with ODBC 2.0 APIs and
28-
// identifiers such as SQLColAttributes, SQL_COLUMN_AUTO_INCREMENT,
29-
// SQL_COLUMN_QUALIFIER_NAME.
27+
// Many tests are disabled for MacOS due to iODBC limitations.
3028

3129
namespace arrow::flight::sql::odbc {
3230

@@ -241,6 +239,7 @@ void CheckSQLColAttribute(SQLHSTMT stmt, SQLUSMALLINT idx,
241239
EXPECT_EQ(expected_unsigned_column, unsigned_col);
242240
}
243241

242+
#ifndef __APPLE__
244243
void CheckSQLColAttributes(SQLHSTMT stmt, SQLUSMALLINT idx,
245244
const std::wstring& expected_column_name,
246245
SQLLEN expected_data_type, SQLLEN expected_display_size,
@@ -310,6 +309,7 @@ void CheckSQLColAttributes(SQLHSTMT stmt, SQLUSMALLINT idx,
310309
EXPECT_EQ(expected_searchable, searchable);
311310
EXPECT_EQ(expected_unsigned_column, unsigned_col);
312311
}
312+
#endif // __APPLE__
313313

314314
void GetSQLColAttributeString(SQLHSTMT stmt, const std::wstring& wsql, SQLUSMALLINT idx,
315315
SQLUSMALLINT field_identifier, std::wstring& value) {
@@ -1392,6 +1392,7 @@ TEST_F(ColumnsMockTest, TestSQLColAttributeAllTypes) {
13921392
SQL_FALSE); // expected_unsigned_column
13931393
}
13941394

1395+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
13951396
#ifndef __APPLE__
13961397
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesAllTypes) {
13971398
// Tests ODBC 2.0 API SQLColAttributes
@@ -1619,6 +1620,8 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeAllTypes) {
16191620
SQL_TRUE); // expected_unsigned_column
16201621
}
16211622

1623+
// iODBC does not support SQLColAttribute in ODBC 2.0 mode.
1624+
#ifndef __APPLE__
16221625
TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributeAllTypesODBCVer2) {
16231626
// Test assumes there is a table $scratch.ODBCTest in remote server
16241627
std::wstring wsql = L"SELECT * from $scratch.ODBCTest;";
@@ -1783,6 +1786,7 @@ TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributeAllTypesODBCVer2) {
17831786
SQL_TRUE); // expected_unsigned_column
17841787
}
17851788

1789+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
17861790
TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesAllTypesODBCVer2) {
17871791
// Tests ODBC 2.0 API SQLColAttributes
17881792
// Test assumes there is a table $scratch.ODBCTest in remote server
@@ -1902,6 +1906,7 @@ TEST_F(ColumnsOdbcV2RemoteTest, TestSQLColAttributesAllTypesODBCVer2) {
19021906
SQL_SEARCHABLE, // expected_searchable
19031907
SQL_TRUE); // expected_unsigned_column
19041908
}
1909+
#endif // __APPLE__
19051910

19061911
TYPED_TEST(ColumnsTest, TestSQLColAttributeCaseSensitive) {
19071912
// Arrow limitation: returns SQL_FALSE for case sensitive column
@@ -1917,6 +1922,7 @@ TYPED_TEST(ColumnsTest, TestSQLColAttributeCaseSensitive) {
19171922
ASSERT_EQ(SQL_FALSE, value);
19181923
}
19191924

1925+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
19201926
#ifndef __APPLE__
19211927
TYPED_TEST(ColumnsOdbcV2Test, TestSQLColAttributesCaseSensitive) {
19221928
// Arrow limitation: returns SQL_FALSE for case sensitive column
@@ -1944,6 +1950,7 @@ TEST_F(ColumnsMockTest, TestSQLColAttributeUniqueValue) {
19441950
ASSERT_EQ(SQL_FALSE, value);
19451951
}
19461952

1953+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
19471954
#ifndef __APPLE__
19481955
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesAutoIncrement) {
19491956
// Tests ODBC 2.0 API SQLColAttributes
@@ -1966,6 +1973,7 @@ TEST_F(ColumnsMockTest, TestSQLColAttributeBaseTableName) {
19661973
ASSERT_EQ(std::wstring(L"AllTypesTable"), value);
19671974
}
19681975

1976+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
19691977
#ifndef __APPLE__
19701978
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesTableName) {
19711979
// Tests ODBC 2.0 API SQLColAttributes
@@ -1998,6 +2006,7 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeCatalogName) {
19982006
ASSERT_EQ(std::wstring(L""), value);
19992007
}
20002008

2009+
// iODBC does not support SQLColAttribute in ODBC 2.0 mode.
20012010
#ifndef __APPLE__
20022011
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesQualifierName) {
20032012
// Mock server limitattion: mock doesn't return catalog for result metadata,
@@ -2065,6 +2074,7 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeSchemaName) {
20652074
ASSERT_EQ(std::wstring(L""), value);
20662075
}
20672076

2077+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
20682078
#ifndef __APPLE__
20692079
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesOwnerName) {
20702080
// Tests ODBC 2.0 API SQLColAttributes
@@ -2136,6 +2146,7 @@ TEST_F(ColumnsRemoteTest, TestSQLColAttributeTypeName) {
21362146
ASSERT_EQ(std::wstring(L"TIMESTAMP"), value);
21372147
}
21382148

2149+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
21392150
#ifndef __APPLE__
21402151
TEST_F(ColumnsOdbcV2MockTest, TestSQLColAttributesTypeName) {
21412152
// Tests ODBC 2.0 API SQLColAttributes
@@ -2194,6 +2205,7 @@ TYPED_TEST(ColumnsTest, TestSQLColAttributeUpdatable) {
21942205
ASSERT_EQ(SQL_ATTR_READWRITE_UNKNOWN, value);
21952206
}
21962207

2208+
// iODBC does not support SQLColAttributes for ODBC 3.0 attributes.
21972209
#ifndef __APPLE__
21982210
TYPED_TEST(ColumnsOdbcV2Test, TestSQLColAttributesUpdatable) {
21992211
// Tests ODBC 2.0 API SQLColAttributes

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,15 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrQuietModeReadOnly) {
104104
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY092);
105105
}
106106

107+
// iODBC needs to be compiled with tracing enabled to handle SQL_ATTR_TRACE
108+
#ifndef __APPLE__
107109
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTraceDMOnly) {
108110
// Verify DM-only attribute is settable via Driver Manager
109111
ASSERT_EQ(SQL_SUCCESS,
110112
SQLSetConnectAttr(this->conn, SQL_ATTR_TRACE,
111113
reinterpret_cast<SQLPOINTER>(SQL_OPT_TRACE_OFF), 0));
112114
}
115+
#endif // __APPLE__
113116

114117
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTracefileDMOnly) {
115118
// Verify DM-only attribute is handled by Driver Manager
@@ -120,14 +123,22 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTracefileDMOnly) {
120123
std::vector<SQLWCHAR> trace_file0(trace_file.begin(), trace_file.end());
121124
ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_TRACEFILE, &trace_file0[0],
122125
static_cast<SQLINTEGER>(trace_file0.size())));
126+
#ifdef __APPLE__
127+
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
128+
#else
123129
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY000);
130+
#endif // __APPLE__
124131
}
125132

126133
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTranslateLabDMOnly) {
127134
// Verify DM-only attribute is handled by Driver Manager
128135
ASSERT_EQ(SQL_ERROR, SQLSetConnectAttr(this->conn, SQL_ATTR_TRANSLATE_LIB, 0, 0));
129136
// Checks for invalid argument return error
137+
#ifdef __APPLE__
138+
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHYC00);
139+
#else
130140
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorStateHY024);
141+
#endif // __APPLE__
131142
}
132143

133144
TYPED_TEST(ConnectionAttributeTest, TestSQLSetConnectAttrTranslateOptionUnsupported) {
@@ -152,6 +163,8 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrDbcInfoTokenSetOnly) {
152163
}
153164
#endif
154165

166+
// iODBC does not treat SQL_ATTR_ODBC_CURSORS as DM-only
167+
#ifndef __APPLE__
155168
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrOdbcCursorsDMOnly) {
156169
// Verify that DM-only attribute is handled by driver manager
157170
SQLULEN cursor_attr;
@@ -160,6 +173,7 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrOdbcCursorsDMOnly) {
160173
EXPECT_EQ(SQL_CUR_USE_DRIVER, cursor_attr);
161174
}
162175

176+
// iODBC needs to be compiled with tracing enabled to handle SQL_ATTR_TRACE
163177
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceDMOnly) {
164178
// Verify that DM-only attribute is handled by driver manager
165179
SQLUINTEGER trace;
@@ -168,6 +182,7 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceDMOnly) {
168182
EXPECT_EQ(SQL_OPT_TRACE_OFF, trace);
169183
}
170184

185+
// iODBC needs to be compiled with tracing enabled to handle SQL_ATTR_TRACEFILE
171186
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceFileDMOnly) {
172187
// Verify that DM-only attribute is handled by driver manager
173188
SQLWCHAR out_str[kOdbcBufferSize];
@@ -181,6 +196,7 @@ TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTraceFileDMOnly) {
181196
ODBC::SqlWcharToString(out_str, static_cast<SQLSMALLINT>(out_str_len));
182197
EXPECT_FALSE(out_connection_string.empty());
183198
}
199+
#endif // __APPLE__
184200

185201
TYPED_TEST(ConnectionAttributeTest, TestSQLGetConnectAttrTranslateLibUnsupported) {
186202
SQLWCHAR out_str[kOdbcBufferSize];

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,18 @@ void GetInfo(SQLHDBC connection, SQLUSMALLINT info_type, SQLWCHAR* value,
6767
}
6868
} // namespace
6969

70-
// Test disabled until we resolve bus error on MacOS
71-
#ifdef DISABLE_TEST
7270
TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoTruncation) {
7371
static constexpr int info_len = 1;
7472
SQLWCHAR value[info_len] = L"";
7573
SQLSMALLINT message_length;
7674

7775
ASSERT_EQ(SQL_SUCCESS_WITH_INFO,
78-
SQLGetInfo(this->conn, SQL_KEYWORDS, value, info_len, &message_length));
76+
SQLGetInfo(this->conn, SQL_INTEGRITY, value, info_len, &message_length));
7977

8078
// Verify string truncation is reported
8179
VerifyOdbcErrorState(SQL_HANDLE_DBC, this->conn, kErrorState01004);
8280
EXPECT_GT(message_length, 0);
8381
}
84-
#endif
8582

8683
// Driver Information
8784

@@ -792,17 +789,14 @@ TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoIntegrity) {
792789
EXPECT_STREQ(static_cast<const SQLWCHAR*>(L"N"), value);
793790
}
794791

795-
// Test disabled until we resolve bus error on MacOS
796-
#ifdef DISABLE_TEST
797792
TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoKeywords) {
798-
// Keyword strings can require 5000 buffer length
799-
static constexpr int info_len = kOdbcBufferSize * 5;
793+
// Keyword strings can require 10000 buffer length
794+
static constexpr int info_len = kOdbcBufferSize * 10;
800795
SQLWCHAR value[info_len] = L"";
801796
GetInfo(this->conn, SQL_KEYWORDS, value, info_len);
802797

803798
EXPECT_GT(wcslen(value), 0);
804799
}
805-
#endif
806800

807801
TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoLikeEscapeClause) {
808802
SQLWCHAR value[kOdbcBufferSize] = L"";

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ TYPED_TEST(ErrorsHandleTest, DISABLED_TestSQLGetDiagFieldWForConnectFailureNTS)
160160
EXPECT_GT(message_text_length, 100);
161161
}
162162

163+
// iODBC does not support application allocated descriptors.
164+
#ifndef __APPLE__
163165
TYPED_TEST(ErrorsTest, TestSQLGetDiagFieldWForDescriptorFailureFromDriverManager) {
164166
SQLHDESC descriptor;
165167

@@ -256,6 +258,7 @@ TYPED_TEST(ErrorsTest, TestSQLGetDiagRecForDescriptorFailureFromDriverManager) {
256258
// Free descriptor handle
257259
EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_DESC, descriptor));
258260
}
261+
#endif // __APPLE__
259262

260263
TYPED_TEST(ErrorsHandleTest, TestSQLGetDiagRecForConnectFailure) {
261264
// Invalid connect string

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,13 @@ class FlightSQLOdbcEnvConnHandleMockTestBase : public FlightSQLODBCMockTestBase
206206
};
207207

208208
/** ODBC read buffer size. */
209+
#ifdef __APPLE__
210+
// iODBC driver manager may crash with smaller buffer sizes
211+
// so we use a larger buffer on MacOS
212+
static constexpr int kOdbcBufferSize = 2048;
213+
#else
209214
static constexpr int kOdbcBufferSize = 1024;
215+
#endif // __APPLE__
210216

211217
/// Compare ConnPropertyMap, key value is case-insensitive
212218
bool CompareConnPropertyMap(Connection::ConnPropertyMap map1,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ TYPED_TEST(StatementAttributeTest, TestSQLGetStmtAttrRowsetSize) {
391391
EXPECT_EQ(static_cast<SQLULEN>(1), value);
392392
}
393393

394-
TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAppParamDescSegFault) {
394+
TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAppParamDesc) {
395395
SQLULEN app_param_desc = 0;
396396
SQLINTEGER string_length_ptr;
397397

@@ -404,7 +404,7 @@ TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAppParamDescSegFault) {
404404
static_cast<SQLULEN>(app_param_desc));
405405
}
406406

407-
TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAppRowDescSegFault) {
407+
TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrAppRowDesc) {
408408
SQLULEN app_row_desc = 0;
409409
SQLINTEGER string_length_ptr;
410410

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ TYPED_TEST(StatementTest, TestSQLExecDirectRowFetching) {
824824
#ifdef __APPLE__
825825
// With iODBC we expect SQL_SUCCESS and the buffer unchanged in this situation.
826826
ASSERT_EQ(SQL_SUCCESS, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, nullptr));
827-
EXPECT_EQ(1, val);
827+
EXPECT_EQ(3, val);
828828
#else
829829
ASSERT_EQ(SQL_ERROR, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, &ind));
830830
// Invalid cursor state
@@ -888,7 +888,7 @@ TYPED_TEST(StatementTest, TestSQLFetchScrollRowFetching) {
888888
#ifdef __APPLE__
889889
// With iODBC we expect SQL_SUCCESS and the buffer unchanged in this situation.
890890
ASSERT_EQ(SQL_SUCCESS, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, nullptr));
891-
EXPECT_EQ(1, val);
891+
EXPECT_EQ(3, val);
892892
#else
893893
ASSERT_EQ(SQL_ERROR, SQLGetData(this->stmt, 1, SQL_C_LONG, &val, 0, &ind));
894894
// Invalid cursor state

0 commit comments

Comments
 (0)