Last active
July 28, 2025 14:22
-
-
Save tsoumdoa/0bb0340b617dfa42a3b8fce2dfdfbfba to your computer and use it in GitHub Desktop.
Simple DuckDB query demo to work with Bim Open Schema by Ara 3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- create table from parquet files: | |
| CREATE TABLE Descriptors AS | |
| SELECT * FROM read_parquet('./Descriptors.parquet'); | |
| CREATE TABLE Documents AS | |
| SELECT * FROM read_parquet('./Documents.parquet'); | |
| CREATE TABLE DoubleParameters AS | |
| SELECT * FROM read_parquet('./DoubleParameters.parquet'); | |
| CREATE TABLE Entities AS | |
| SELECT * FROM read_parquet('./Entities.parquet'); | |
| CREATE TABLE EntityParameters AS | |
| SELECT * FROM read_parquet('./EntityParameters.parquet'); | |
| CREATE TABLE IntegerParameters AS | |
| SELECT * FROM read_parquet('./IntegerParameters.parquet'); | |
| CREATE TABLE PointParameters AS | |
| SELECT * FROM read_parquet('./PointParameters.parquet'); | |
| CREATE TABLE Points AS | |
| SELECT * FROM read_parquet('./Points.parquet'); | |
| CREATE TABLE Relations AS | |
| SELECT * FROM read_parquet('./Relations.parquet'); | |
| CREATE TABLE StringParameters AS | |
| SELECT * FROM read_parquet('./StringParameters.parquet'); | |
| CREATE TABLE Strings AS | |
| SELECT * FROM read_parquet('./Strings.parquet'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- adding index (zero-based) to Documents, Entities, Points & Strings as those table don't have index. | |
| -- Entities table | |
| CREATE TABLE Entities_New AS | |
| SELECT | |
| *, | |
| (row_number() OVER () - 1) AS "index" | |
| FROM | |
| Entities; | |
| DROP TABLE Entities; | |
| ALTER TABLE Entities_New RENAME TO Entities; | |
| -- Descriptors table | |
| CREATE TABLE Descriptors_New AS | |
| SELECT | |
| *, | |
| (row_number() OVER () - 1) AS "index" | |
| FROM | |
| Descriptors; | |
| DROP TABLE Descriptors; | |
| ALTER TABLE Descriptors_New RENAME TO Descriptors; | |
| -- Documents table | |
| CREATE TABLE Documents_New AS | |
| SELECT | |
| *, | |
| (row_number() OVER () - 1) AS "index" | |
| FROM | |
| Documents; | |
| DROP TABLE Documents; --Rename Documents Table | |
| ALTER TABLE Documents_New RENAME TO Documents; | |
| -- Points table | |
| CREATE TABLE Points_New AS | |
| SELECT | |
| *, | |
| (row_number() OVER () - 1) AS "index" | |
| FROM | |
| Points; | |
| DROP TABLE Points; --Rename Points Table | |
| ALTER TABLE Points_New RENAME TO Points; | |
| -- Strings table | |
| CREATE TABLE Strings_New AS | |
| SELECT | |
| *, | |
| (row_number() OVER () - 1) AS "index" | |
| FROM | |
| Strings; | |
| DROP TABLE Strings; --Rename Strings Table | |
| ALTER TABLE Strings_New RENAME TO Strings; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Denormalizing entities table by creating a view | |
| CREATE OR REPLACE VIEW denorm_entities | |
| AS | |
| select LocalId, GlobalId,Entities."index" as name_index, s_name.String as name, s_category.String as category, s_path.String as path_name, s_title.String as project_name | |
| from Entities | |
| LEFT OUTER JOIN Strings AS s_name | |
| ON Entities."name" = s_name."index" | |
| LEFT OUTER JOIN Strings AS s_category | |
| ON Entities.category = s_category."index" | |
| LEFT OUTER JOIN Documents | |
| ON Entities.Document = Documents."index" | |
| LEFT OUTER JOIN Strings AS s_path | |
| ON Documents.Path = s_path."index" | |
| LEFT OUTER JOIN Strings AS s_title | |
| ON Documents.Title = s_title."index"; | |
| select * | |
| FROM denorm_entities; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| category, | |
| COUNT(*) AS Occurrences | |
| FROM | |
| denorm_entities | |
| GROUP BY | |
| category | |
| ORDER BY | |
| Occurrences DESC; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DuckDB + BIM Open Schema
This Gist is all about showing you how to explore your BIM data, exported using the awesome BIM Open Schema project by Ara 3D, with the super-fast and friendly DuckDB.
Think of this as a quick dive into getting started with querying your BIM data, whether you're a Revit user or just curious to see how it works!
What You'll Need (Getting Your Data Ready)
You've got a couple of easy ways to get your hands on some
.parquetdata:Export from Revit (for the adventurous!):
If you're a Revit user and have the Bowerbird plugin installed, you can export your own data! Just run this command:
Ara3D.Bowerbird.RevitSamples/CommandExportBIMOpenSchema.csThis will generate the
.parquetfiles for you.Download a Sample (Quick & Easy!):
Don't have Revit or just want to jump straight in? No problem! You can grab a pre-exported sample:
Download and unzip
snowdon.bimdata.parquet.zipUnzip this file, and you'll have your
.parquetdata ready to go!Setting Up DuckDB
First things first, you'll need DuckDB itself. It's super easy to install:
Pro Tip: DuckDB UI for the Win!
While you can use the command line, I highly recommend checking out the DuckDB UI. It makes exploring your data and running queries much more visual and fun!
Important for UI users: Once you have your
.parquetfiles, navigate your terminal to the directory where you've saved them, then simply run:This will launch the UI in your browser, connected to your data's location!
What This Gist Shows You (The Fun Part!)
This Gist walks you through a really simple, but powerful, workflow:
.parquetfiles into queryable tables in DuckDB.This is just the tip of the iceberg! Once you've got this basic setup down, you can start building much more complex and insightful queries to truly understand your BIM data.
Happy querying! Let me know if you have any questions or cool ideas to share!