Home

Awesome

pbix

This repository is based on https://github.com/duckdb/extension-template, check it out if you want to build and ship your own DuckDB extension.


This duckdb extension, pbix, allows you to parse the data model embedded in PowerBI (pbix) files.

For a pure Python implementation of the pbix parser, check out this library šŸ‘‰ PBIXray.

Building

Build steps

Now to build the extension, run:

make

The main binaries that will be built are:

./build/release/duckdb
./build/release/test/unittest
./build/release/extension/pbix/pbix.duckdb_extension

Running the extension

To run the extension code, start the shell with ./build/release/duckdb.

Now we can use the features from the extension directly in DuckDB. The extension contains two table functions pbix_meta() that takes two string arguments (filename and metadata table) and returns the contents of the metadata table and pbix_read that takes two string arguments (filename and table) and returns the contents of the table:

pbix_meta()

Returns metadata table for a data model (consult MS-SSAS-T for metadata structures). For a list of available tables try sqlite_master.

D SELECT Name FROM pbix_meta('Adventure Works DW 2020.pbix','table') where isHidden=0;
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
ā”‚ Name            ā”‚
ā•žā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•”
ā”‚ Customer        ā”‚
ā”‚ Date            ā”‚
ā”‚ Sales Territory ā”‚
ā”‚ Product         ā”‚
ā”‚ Sales Order     ā”‚
ā”‚ Sales           ā”‚
ā”‚ Reseller        ā”‚
ā”‚ Currency Rate   ā”‚
ā”‚ Currency        ā”‚
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

pbix_read()

Returns the contents of table from pbix file.

D SELECT 
  ResellerKey, 
  'Business Type', 
  Reseller, 
  'Reseller ID' 
  FROM pbix_read('Adventure Works DW 2020.pbix','Reseller') limit 10; 
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
ā”‚ ResellerKey ā”† 'Business Type'      ā”† Reseller                        ā”†'Reseller ID'ā”‚
ā•žā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•Ŗā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•Ŗā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•Ŗā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•”
ā”‚         277 ā”† Specialty Bike Shop  ā”† The Bicycle Accessories Company ā”† AW00000277  ā”‚
ā”‚         455 ā”† Value Added Reseller ā”† Timely Shipping Service         ā”† AW00000455  ā”‚
ā”‚         609 ā”† Value Added Reseller ā”† Good Toys                       ā”† AW00000609  ā”‚
ā”‚         492 ā”† Specialty Bike Shop  ā”† Basic Sports Equipment          ā”† AW00000492  ā”‚
ā”‚         365 ā”† Specialty Bike Shop  ā”† Distinctive Store               ā”† AW00000365  ā”‚
ā”‚         168 ā”† Specialty Bike Shop  ā”† Economy Bikes Company           ā”† AW00000168  ā”‚
ā”‚           6 ā”† Warehouse            ā”† Aerobic Exercise Company        ā”† AW00000006  ā”‚
ā”‚         402 ā”† Warehouse            ā”† Pro Sporting Goods              ā”† AW00000402  ā”‚
ā”‚         529 ā”† Warehouse            ā”† Big-Time Bike Store             ā”† AW00000529  ā”‚
ā”‚         241 ā”† Specialty Bike Shop  ā”† Vale Riding Supplies            ā”† AW00000241  ā”‚
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Running the tests

Different tests can be created for DuckDB extensions. The primary way of testing DuckDB extensions should be the SQL tests in ./test/sql. These SQL tests can be run using:

make test

Installing the deployed binaries

You will need to do two things to install your extension binaries from S3. Firstly, DuckDB should be launched with the allow_unsigned_extensions option set to true. How to set this will depend on the client you're using. Some examples:

CLI:

duckdb -unsigned

Python:

con = duckdb.connect(':memory:', config={'allow_unsigned_extensions' : 'true'})

NodeJS:

db = new duckdb.Database(':memory:', {"allow_unsigned_extensions": "true"});

Secondly, you must set the repository endpoint in DuckDB to the HTTP URL of your bucket + version of the extension you want to install. To do this, run the following SQL query in DuckDB:

SET custom_extension_repository='https://duckdb.pbix.info';

After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB:

INSTALL pbix
LOAD pbix

Limitations/Bugs/Features/TODO