Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Bruce__z
Employee
Employee

Power BI custom data connector - how to override cast behavior for int64/uint data type

I'm writing a custom data connector for Click House, to support the direct query feature. The connector is based on Click House ODBC driver.

 

The connector works for number types except int64 and uint64. When loading the connector in Power BI Desktop and connecting to the database, if I check the int64 field and check a visualization chart, it always show "Can't display the visual". Looking into the details, it says: DB::Exception: Decimal data type family must have exactly two arguments: precision and scale: While processing CAST(i64, 'DECIMAL').

 

Here is a sample statement - "  select sum(cast(`int64field` as DECIMAL)) as `C1` from `db`.`table`  ".

 

The reason for above error is that Click House must specify 2 parameters for the Decimal type, as described at Type Conversion | ClickHouse Documentation.

 

As the sql statement is automatically generated, is there any way to correct the statement while it is generating?

 

I found seems the cast statement can be modified through "AstVisitor" feature in the sample DataConnectors/RedshiftODBC.pq. However below code doesn't work. (The AstVisitor has already added into OdbcOptions in Odbc.DataSource.)

 

 

 

 

 

 

        AstVisitor = [
            Constant =
                let
                    Cast = (value, typeName) => [
                        Text = Text.Format("CAST(#{0} as #{1})", { value, typeName })
                    ],
                    Visitor = [
                        BIGINT = each Cast(_, "Decimal256(0)")
                    ]
                in
                    (typeInfo, ast) => Record.FieldOrDefault(Visitor, typeInfo[TYPE_NAME], each null)(ast[Value])
        ]

 

 

 

 

 

 

Thank you !

1 ACCEPTED SOLUTION
Bruce__z
Employee
Employee

I didn't find a workaround for modifying the cast statement. But I fixed this issue by modifying the column info in SQLColumns handler. Just change the columns which are int64/uint64 types to DOUBLE type, by updating DATA_TYPE/SQL_DATA_TYPE/TYPE_NAME columns in the metadata table.  This way power BI even doesn't generate the cast statement. Here is a sample for SQLColumns - DataConnectors/SnowflakeODBC.pq at master · microsoft/DataConnectors (github.com)

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Bruce__z,

Thanks for your sharing, I think they will help others who face a similar scenario. 🙂

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Bruce__z
Employee
Employee

I didn't find a workaround for modifying the cast statement. But I fixed this issue by modifying the column info in SQLColumns handler. Just change the columns which are int64/uint64 types to DOUBLE type, by updating DATA_TYPE/SQL_DATA_TYPE/TYPE_NAME columns in the metadata table.  This way power BI even doesn't generate the cast statement. Here is a sample for SQLColumns - DataConnectors/SnowflakeODBC.pq at master · microsoft/DataConnectors (github.com)

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.