docs(bi-sql-examples): add ThoughtSpot SQL captures - #438
Merged
Merged
Conversation
Creates the model the captured queries run against: a six-table Dunder Mifflin star and two warehouse-native semantic layers over it — a Databricks Metric View and a Snowflake Semantic View. Both layers are reduced to the columns these examples exercise, so every object declared is used. They are otherwise as deployed, and they are not the same surface: category_quantity is a dimension on Databricks and a metric on Snowflake, and their comments describe it differently. No data ships with it; the captures are reproduced for their SQL shape, not their results. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Twenty-six queries across eight feature areas, none written by hand. Twenty-two are saved Answers captured with metadata/answer/sql; four are AgentQL statements compiled through the same generator. Every one was executed against the model to confirm it is valid, not merely verbatim. Each is reproduced as generated apart from removing the generator's own provenance comments, stripping trailing whitespace, and adding a statement terminator. The comment above each query records what the shape shows and, where a Tableau counterpart exists, how the two differ. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Covers what the folder is, why the query shapes matter to a SQL interface for reusable semantics, how the SQL was captured, and three properties of the captures that matter if they are reused: they are dated, their column aliases are positional rather than stable, and a parameter is resolved before generation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
jbonofre
approved these changes
Oct 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
bi-sql-examples/thoughtspot/, a sibling to the existingtableau/folder: real SQLthat ThoughtSpot generated while querying metrics defined outside the tool, in a
warehouse-native semantic layer.
The model is a six-table star with a Databricks Metric View over it.
setup.sqldeclaresthe tables and the view, and also carries a Snowflake Semantic View over the same star so
the two vendors' expressions can be compared. No data ships — the queries are reproduced
for their SQL shape rather than their results, so none of them depends on the original
rows.
Twenty-six queries across eight feature areas. Twenty-two are saved Answers captured with
POST /api/rest/2.0/metadata/answer/sql; four are AgentQL (Semantic SQL) statementscompiled by the same generator. No SQL in the folder was written by hand. Each
statement is verbatim apart from three disclosed edits (the generator's own provenance
comments removed, trailing whitespace stripped, a terminator added).
Both properties were checked mechanically rather than asserted: every statement is
byte-identical to its capture, and every statement executes against a metric view rebuilt
from this
setup.sqltext.What the captures show
A few things in them bear on what a SQL interface to reusable semantics has to decide:
detects it.
category_quantityis a dimension on the Databricks Metric View and ametric on the Snowflake Semantic View. Under the same filter, Databricks returns the
whole category's units while Snowflake returns the filtered total — the window is
evaluated before the filter on one and after it on the other. Neither errors; the numbers
simply differ. Verified against both deployed layers (
04-lod-two-stage-aggregation.sql).A windowed measure declared as a dimension is grouped by and filtered on in
WHERE,neither of which a window function permits at the same query level.
LIMITat a tie isundetermined. A folded top-N whose search asked for a sort does carry one — so the
tiebreak comes from the request, confirmed against a sibling Answer differing only in
that clause (
03-top-n-and-subselects.sql).or expanded inline. Two of the substitutions replace functions Databricks already has
(
zeroifnull,split_part), so they are choices rather than gaps.SELECT DISTINCTbecomes
GROUP BYevery time (07-scalar-and-string-functions.sql).byte-identical searches compile to the same shape, differing only in
SELECTorder — andbecause aliases are positional, that alone makes
ca_2a different measure in each(
08-result-shape.sql).replace()calls,
NULLIF(3,0)eleven times in one statement,case 1 when 1 then 1 else …with anunreachable arm carrying live column references.
Three properties matter if the statements are reused rather than read: they are dated (a
relative date resolves at generation time to bare constants, with no
CURRENT_DATEanywhere); column aliases are positional, not stable; and a conditional is decided before
generation with the losing arm discarded, so the SQL cannot tell you whether a switch
worked or its condition never matched.
Related Issues
Discussion: #436 — opened before this PR per
CONTRIBUTING.md. It raisesthree open questions (whether a second subfolder on this pattern is wanted, whether a
runnable
setup.sqlis acceptable alongside the Tableau folder's illustrative one, andwhether the demo schema should be renamed to something neutral). Happy to reshape this
PR on any of them.
Checklist
Documentation
Examples
bi-sql-examples/, alongside the existingtableau/folderTests
bi-sql-examples/, so none runs against this path. In place ofthat, every statement was executed against a metric view built from this PR's own
setup.sql, and every statement was diffed against its capture.Compliance
Not applicable: Specification, Ontology, Converters, Validation — this changes none of
core-spec/,ontology/,converters/orvalidation/.🤖 Generated with Claude Code