Skip to content

fix(showcase-ecommerce): re-add query entities with contentType - #241

Open
nwadams wants to merge 4 commits into
mainfrom
na--showcase-ecommerce-queries-contenttype
Open

nwadams wants to merge 4 commits into
mainfrom
na--showcase-ecommerce-queries-contenttype

Conversation

@nwadams

@nwadams nwadams commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Re-adds the 312 query entities from #198 with the bug fixed that made #203 revert them. This replaces #204, which re-applies #198 unchanged.

What changed

  • contentType on every aspect. None of the 1,246 aspects in Revert "Revert "feat(showcase-ecommerce): add 312 query entities for text-to-sql / anchor demo"" #204's 04-queries.json had "contentType": "application/json". Without it, the CLI's file source can't parse the GenericAspect envelope and rejects every record, so datahub datapack load showcase-ecommerce exits non-zero. That is what broke the OSS tests/datapack/test_datapack_smoke run.
  • New file name, 04-queries-v2.json. The CLI caches each pack file by URL and doesn't refetch it when the index version changes. A client that cached the broken 04-queries.json from feat(showcase-ecommerce): add 312 query entities for text-to-sql / anchor demo #198 would keep it. A new URL forces a fresh fetch. The query README now says to rename the file whenever its content changes.
  • index.json version 4 → 5. So clients refetch the index and find the new file.
  • Mart revenue queries sum each order once. analytics.order_details has one row per line item and repeats order_total on each row. revenue_by_customer_class/01-canonical_mart, 03-with_aov_per_class and customer_geo_distribution/03-mart_version summed it at that grain, which counted an order once per line item. They now collapse to one row per order and exclude statuses 3 and 4, like the raw canonical variant. The variants already commented as approximate or as the wrong way to do it (aov_monthly/03-weighted_avg_anti, daily_order_volume_30d/04) and the noise queries are unchanged on purpose.
  • One dangling subject removed. noise/abandoned_logon_to_order_funnel pointed at order_entry_db.order_entry.logon, which is not in the pack. The query stays with no subjects, like the two schema-exploration noise queries.

The commits keep Alex's revert of the revert first, then add the fixes, so the diff against #198 stays readable.

Testing

  • Loaded 04-queries-v2.json from this branch with datahub datapack load --url file://… --trust-custom --no-cache (CLI 1.7.0.12) into a local stack (GMS v2.4.0rc1): 1,245 records written, 0 failures. The stored statement for revenue_by_customer_class/01-canonical_mart matches the new source file.
  • Every packaged statement matches its .sql source file.
  • Ran the old and new mart queries in DuckDB on an order with two line items (total 100), an order with one item (total 50), and a cancelled order. Old 01-canonical_mart: revenue 2,248. New: revenue 150, AOV 75, the same as 02-canonical_raw_join.
  • Not run: the OSS smoke test against this branch. It loads the pack from main through the registry, so it can only run after merge.

Open question

@devashish2203 asked in the revert thread whether these queries belong in a separate pack, because OSS CI loads showcase-ecommerce. This PR keeps them in the same pack. They add about 0.7 MB and load in about 5 s. If you'd rather have a separate pack, say so and I'll move the file out.

#202 changes the same file and adds 05-query-usage.json. It will need a rebase onto this after merge.

🤖 Generated with Claude Code

alexsku and others added 2 commits October 28, 2026 17:13
Re-applies the 312 query entities from #198, which #203 reverted because
they broke the OSS datapack smoke test.

- Add "contentType": "application/json" to every aspect in
  04-queries.json. Without it the CLI's file source can't parse the
  GenericAspect envelope and rejects all 1,246 records.
- Bump index.json to version 5 so CLIs that cached version 4 fetch the
  new file.
- Drop the querySubjects record of
  noise/abandoned_logon_to_order_funnel. It pointed at
  order_entry.logon, which is not in the pack. The query stays, with no
  subjects, like the two schema-exploration noise queries.

Co-Authored-By: Alex Skurikhin <alex.skurikhin@datahub.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@alexsku alexsku left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full PR. The serialization fix checks out: all 1,245 records deserialize, all 312 packaged SQL statements match their source files, and referenced datasets and authors resolve within the pack.

I found two reproducible medium-priority correctness issues, detailed inline: existing caches can retain the earlier broken query file despite the version bump, and a query labeled canonical double-counts order-header revenue at line-item grain.

Validation included an isolated cache-upgrade reproduction and a small SQLite fixture for the revenue aggregation. I did not run Snowflake execution or an OSS server ingestion test. The passing CI check only validates image sizes.

Comment thread datapacks/showcase-ecommerce/index.json Outdated
{"path": "02-data.json"},
{"path": "03-context.json"}
{"path": "03-context.json"},
{"path": "04-queries.json"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Publish the corrected query file under a fresh URL

Reusing this path leaves users who cached the file from #198 with the broken serialization. The current datapack loader refreshes the index when its version changes, but caches child files by URL and reuses them unless no_cache is enabled. I reproduced a cached version 4 index plus the old query file: a normal load advanced the cached version to 5 while retaining the old bytes, producing 1,246 parse failures. Forcing a refresh fetched this PR's file and produced zero failures. Please give the corrected fixture a new filename and update this entry, or ship a loader fix that invalidates child files when the index version changes. A regression test should cover an upgrade with the earlier query file already cached.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b594a10. The file is now 04-queries-v2.json and index.json points to it, so every client fetches it from a new URL. The query README now says to rename the file whenever its content changes.

You're right about the loader: when the index version changes, download_pack fetches the index again but calls _resolve_index_file with no_cache=False, so cached child files are reused. I'm fixing that in a separate datahub PR, with a regression test for an upgrade where the old child file is already cached. This PR doesn't depend on it.

Comment on lines +5 to +7
SUM(order_total) AS total_revenue,
COUNT(DISTINCT order_id) AS order_count,
AVG(order_total) AS avg_order_value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Aggregate header totals once per order

order_details contains one row per line item, so SUM(order_total) repeats each order's revenue and AVG(order_total) weights orders by their item count. With a two-item order totaling 100 and a one-item order totaling 50, this query returns revenue 250 and AOV 83.33; the correct values are 150 and 75. The raw canonical variant returns revenue 150 for the same fixture. Please deduplicate to one row per order before aggregating and align the status filter with the raw canonical variant. The same issue occurs in 03-with_aov_per_class.sql and both packaged statements, so regenerate 04-queries.json after correcting the sources. A fixture with differing item counts per order would protect this behavior.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 53e5598. 01-canonical_mart and 03-with_aov_per_class now collapse order_details to one row per order, then exclude statuses 3 and 4 like 02-canonical_raw_join. The same bug was in customer_geo_distribution/03-mart_version, so I fixed that one too. The three packaged statements are regenerated and match their source files.

On your fixture (a two-item order totaling 100, a one-item order totaling 50, plus a cancelled order) in DuckDB, the new canonical query returns revenue 150 and AOV 75, the same as the raw canonical query. The old one returned 2,248.

The repo has no SQL test harness, so I didn't commit the fixture. I left aov_monthly/03-weighted_avg_anti, daily_order_volume_30d/04 and the noise queries unchanged, because they are meant to be wrong or approximate and their comments say so.

nwadams and others added 2 commits October 29, 2026 14:01
The datapack CLI caches each pack file by URL and reuses it when the
index version changes. A client that cached 04-queries.json from #198
would keep the copy without contentType and fail to parse all 1,246
records. A new file name forces every client to fetch the fixed copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
analytics.order_details has one row per line item and repeats
order_total on every row. Summing or averaging it there counts an order
once per item. Collapse to one row per order first, and exclude status
3 and 4 like the raw canonical variant. Applies to
revenue_by_customer_class 01 and 03 and customer_geo_distribution 03,
and their packaged statements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants