Skip to content

Commit

Permalink
Merge pull request #1 from mariadb-corporation/fix-sqlcolumns-char-float
Browse files Browse the repository at this point in the history
Fix CHAR and FLOAT runtime error in Power BI
  • Loading branch information
toddstoffel authored Sep 1, 2020
2 parents c58657f + 01dddf1 commit 29c97e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
43 changes: 26 additions & 17 deletions MariaDB/MariaDB.pq
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,26 @@ MariaDBDatabaseImplOdbc = (server as text, optional db as text) as table =>
// to the user trace log, without any modification.
SQLColumns = (catalogName, schemaName, tableName, columnName, source) =>
let
OdbcSqlType.WCHAR = -8,
OdbcSqlType.WVARCHAR = -9,

FixDataType = (dataType) =>
if dataType = OdbcSqlType.WCHAR then
OdbcSqlType.WVARCHAR
else
dataType,
FixTypeName = (typeName) =>
if typeName = "ENUM" then
"VARCHAR"
OdbcSqlType.REAL = 7,
OdbcSqlType.DOUBLE = 8,

FixColumns = (row) as record =>
if row[TYPE_NAME] = "ENUM" then
Record.TransformFields(row, {
{ "DATA_TYPE", (val) => OdbcSqlType.WVARCHAR },
{ "TYPE_NAME", (val) => "VARCHAR" }
})
else if row[DATA_TYPE] = OdbcSqlType.REAL then
Record.TransformFields(row, {
{ "DATA_TYPE", (val) => OdbcSqlType.DOUBLE },
{ "TYPE_NAME", (val) => "DOUBLE" }
})
else
typeName,
TransformDataType = Table.TransformColumns(source, { { "DATA_TYPE", FixDataType } }),
Transform = Table.TransformColumns(TransformDataType, { { "TYPE_NAME", FixTypeName } })
row,
TransformedRows = Table.TransformRows(source, each FixColumns(_)), // column data types info is lost here
EmptyTableWithColumnTypes = Table.FirstN(source, 0), // get an empty table with the original column data types
Transform = Table.InsertRows(EmptyTableWithColumnTypes, 0, TransformedRows)
in
if (EnableTraceOutput <> true) then Transform else
// the if statement conditions will force the values to evaluated/written to diagnostics
Expand Down Expand Up @@ -273,7 +278,7 @@ MariaDB = [

// Data Source UI publishing description
MariaDB.Publish = [
Beta = true,
Beta = false,
SupportsDirectQuery = true, // enables direct query
Category = "Database",
ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
Expand Down Expand Up @@ -349,9 +354,13 @@ ODBC = Extension.LoadFunction("OdbcConstants.pqm");
// SQL_SC_SQL92_FULL = 8
// ]
//
// SQL_SC_SQL92_INTERMEDIATE value derived from MariaDB ODBC Connector 3.1.7 sources ma_connection.c:1584
//
Config_SqlConformance = ODBC[SQL_SC][SQL_SC_SQL92_INTERMEDIATE]; // null, 1, 2, 4, 8
// SQL_SC_SQL92_INTERMEDIATE value was originially derived from MariaDB ODBC Connector 3.1.7 sources ma_connection.c:1584
// However, during Connecto Certification testing it was found that SQL_SC_SQL92_FULL conformance was required by the Mashup Engine to support joins (JOIN).
// The SQL92_FULL requirement comes from Microsoft.Mashup.Engine1.Library.Odbc.OdbcQuery.PushDownQuerySpecification(bool liftOrderBy)
// where a FoldingFailureException is thrown if DataSource.Info.SupportsDerivedTable == false.
// Respectively, the property definition in the Mashup Engine was: public virtual bool SupportsDerivedTable => Supports(Odbc32.SQL_SC.SQL_SC_SQL92_FULL);
// Thus, here SQL92 conformance is reported higher (FULL) than the ODBC driver actually supports or at least reports (INTERMEDIATE).
Config_SqlConformance = ODBC[SQL_SC][SQL_SC_SQL92_FULL]; // null, 1, 2, 4, 8

// This setting controls row count limits and offsets. If not set correctly, query
// folding capabilities for this connector will be extremely limited. You can use
Expand Down
9 changes: 9 additions & 0 deletions MariaDB/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ REQUIREMENTS

- MariaDB ODBC Driver v3.1.7 or later
https://mariadb.com/kb/en/mariadb-connector-odbc/


CHANGE LOG

20-Aug-2020
- Fixed "joins not working" issue.

12-Aug-2020
- Disabled tracing as requested by Microsoft.

0 comments on commit 29c97e6

Please sign in to comment.