Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 12 additions & 3 deletions sql-odbc/src/PowerBIConnector/SqlOdbcPBIConnector.pq
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ SqlOdbcPBIConnectorImpl = (Server as text) as table =>
SQLGetTypeInfo = (types) =>
if (EnableTraceOutput <> true) then types else
let
// SELECT CAST(1 AS KEYWORD) does not work for OpenSearch
// SELECT CAST(1 AS STRING) works for OpenSearch
FixTypeName = (typeName) =>
if typeName = "keyword" then "string"
else typeName,

// Outputting the entire table might be too large, and result in the value being truncated.
// We can output a row at a time instead with Table.TransformRows()
rows = Table.TransformRows(types, each Diagnostics.LogValue("SQLGetTypeInfo " & _[TYPE_NAME], _)),
toTable = Table.FromRecords(rows)
toTable = Table.FromRecords(rows),

// Override the type name of columns
modifiedColumns = Table.TransformColumns(toTable, {{"TYPE_NAME", FixTypeName}})
in
Value.ReplaceType(toTable, Value.Type(types)),
Value.ReplaceType(modifiedColumns, Value.Type(types)),

// SQLColumns is a function handler that receives the results of an ODBC call to SQLColumns().
SQLColumns = (catalogName, schemaName, tableName, columnName, source) =>
Expand Down Expand Up @@ -206,7 +215,7 @@ SqlOdbcPBIConnector.Publish = [
LearnMoreUrl = "https://www.opensearch.org/",

// Disabling direct query due to limited SQL query support
SupportsDirectQuery = false,
SupportsDirectQuery = true,

SourceImage = SqlOdbcPBIConnector.Icons,
SourceTypeImage = SqlOdbcPBIConnector.Icons
Expand Down
42 changes: 35 additions & 7 deletions sql-odbc/src/sqlodbc/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,14 @@ RETCODE SQL_API OPENSEARCHAPI_GetInfo(HDBC hdbc, SQLUSMALLINT fInfoType,
break;

case SQL_CONVERT_GUID:
case SQL_CONVERT_INTEGER:
case SQL_CONVERT_SMALLINT:
case SQL_CONVERT_TINYINT:
case SQL_CONVERT_BIT:
case SQL_CONVERT_VARCHAR:
case SQL_CONVERT_BIGINT:
case SQL_CONVERT_DECIMAL:
case SQL_CONVERT_DOUBLE:
case SQL_CONVERT_FLOAT:
case SQL_CONVERT_NUMERIC:
case SQL_CONVERT_REAL:
case SQL_CONVERT_DATE:
case SQL_CONVERT_TIME:
case SQL_CONVERT_TIMESTAMP:
case SQL_CONVERT_BINARY:
case SQL_CONVERT_LONGVARBINARY:
case SQL_CONVERT_VARBINARY: /* ODBC 1.0 */
Expand All @@ -126,12 +120,46 @@ RETCODE SQL_API OPENSEARCHAPI_GetInfo(HDBC hdbc, SQLUSMALLINT fInfoType,
#ifdef UNICODE_SUPPORT
case SQL_CONVERT_WCHAR:
case SQL_CONVERT_WLONGVARCHAR:
case SQL_CONVERT_WVARCHAR:
#endif /* UNICODE_SUPPORT */
len = sizeof(SQLUINTEGER);
value = 0; /* CONVERT is unavailable */
break;

case SQL_CONVERT_INTEGER: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_CVT_BIT | SQL_CVT_WVARCHAR | SQL_CVT_DOUBLE | SQL_CVT_BIGINT | SQL_CVT_REAL;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're also missing the ability to convert to the same type, ex integer -> integer, and so on?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ,should what about SQL_CVT_VARCHAR in addition to SQL_CVT_WVARCHAR?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should SQL_CVT_SMALLINT or SQL_CVT_TINYINT also be here? (I'm assuming those are valid constants, it's possible they are not).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add conversion for the same types.
SQLGetTypeInfo does not include the value for type SQL_CVT_VARCHAR so I assume it is not supported.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SMALLINT and TINYINT are byte and short for OpenSearch and casting to byte, short, SMALLINT, and TINYINT do not work.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that my comment around SMALLINT and TINYINT are for all conversions, are they unsupported for all?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant I could not find the varchar value when I run SQLGetTypeInfo in ODBCTest
image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of right now, I don't think they are supported.
image

break;

case SQL_CONVERT_BIT: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_CVT_INTEGER | SQL_CVT_WVARCHAR | SQL_CVT_DOUBLE | SQL_CVT_BIGINT | SQL_CVT_REAL;
break;

case SQL_CONVERT_WVARCHAR: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_CVT_INTEGER | SQL_CVT_DOUBLE | SQL_CVT_BIGINT | SQL_CVT_REAL;
break;

case SQL_CONVERT_DOUBLE: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_CVT_INTEGER | SQL_CVT_BIT | SQL_CVT_WVARCHAR | SQL_CVT_BIGINT | SQL_CVT_REAL;
break;

case SQL_CONVERT_BIGINT: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_CVT_INTEGER | SQL_CVT_BIT | SQL_CVT_WVARCHAR | SQL_CVT_DOUBLE | SQL_CVT_REAL;
break;

case SQL_CONVERT_REAL: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_CVT_INTEGER | SQL_CVT_BIT | SQL_CVT_WVARCHAR | SQL_CVT_DOUBLE | SQL_CVT_BIGINT;
break;

case SQL_CONVERT_TIMESTAMP: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_CVT_WVARCHAR;
break;

case SQL_CONVERT_FUNCTIONS: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_FN_CVT_CAST;
Expand Down