feat(appkit): resolve schema-relative typegen queries via catalog/schema context#464
Open
QuentinAmbard wants to merge 1 commit into
Open
Conversation
…ema context The type-generator DESCRIBE pass ran `DESCRIBE QUERY <sql>` with only a warehouse id and no session catalog/schema. Schema-relative queries — unqualified table names like `FROM orders`, which resolve fine at runtime when the app passes catalog/schema as statement context — therefore failed at typegen time with TABLE_OR_VIEW_NOT_FOUND, and the generated types silently degraded to `result: unknown`. Thread an optional catalog/schema through the typegen path so DESCRIBE runs with the same session context the runtime uses: - vite-plugin reads DATABRICKS_CATALOG / DATABRICKS_SCHEMA from env (next to the existing DATABRICKS_WAREHOUSE_ID) and forwards them. - generateFromEntryPoint -> generateQueriesFromDescribe -> describeAdaptive carry the optional context down to executeStatement, which honors top-level catalog/schema as the equivalent of USE CATALOG / USE SCHEMA for that one statement. Fully backward compatible: when the env vars are unset, no catalog/schema keys are added to the request and behavior is unchanged. Adds describeAdaptive tests covering both the forwarded-context and omitted-context (back-compat) paths. Signed-off-by: Quentin Ambard <quentin.ambard@databricks.com>
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.
Problem
The type-generator's DESCRIBE pass runs
DESCRIBE QUERY <sql>with only awarehouse_idand no session catalog/schema. Queries written schema-relative — unqualified table names likeFROM orders— therefore fail at typegen time withTABLE_OR_VIEW_NOT_FOUND, even though they resolve fine at runtime (the analytics route can pass catalog/schema as statement context). When DESCRIBE fails, the generated types silently degrade toresult: unknown, so apps lose chart type-safety with no obvious cause.This is increasingly common: writing queries schema-relative (and supplying catalog/schema as session context) is how an app stays portable across workspaces without hardcoding
catalog.schema.tablein every.sql.Repro
Same table, same warehouse — only difference is the session context:
Fix
Thread an optional
catalog/schemathrough the typegen path so DESCRIBE runs with the same session context the runtime uses:vite-plugin.tsreadsDATABRICKS_CATALOG/DATABRICKS_SCHEMAfrom env (right next to the existingDATABRICKS_WAREHOUSE_ID) and forwards them.generateFromEntryPoint→generateQueriesFromDescribe→describeAdaptivecarry the optional context down toexecuteStatement, which honors top-levelcatalog/schemaas the equivalent ofUSE CATALOG/USE SCHEMAfor that one statement.I used the native top-level
catalog/schemafields rather than prependingUSE CATALOG; …to the statement string, since the Statement Execution API already supports them and it avoids multi-statement handling.Backward compatibility
When the env vars are unset, no
catalog/schemakeys are added to the request and behavior is byte-for-byte unchanged. Existing behavior for fully-qualified queries is unaffected.Tests
Added two
describeAdaptivetests instatement-result.test.ts:catalog/schematoexecuteStatementwhen context is provided;Full package:
tsc --noEmitclean,biome checkclean, commitlint clean, 524 type-generator + analytics tests pass.