Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

ODBC: Remove catalog support from driver #566

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions sql-odbc/src/IntegrationTests/ITODBCCatalog/test_odbc_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,20 @@ typedef struct bind_info {

// Column test constants and macro
const std::vector< std::string > flights_column_name = {
"FlightNum", "Origin",
"FlightDelay", "DistanceMiles", "FlightTimeMin", "OriginWeather",
"dayOfWeek", "AvgTicketPrice", "Carrier", "FlightDelayMin",
"OriginRegion", "DestAirportID", "FlightDelayType", "timestamp",
"Dest", "FlightTimeHour", "Cancelled", "DistanceKilometers",
"OriginCityName", "DestWeather", "OriginCountry", "DestCountry",
"DestRegion", "DestCityName", "OriginAirportID"};
"FlightNum", "Origin", "FlightDelay",
"DistanceMiles", "FlightTimeMin", "OriginWeather",
"dayOfWeek", "AvgTicketPrice", "Carrier",
"FlightDelayMin", "OriginRegion", "DestAirportID",
"FlightDelayType", "timestamp", "Dest",
"FlightTimeHour", "Cancelled", "DistanceKilometers",
"OriginCityName", "DestWeather", "OriginCountry",
"DestCountry", "DestRegion", "DestCityName",
"OriginAirportID"};
const std::vector< std::string > flights_data_type = {
"keyword", "keyword", "boolean", "float",
"float", "keyword", "integer", "float", "keyword", "integer",
"keyword", "keyword", "keyword", "date", "keyword", "keyword",
"boolean", "float", "keyword", "keyword", "keyword", "keyword",
"keyword", "keyword", "keyword"};
"keyword", "keyword", "boolean", "float", "float", "keyword", "integer",
"float", "keyword", "integer", "keyword", "keyword", "keyword", "date",
"keyword", "keyword", "boolean", "float", "keyword", "keyword", "keyword",
"keyword", "keyword", "keyword", "keyword"};
const std::string flights_catalog_odfe = "odfe-cluster";
const std::string flights_catalog_elas = "elasticsearch";
const std::string flights_table_name = "kibana_sample_data_flights";
Expand Down Expand Up @@ -157,9 +158,6 @@ const std::vector< table_data > excel_table_data_all{
};
const std::vector< table_data > table_data_types{
{"", "", "", "BASE TABLE", ""}};
const std::vector< table_data > table_data_schemas{{"", "", "", "", ""}};
const std::vector< table_data > table_data_catalogs{
{"odfe-cluster", "", "", "", ""}};

class TestSQLTables : public testing::Test {
public:
Expand Down Expand Up @@ -229,9 +227,10 @@ void CheckTableData(SQLHSTMT m_hstmt,
TEST_F(TestSQLTables, test_name) { \
EXPECT_EQ(SQL_SUCCESS, SQLSetStmtAttr(m_hstmt, SQL_ATTR_METADATA_ID, \
(void*)(!enable_pattern), 0)); \
EXPECT_TRUE(SQL_SUCCEEDED(SQLTables(m_hstmt, catalog, SQL_NTS, schema, \
SQLRETURN ret2 = SQLTables(m_hstmt, catalog, SQL_NTS, schema, \
SQL_NTS, table, SQL_NTS, \
table_type, SQL_NTS))); \
table_type, SQL_NTS); \
LogAnyDiagnostics(SQL_HANDLE_STMT, m_hstmt, ret2); \
if (empty) { \
size_t result_count = 0; \
SQLRETURN ret; \
Expand Down Expand Up @@ -280,13 +279,21 @@ class TestSQLCatalogKeys : public testing::Test {
// NULL test
TEST_SQL_TABLES(Null, NULL, NULL, NULL, NULL, table_data_all, true, false);

// Catalog tests
TEST_SQL_TABLES(WildCatalogs, (SQLTCHAR*)L"%", (SQLTCHAR*)L"", (SQLTCHAR*)L"",
NULL, table_data_catalogs, false, false)
// Catalog tests (error: catalogs not supported)
TEST_F(TestSQLTables, WildCatalogs) {
SQLRETURN ret = SQLTables(m_hstmt, (SQLTCHAR*)L"%", SQL_NTS, (SQLTCHAR*)L"",
SQL_NTS, (SQLTCHAR*)L"", SQL_NTS, NULL, SQL_NTS);
EXPECT_EQ(ret, SQL_ERROR);
LogAnyDiagnostics(SQL_HANDLE_STMT, m_hstmt, ret);
}

// Schema tests
TEST_SQL_TABLES(WildSchema, (SQLTCHAR*)L"", (SQLTCHAR*)L"%", (SQLTCHAR*)L"",
NULL, table_data_schemas, false, false)
// Schema tests (error: schemas not supported)
TEST_F(TestSQLTables, WildSchema) {
SQLRETURN ret = SQLTables(m_hstmt, (SQLTCHAR*)L"", SQL_NTS, (SQLTCHAR*)L"%",
SQL_NTS, (SQLTCHAR*)L"", SQL_NTS, NULL, SQL_NTS);
EXPECT_EQ(ret, SQL_ERROR);
LogAnyDiagnostics(SQL_HANDLE_STMT, m_hstmt, ret);
}

// Table tests
TEST_SQL_TABLES(ValidTable, NULL, NULL, (SQLTCHAR*)L"kibana_sample_data%", NULL,
Expand Down
33 changes: 19 additions & 14 deletions sql-odbc/src/IntegrationTests/ITODBCInfo/test_odbc_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,16 @@ int Ver1GEVer2(std::wstring ver_1_str, std::wstring ver_2_str) {
TEST_SQL_GET_INFO_STRING(SQLDriverName, SQL_DRIVER_NAME, L"odfesqlodbc.dll");
TEST_SQL_GET_INFO_STRING(SQLDriverODBCVer, SQL_DRIVER_ODBC_VER, L"03.51");

std::wstring version = std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t >{}
std::wstring version =
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t >, wchar_t >{}
.from_bytes(ELASTICSEARCHDRIVERVERSION);
TEST_SQL_GET_INFO_STRING(SQLDriverVer, SQL_DRIVER_VER, version);

TEST_SQL_GET_INFO_UINT16(SQLGetDataExtensions, SQL_GETDATA_EXTENSIONS,
(SQL_GD_ANY_COLUMN | SQL_GD_ANY_ORDER | SQL_GD_BOUND
| SQL_GD_BLOCK));
TEST_SQL_GET_INFO_STRING(SQLSearchPatternEscape, SQL_SEARCH_PATTERN_ESCAPE, L"");
TEST_SQL_GET_INFO_STRING(SQLSearchPatternEscape, SQL_SEARCH_PATTERN_ESCAPE,
L"");

//////////////////////
// Data Source Info //
Expand All @@ -158,8 +160,8 @@ TEST_SQL_GET_INFO_UINT16(SQLCursorCommitBehavior, SQL_CURSOR_COMMIT_BEHAVIOR,
TEST_SQL_GET_INFO_UINT16(SQLTxnCapable, SQL_TXN_CAPABLE, SQL_TC_NONE);
TEST_SQL_GET_INFO_UINT16(SQLConcatNullBehavior, SQL_CONCAT_NULL_BEHAVIOR,
SQL_CB_NULL);
TEST_SQL_GET_INFO_STRING(SQLSchemaTerm, SQL_SCHEMA_TERM, L"schema");
TEST_SQL_GET_INFO_STRING(SQLCatalogTerm, SQL_CATALOG_TERM, L"catalog");
TEST_SQL_GET_INFO_STRING(SQLSchemaTerm, SQL_SCHEMA_TERM, L"");
TEST_SQL_GET_INFO_STRING(SQLCatalogTerm, SQL_CATALOG_TERM, L"");

///////////////
// DBMS Info //
Expand All @@ -173,7 +175,8 @@ TEST_SQL_GET_INFO_VERSION_GE(SQLDBMSVer, SQL_DBMS_VER, L"7.1.1");
///////////////////

TEST_SQL_GET_INFO_STRING(SQLColumnAlias, SQL_COLUMN_ALIAS, L"Y");
TEST_SQL_GET_INFO_UINT16(SQLGroupBy, SQL_GROUP_BY, SQL_GB_GROUP_BY_EQUALS_SELECT);
TEST_SQL_GET_INFO_UINT16(SQLGroupBy, SQL_GROUP_BY,
SQL_GB_GROUP_BY_EQUALS_SELECT);
TEST_SQL_GET_INFO_STRING(SQLIdentifierQuoteChar, SQL_IDENTIFIER_QUOTE_CHAR,
L"`");
TEST_SQL_GET_INFO_UINT_MASK(SQLOJCapabilities, SQL_OJ_CAPABILITIES,
Expand All @@ -187,11 +190,10 @@ TEST_SQL_GET_INFO_UINT_MASK(SQLODBCInterfaceConformance,
SQL_ODBC_INTERFACE_CONFORMANCE, SQL_OIC_CORE);
TEST_SQL_GET_INFO_UINT_MASK(SQLSQLConformance, SQL_SQL_CONFORMANCE,
SQL_SC_SQL92_ENTRY);
TEST_SQL_GET_INFO_UINT_MASK(SQLCatalogUsage, SQL_CATALOG_USAGE,
SQL_CU_DML_STATEMENTS);
TEST_SQL_GET_INFO_UINT16(SQLCatalogLocation, SQL_CATALOG_LOCATION, SQL_QL_START);
TEST_SQL_GET_INFO_UINT_MASK(SQLCatalogUsage, SQL_CATALOG_USAGE, 0);
TEST_SQL_GET_INFO_UINT16(SQLCatalogLocation, SQL_CATALOG_LOCATION, 0);
TEST_SQL_GET_INFO_STRING(SQLCatalogNameSeparator, SQL_CATALOG_NAME_SEPARATOR,
L".");
L"");
TEST_SQL_GET_INFO_UINT_MASK(SQLSQL92Predicates, SQL_SQL92_PREDICATES,
SQL_SP_BETWEEN | SQL_SP_COMPARISON | SQL_SP_IN
| SQL_SP_ISNULL | SQL_SP_LIKE);
Expand All @@ -204,7 +206,8 @@ TEST_SQL_GET_INFO_UINT_MASK(SQLSQL92ValueExpressions,
SQL_SQL92_VALUE_EXPRESSIONS,
SQL_SVE_CASE | SQL_SVE_CAST);
TEST_SQL_GET_INFO_UINT_MASK(SQLDatetimeLiterals, SQL_DATETIME_LITERALS, 0);
TEST_SQL_GET_INFO_STRING(SQLOrderByColumnsInSelect, SQL_ORDER_BY_COLUMNS_IN_SELECT, L"Y");
TEST_SQL_GET_INFO_STRING(SQLOrderByColumnsInSelect,
SQL_ORDER_BY_COLUMNS_IN_SELECT, L"Y");
TEST_SQL_GET_INFO_STRING(SQLCatalogName, SQL_CATALOG_NAME, L"N");

////////////////
Expand Down Expand Up @@ -232,11 +235,11 @@ TEST_SQL_GET_INFO_UINT_MASK(SQLConvertVarbinary, SQL_CONVERT_VARBINARY, 0);
TEST_SQL_GET_INFO_UINT_MASK(SQLConvertChar, SQL_CONVERT_CHAR, 0);
TEST_SQL_GET_INFO_UINT_MASK(SQLConvertLongVarchar, SQL_CONVERT_LONGVARCHAR, 0);
TEST_SQL_GET_INFO_UINT_MASK(SQLConvertWChar, SQL_CONVERT_WCHAR, 0);
TEST_SQL_GET_INFO_UINT_MASK(SQLConvertWLongVarchar, SQL_CONVERT_WLONGVARCHAR, 0);
TEST_SQL_GET_INFO_UINT_MASK(SQLConvertWLongVarchar, SQL_CONVERT_WLONGVARCHAR,
0);
TEST_SQL_GET_INFO_UINT_MASK(SQLConvertWVarchar, SQL_CONVERT_WVARCHAR, 0);
TEST_SQL_GET_INFO_UINT_MASK(SQLConvertGuid, SQL_CONVERT_GUID, 0);


//////////////////////
// Scalar Functions //
//////////////////////
Expand Down Expand Up @@ -278,8 +281,10 @@ TEST_SQL_GET_INFO_UINT_MASK(SQLSQL92StringFunctions, SQL_SQL92_STRING_FUNCTIONS,
////////////

TEST_SQL_GET_INFO_UINT16(SQLMaxIdentifierLen, SQL_MAX_IDENTIFIER_LEN, SHRT_MAX);
TEST_SQL_GET_INFO_UINT16(SQLMaxColumnsInGroupBy, SQL_MAX_COLUMNS_IN_GROUP_BY, 0);
TEST_SQL_GET_INFO_UINT16(SQLMaxColumnsInOrderBy, SQL_MAX_COLUMNS_IN_ORDER_BY, 0);
TEST_SQL_GET_INFO_UINT16(SQLMaxColumnsInGroupBy, SQL_MAX_COLUMNS_IN_GROUP_BY,
0);
TEST_SQL_GET_INFO_UINT16(SQLMaxColumnsInOrderBy, SQL_MAX_COLUMNS_IN_ORDER_BY,
0);
TEST_SQL_GET_INFO_UINT16(SQLMaxColumnsInSelect, SQL_MAX_COLUMNS_IN_SELECT, 0);

int main(int argc, char** argv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const int delay_offset_3_1 = 0;
const int delay_offset_3_2 = 180;
const SQLSMALLINT single_col_name_length = 6;
const SQLSMALLINT single_col_data_type = SQL_WVARCHAR;
const SQLULEN single_col_column_size = 25;
const SQLULEN single_col_column_size = 15;
const SQLSMALLINT single_col_decimal_digit = 0;
const SQLSMALLINT single_col_nullable = 2;
const std::wstring single_row = L"1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<show-ssl-checkbox value="true" />
<vendor1-prompt value="Region: " />
<vendor2-prompt value="Additional Options: " />
<has-databases value="false" />
<has-schemas value="false" />
</connection-config>
</connection-dialog>
Binary file modified sql-odbc/src/TableauConnector/odfe_sql_odbc/odfe_sql_odbc.taco
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<show-ssl-checkbox value="true" />
<vendor1-prompt value="Region: " />
<vendor2-prompt value="Additional Options: " />
<has-databases value="false" />
<has-schemas value="false" />
</connection-config>
</connection-dialog>
Binary file not shown.
24 changes: 7 additions & 17 deletions sql-odbc/src/odfesqlodbc/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,36 +636,26 @@ void CC_log_error(const char *func, const char *desc,
#define NULLCHECK(a) (a ? a : "(NULL)")

if (self) {
MYLOG(ES_ERROR, "CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",
func, desc, self->__error_number,
NULLCHECK(self->__error_message));
MYLOG(ES_ERROR,
"CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func,
desc, self->__error_number, NULLCHECK(self->__error_message));
MYLOG(ES_ERROR,
" "
"------------------------------------------------------------\n");
MYLOG(ES_ERROR,
" henv=%p, conn=%p, status=%u, num_stmts=%d\n",
self->henv, self, self->status, self->num_stmts);
MYLOG(ES_ERROR,
" esconn=%p, stmts=%p, lobj_type=%d\n", self->esconn,
self->stmts, self->lobj_type);
MYLOG(ES_ERROR, " esconn=%p, stmts=%p, lobj_type=%d\n",
self->esconn, self->stmts, self->lobj_type);
} else {
MYLOG(ES_ERROR, "INVALID CONNECTION HANDLE ERROR: func=%s, desc='%s'\n", func,
desc);
MYLOG(ES_ERROR, "INVALID CONNECTION HANDLE ERROR: func=%s, desc='%s'\n",
func, desc);
}
}

const char *CurrCat(const ConnectionClass *conn) {
// Keeping this NULL since it's required for getting list of tables in
// Microsoft Excel with ODBC Connection mode. This causes error in Data
// Connection wizard mode but data connection wizard sends query with
// catalog.table_name which fails. So setting this to NULL will enable more
// functionality
UNUSED(conn);
return NULL;

// Change this to following return value when found a solution which works
// with ODBC and Data Connection wizard in Microsoft Excel return
// conn->cluster_name;
}

const char *CurrCatString(const ConnectionClass *conn) {
Expand Down
21 changes: 11 additions & 10 deletions sql-odbc/src/odfesqlodbc/es_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ std::shared_ptr< Aws::Http::HttpResponse > ESCommunication::IssueRequest(
request->SetAuthorization("Basic " + hashed_userpw);
} else if (m_rt_opts.auth.auth_type == AUTHTYPE_IAM) {
std::shared_ptr< Aws::Auth::ProfileConfigFileAWSCredentialsProvider >
credential_provider =
Aws::MakeShared< Aws::Auth::ProfileConfigFileAWSCredentialsProvider >(
ALLOCATION_TAG.c_str(), ESODBC_PROFILE_NAME.c_str());
credential_provider = Aws::MakeShared<
Aws::Auth::ProfileConfigFileAWSCredentialsProvider >(
ALLOCATION_TAG.c_str(), ESODBC_PROFILE_NAME.c_str());
Aws::Client::AWSAuthV4Signer signer(credential_provider,
SERVICE_NAME.c_str(),
m_rt_opts.auth.region.c_str());
Expand Down Expand Up @@ -524,7 +524,8 @@ int ESCommunication::ExecDirect(const char* query, const char* fetch_size_) {
try {
ConstructESResult(*result);
} catch (std::runtime_error& e) {
m_error_message = "Received runtime exception: " + std::string(e.what());
m_error_message =
"Received runtime exception: " + std::string(e.what());
if (!result->result_json.empty()) {
m_error_message += " Result body: " + result->result_json;
}
Expand All @@ -542,10 +543,9 @@ int ESCommunication::ExecDirect(const char* query, const char* fetch_size_) {
result.release();

if (!cursor.empty()) {
// If the response has a cursor, this thread will retrieve more result pages asynchronously.
std::thread([&, cursor]() {
SendCursorQueries(cursor);
}).detach();
// If the response has a cursor, this thread will retrieve more result
// pages asynchronously.
std::thread([&, cursor]() { SendCursorQueries(cursor); }).detach();
}

return 0;
Expand All @@ -570,7 +570,7 @@ void ESCommunication::SendCursorQueries(std::string cursor) {
return;
}

std::unique_ptr<ESResult> result = std::make_unique<ESResult>();
std::unique_ptr< ESResult > result = std::make_unique< ESResult >();
AwsHttpResponseToString(response, result->result_json);
PrepareCursorResult(*result);

Expand All @@ -586,7 +586,8 @@ void ESCommunication::SendCursorQueries(std::string cursor) {
&& !m_result_queue.push(QUEUE_TIMEOUT, result.get())) {
}

// Don't release when attempting to push to the queue as it may take multiple tries.
// Don't release when attempting to push to the queue as it may take
// multiple tries.
result.release();
}
} catch (std::runtime_error& e) {
Expand Down
5 changes: 3 additions & 2 deletions sql-odbc/src/odfesqlodbc/es_communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class ESCommunication {
std::string& output);
void SendCloseCursorRequest(const std::string& cursor);
void StopResultRetrieval();
std::vector< std::string > GetColumnsWithSelectQuery(const std::string table_name);
std::vector< std::string > GetColumnsWithSelectQuery(
const std::string table_name);

private:
void InitializeConnection();
Expand All @@ -85,7 +86,7 @@ class ESCommunication {
void PrepareCursorResult(ESResult& es_result);

// TODO #35 - Go through and add error messages on exit conditions
std::string m_error_message;
std::string m_error_message;
const std::vector< std::string > m_supported_client_encodings = {"UTF8"};

ConnStatusType m_status;
Expand Down
7 changes: 3 additions & 4 deletions sql-odbc/src/odfesqlodbc/es_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ std::string GetServerVersion(void* es_conn) {
}

std::string GetClusterName(void* es_conn) {
return es_conn
? static_cast< ESCommunication* >(es_conn)->GetClusterName()
: "";
return es_conn ? static_cast< ESCommunication* >(es_conn)->GetClusterName()
: "";
}

void* InitializeESConn() {
Expand Down Expand Up @@ -111,7 +110,7 @@ void ESClearResult(ESResult* es_result) {
}

void ESStopRetrieval(void* es_conn) {
static_cast< ESCommunication* >(es_conn)->StopResultRetrieval();
static_cast< ESCommunication* >(es_conn)->StopResultRetrieval();
}

std::vector< std::string > ESGetColumnsWithSelectQuery(
Expand Down
Loading