import%20marimo%0A%0A__generated_with%20%3D%20%220.14.16%22%0Aapp%20%3D%20marimo.App(%0A%20%20%20%20width%3D%22medium%22%2C%0A%20%20%20%20app_title%3D%22Dimensional%20Indexing%20Pattern%22%2C%0A%20%20%20%20css_file%3D%22marimo_custom.css%22%2C%0A)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20text_cell(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%20Dimensional%20Indexing%0A%0A%20%20%20%20Build%20search%20indexes%20for%20data%20discovery%20and%20exploration.%0A%0A%20%20%20%20%23%23%20Overview%0A%0A%20%20%20%20Dimensional%20indexing%20creates%20searchable%20catalogs%20of%20your%20data%20by%20analyzing%0A%20%20%20%20dimension%20values%20and%20their%20frequencies.%20This%20pattern%20helps%20you%3A%0A%20%20%20%20-%20Discover%20what%20values%20exist%20in%20your%20dimensions%0A%20%20%20%20-%20Build%20autocomplete%20and%20search%20features%0A%20%20%20%20-%20Understand%20data%20distribution%20and%20cardinality%0A%20%20%20%20-%20Create%20data%20catalogs%20for%20exploration%0A%0A%20%20%20%20**Malloy%20reference%3A**%20%5BDimensional%20Indexing%5D(https%3A%2F%2Fdocs.malloydata.dev%2Fdocumentation%2Fpatterns%2Fdim_index)%0A%0A%20%20%20%20This%20pattern%20is%20essential%20for%3A%0A%20%20%20%20-%20**Data%20discovery**%20-%20Understanding%20what's%20in%20your%20data%0A%20%20%20%20-%20**Search%20interfaces**%20-%20Building%20autocomplete%20and%20search%0A%20%20%20%20-%20**Data%20quality**%20-%20Analyzing%20value%20distributions%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20text_cell()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20ibis%0A%20%20%20%20import%20ibis.selectors%20as%20s%0A%20%20%20%20from%20ibis%20import%20_%0A%20%20%20%20from%20boring_semantic_layer%20import%20to_semantic_table%0A%20%20%20%20import%20textwrap%0A%0A%20%20%20%20BASE_URL%20%3D%20%22https%3A%2F%2Fpub-a45a6a332b4646f2a6f44775695c64df.r2.dev%22%0A%0A%20%20%20%20%23%20Define%20code%20as%20strings%20for%20accordion%0A%20%20%20%20imports_code%20%3D%20textwrap.dedent(%22%22%22%5C%0A%20%20%20%20import%20ibis%0A%20%20%20%20import%20ibis.selectors%20as%20s%0A%20%20%20%20from%20ibis%20import%20_%0A%20%20%20%20from%20boring_semantic_layer%20import%20to_semantic_table%0A%20%20%20%20%22%22%22)%0A%0A%20%20%20%20data_code%20%3D%20textwrap.dedent(f%22%22%22%5C%0A%20%20%20%20BASE_URL%20%3D%20%22%7BBASE_URL%7D%22%0A%20%20%20%20con%20%3D%20ibis.duckdb.connect(%22%3Amemory%3A%22)%0A%0A%20%20%20%20%23%20Load%20airports%20data%0A%20%20%20%20airports_tbl%20%3D%20con.read_parquet(f%22%7B%7BBASE_URL%7D%7D%2Fairports.parquet%22)%0A%20%20%20%20%22%22%22)%0A%0A%20%20%20%20semantic_code%20%3D%20textwrap.dedent(%22%22%22%5C%0A%20%20%20%20airports%20%3D%20(%0A%20%20%20%20%20%20%20%20to_semantic_table(airports_tbl%2C%20name%3D%22airports%22)%0A%20%20%20%20%20%20%20%20.with_dimensions(%0A%20%20%20%20%20%20%20%20%20%20%20%20code%3Dlambda%20t%3A%20t.code%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20city%3Dlambda%20t%3A%20t.city%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20state%3Dlambda%20t%3A%20t.state%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20fac_type%3Dlambda%20t%3A%20t.fac_type%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20elevation%3Dlambda%20t%3A%20t.elevation%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.with_measures(%0A%20%20%20%20%20%20%20%20%20%20%20%20airport_count%3Dlambda%20t%3A%20t.count()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20avg_elevation%3Dlambda%20t%3A%20t.elevation.mean()%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%0A%20%20%20%20%22%22%22)%0A%0A%20%20%20%20%23%20Execute%20setup%0A%20%20%20%20con%20%3D%20ibis.duckdb.connect(%22%3Amemory%3A%22)%0A%20%20%20%20airports_tbl%20%3D%20con.read_parquet(f%22%7BBASE_URL%7D%2Fairports.parquet%22)%0A%0A%20%20%20%20airports%20%3D%20(%0A%20%20%20%20%20%20%20%20to_semantic_table(airports_tbl%2C%20name%3D%22airports%22)%0A%20%20%20%20%20%20%20%20.with_dimensions(%0A%20%20%20%20%20%20%20%20%20%20%20%20code%3Dlambda%20t%3A%20t.code%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20city%3Dlambda%20t%3A%20t.city%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20state%3Dlambda%20t%3A%20t.state%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20fac_type%3Dlambda%20t%3A%20t.fac_type%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20elevation%3Dlambda%20t%3A%20t.elevation%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.with_measures(%0A%20%20%20%20%20%20%20%20%20%20%20%20airport_count%3Dlambda%20t%3A%20t.count()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20avg_elevation%3Dlambda%20t%3A%20t.elevation.mean()%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Display%20accordion%20with%20setup%20code%0A%20%20%20%20_title%20%3D%20mo.md(%22%23%23%20Define%20Semantic%20Model%22)%0A%20%20%20%20_desc%20%3D%20mo.md(%22We%20create%20a%20semantic%20table%20with%20dimensions%20and%20measures%3A%22)%0A%20%20%20%20_accordion%20%3D%20mo.accordion(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%220%EF%B8%8F%E2%83%A3%20Imports%22%3A%20mo.md(f%22%60%60%60python%5Cn%7Bimports_code%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%221%EF%B8%8F%E2%83%A3%20Load%20data%22%3A%20mo.md(f%22%60%60%60python%5Cn%7Bdata_code%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%222%EF%B8%8F%E2%83%A3%20Define%20semantic%20table%22%3A%20mo.md(f%22%60%60%60python%5Cn%7Bsemantic_code%7D%5Cn%60%60%60%22)%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20)%0A%0A%20%20%20%20mo.vstack(%5B_title%2C%20_desc%2C%20_accordion%5D)%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20text_cell(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%23%20Simple%20Index%20-%20All%20Dimensions%0A%0A%20%20%20%20Create%20an%20index%20of%20all%20dimension%20values%20with%20their%20frequencies%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20import%20ibis.selectors%20as%20s%0A%0A%20%20%20%20q1%20%3D%20%22%22%22%0A%20%20%20%20airports.index(s.all()).limit(20)%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20q1_e%20%3D%20eval(%22(%22%20%2B%20q1%20%2B%20%22)%22)%0A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(f%22%60%60%60python%5Cn%7Bq1%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20mo.ui.tabs(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%93%8A%20Table%22%3A%20mo.ui.table(q1_e.execute())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%92%BB%20SQL%22%3A%20mo.md(f%22%60%60%60sql%5Cn%7Bq1_e.sql()%7D%5Cn%60%60%60%22)%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20text_cell(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%23%20Most%20Common%20String%20Values%0A%0A%20%20%20%20Filter%20the%20index%20to%20show%20only%20string%20fields%2C%20ordered%20by%20frequency%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20import%20ibis.selectors%20as%20s%0A%0A%20%20%20%20q2%20%3D%20%22%22%22%0A%20%20%20%20airports.index(s.all())%0A%20%20%20%20.filter(lambda%20t%3A%20t.fieldType%20%3D%3D%20%22string%22)%0A%20%20%20%20.order_by(lambda%20t%3A%20t.weight.desc())%0A%20%20%20%20.limit(15)%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20q2_e%20%3D%20eval(%22(%22%20%2B%20q2%20%2B%20%22)%22)%0A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(f%22%60%60%60python%5Cn%7Bq2%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20mo.ui.tabs(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%93%8A%20Table%22%3A%20mo.ui.table(q2_e.execute())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%92%BB%20SQL%22%3A%20mo.md(f%22%60%60%60sql%5Cn%7Bq2_e.sql()%7D%5Cn%60%60%60%22)%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20text_cell(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%23%20Search%20Index%20-%20Find%20Values%20Containing%20'SAN'%0A%0A%20%20%20%20Use%20the%20index%20to%20search%20for%20values%20matching%20a%20pattern%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20import%20ibis.selectors%20as%20s%0A%0A%20%20%20%20q3%20%3D%20%22%22%22%0A%20%20%20%20airports.index(s.all())%0A%20%20%20%20.filter(lambda%20t%3A%20t.fieldValue.like(%22%25SAN%25%22))%0A%20%20%20%20.order_by(lambda%20t%3A%20t.weight.desc())%0A%20%20%20%20.limit(10)%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20q3_e%20%3D%20eval(%22(%22%20%2B%20q3%20%2B%20%22)%22)%0A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(f%22%60%60%60python%5Cn%7Bq3%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20mo.ui.tabs(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%93%8A%20Table%22%3A%20mo.ui.table(q3_e.execute())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%92%BB%20SQL%22%3A%20mo.md(f%22%60%60%60sql%5Cn%7Bq3_e.sql()%7D%5Cn%60%60%60%22)%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20text_cell(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%23%20Index%20Specific%20Fields%0A%0A%20%20%20%20Create%20an%20index%20for%20only%20certain%20dimensions%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20import%20ibis.selectors%20as%20s%0A%0A%20%20%20%20q4%20%3D%20%22%22%22%0A%20%20%20%20airports.index(s.cols(%22state%22%2C%20%22city%22))%0A%20%20%20%20.order_by(lambda%20t%3A%20t.weight.desc())%0A%20%20%20%20.limit(15)%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20q4_e%20%3D%20eval(%22(%22%20%2B%20q4%20%2B%20%22)%22)%0A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(f%22%60%60%60python%5Cn%7Bq4%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20mo.ui.tabs(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%93%8A%20Table%22%3A%20mo.ui.table(q4_e.execute())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%92%BB%20SQL%22%3A%20mo.md(f%22%60%60%60sql%5Cn%7Bq4_e.sql()%7D%5Cn%60%60%60%22)%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20text_cell(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%23%20Custom%20Weight%20-%20High%20Elevation%20Cities%0A%0A%20%20%20%20Use%20a%20measure%20to%20weight%20index%20entries%20(finds%20cities%20with%20highest%20average%20elevation)%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20import%20ibis.selectors%20as%20s%0A%0A%20%20%20%20q5%20%3D%20%22%22%22%0A%20%20%20%20airports.index(s.cols(%22city%22%2C%20%22state%22)%2C%20by%3D%22avg_elevation%22)%0A%20%20%20%20.order_by(lambda%20t%3A%20t.weight.desc())%0A%20%20%20%20.limit(10)%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20q5_e%20%3D%20eval(%22(%22%20%2B%20q5%20%2B%20%22)%22)%0A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(f%22%60%60%60python%5Cn%7Bq5%7D%5Cn%60%60%60%22)%2C%0A%20%20%20%20%20%20%20%20mo.ui.tabs(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%93%8A%20Table%22%3A%20mo.ui.table(q5_e.execute())%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%F0%9F%92%BB%20SQL%22%3A%20mo.md(f%22%60%60%60sql%5Cn%7Bq5_e.sql()%7D%5Cn%60%60%60%22)%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20text_cell(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%23%20Key%20Insights%0A%0A%20%20%20%20Dimensional%20indexing%20provides%3A%0A%20%20%20%20-%20**Value%20discovery**%20-%20See%20all%20unique%20values%20and%20their%20frequencies%0A%20%20%20%20-%20**Search%20capabilities**%20-%20Filter%20and%20find%20specific%20values%0A%20%20%20%20-%20**Data%20profiling**%20-%20Understand%20cardinality%20and%20distribution%0A%20%20%20%20-%20**Custom%20weighting**%20-%20Use%20measures%20to%20prioritize%20index%20entries%0A%0A%20%20%20%20This%20pattern%20is%20powerful%20for%3A%0A%20%20%20%20-%20Building%20autocomplete%20interfaces%0A%20%20%20%20-%20Creating%20data%20catalogs%0A%20%20%20%20-%20Quality%20checking%20dimension%20values%0A%20%20%20%20-%20Understanding%20data%20before%20analysis%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
24f4c96667d0e89d2b8ab615e2793586a0b60e532169219eb88e21d048a30fb6