Repository navigation
feat(dbt): native dialect column types, a runtime platform check, and a shared type table - #1187
Merged
Merged
Conversation
…stays unmapped The 0.7.7 column-type enum admits dialect names such as int64, float64 and datetime2. On Redshift, DuckDB and Databricks they fell back silently to the adapter's catch-all (varchar, string). A second alias table, chained after the existing one, now folds them onto types each adapter maps, and new native entries keep a fold from narrowing (int64 stays bigint, float64 stays double). Names with no native type on an adapter (bit, bignumeric, interval on Redshift and Databricks, the geometry family on DuckDB and Databricks, hll off Redshift, row on BigQuery) stay unmapped. fluid validate refuses a column that declares one where a dbt build types it: a hybrid-reference build, on the exposes it writes (those its outputs name, less any bound to another warehouse). fluid generate transformation --model-contracts judges embedded-logic and multi-stage builds too. Each message names the column and what it would become. A dbt-<adapter> engine forge writes no profile for (dbt-postgres, dbt-glue) is not judged: engine_issues already warns that its project is typed for the platform's adapter. The Databricks emitter reads the same table, so a Unity Catalog column declared int64 or datetime2 is now provisioned (BIGINT, TIMESTAMP_NTZ) instead of refused. Snowflake and BigQuery lookups do not follow the new aliases, so their mapping is exactly as before. Signed-off-by: Speculator55005 <50082482+fas89@users.noreply.github.com>
…time platform A dbt build with no execution.runtime.platform is not a Databricks job build, so the local dbt runner ran it, on DuckDB unless the dbt project had its own profiles.yml, while its models were typed for the Databricks expose, and nothing said so. fluid validate now refuses it and names builds[i].execution.runtime.platform, with the two values to choose from: databricks for a Databricks job, local to keep running it on this machine. The check lives next to the dbt engine's other issues, so fluid generate reports it too. A build is judged for the exposes it writes, as the column type check judges them, and both dbt checks in validate share one helper that fails closed. The catalog gets contract_dbt_runtime_platform. Two test fixtures that meant a Databricks or local run now say so. Signed-off-by: Speculator55005 <50082482+fas89@users.noreply.github.com>
…and the emitters share The Snowflake and Databricks emitters, the Databricks dbt test emitter and the Databricks provider typed their columns by importing the dbt engine's type module, so writing a table loaded the project generator. The table itself (the per-adapter maps, the alias chains, split_parameterized, sql_type, known_type and the decimal argument check) now lives in fluid_build/util/type_table.py, which both sides import. What the dbt engine judges with it (adapter_for_build, engine_issues, the decimal refusal, the precision warnings) stays in engines/dbt/_types.py. An import-linter contract keeps fluid_build.iac and fluid_build.providers from importing fluid_build.engines directly. No type changes: the moved functions give the same answer for 1,326 type spellings on ten adapter names before and after. Signed-off-by: Speculator55005 <50082482+fas89@users.noreply.github.com>
…atabricks project A dbt build that writes a Databricks table has to name where it runs, or fluid validate refuses it (contract_dbt_runtime_platform). The dbt manifest importer wrote such a build without one, so a project of Databricks tables came out of the import failing validate on that error alone. It now writes runtime.platform: local, which is what the build did before (dbt on this machine, with the project's own profile), and says so in its report. Other adapters are unchanged. Signed-off-by: Speculator55005 <50082482+fas89@users.noreply.github.com>
…uote The two dbt checks quoted an expose id, a build id, a column name and a type as written. A contract is input: an id with a line feed forged a line in the error list, and a name or a type could be as long as the file. The messages now spell out every character that is not printable and cut each value after 80 characters, through util/excerpt.py, as the other contract checks cut theirs. Signed-off-by: Speculator55005 <50082482+fas89@users.noreply.github.com>
The column type entry listed bit and bignumeric for Redshift and Databricks only, and hll as refused off Redshift, while DuckDB refuses bit and bignumeric too and hll is refused on DuckDB and Databricks. It also said Snowflake and BigQuery "keep their mapping", which hid that a Snowflake dbt build is not judged at all and that only row is refused on BigQuery. Both entries now say that fluid generate transformation refuses the same builds as fluid validate, and the runtime platform entry says what the dbt importer writes. Signed-off-by: Speculator55005 <50082482+fas89@users.noreply.github.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.
Summary
Three changes to how column types reach a dbt build and the Databricks and Snowflake emitters. They share one module: the second reads what the first adds, and the third moves that module, so they land together, one commit each.
fluid validaterefuses what stays unmappedfeat(dbt)fluid validaterefuses a dbt build for a Databricks expose with no runtime platformfix(validate)refactor(types)Each change was checked alone before they were grouped. The checks on the grouped head are under "Grouped head" at the end.
1. Dialect column types in a dbt build
What
The 0.7.7 column-type enum admits dialect spellings such as
int64,float64,datetime2,varchar2anduniqueidentifier. In a dbt build on Redshift, DuckDB and Databricks they fell back without a word to the adapter's catch-all (varchar,string), so anint64column was cast tovarcharin the generated model and typedstringin its model contract.engines/dbt/_types.pygains a second alias table,_DIALECT_ALIASES, followed after_ALIASESin a chained walk until a key of the adapter's table matches. Each fold ends on a type of the same family that never narrows:int64tobigint,float64todouble,datetime2andsmalldatetimetotimestamp_ntz(DatabricksTIMESTAMP_NTZ,timestampelsewhere),varchar2tovarchar,uniqueidentifierandguidtouuid(stringon Databricks),byteaandrawto binary (varbyteon Redshift,blobon DuckDB). Native entries where a fold would lose meaning: Redshiftgeometry,geography,hllsketch,varbyte; DuckDBdouble,interval,blob. (Change 3 moves the table toutil/type_table.py.)biton Redshift, DuckDB and Databricks (a boolean in one dialect, a bit string in another),bignumericon the same three (no 76-digit decimal),intervalon Redshift and Databricks, the geometry family andhllon DuckDB and Databricks, androwon BigQuery, whose emitter refuses it too.fluid validateandfluid generate transformationrefuse a column with such a type where the generated project types it, naming the column, the type and what dbt would write instead (eventcontract_dbt_column_type):cast(null as <type>)); an embedded-logic or multi-stage build is its own SQL.fluid generate transformation --model-contractswrites each column'sdata_type, so there it judges those builds too;outputsname (every expose when it declares none), less any bound to another warehouse's table;util/excerpt.py, as the other contract checks do), so a contract cannot forge a line in the error list or make a message as long as the file.datetime2orbit, is still written asVARCHAR. BigQuery keeps its mapping too (its types come from its IaC emitter) and its builds are judged, but the only spelling refused there isrow, which that emitter refuses as well. A golden test pins both mappings.int64ordatetime2is now provisioned asBIGINTorTIMESTAMP_NTZinstead of being refused (databricks-column-type). A type it still refuses keeps that refusal;fluid validatethen reports it under both checks.Snowflake waits for a test account before its half lands. With the dialect aliases, these Snowflake columns would change from
VARCHAR(and a table already applied would plan a type change, which the data-loss gate decides):mediumint,longint,bigserial,year,datetime2,smalldatetime,timestampntz,row,super,bytea,raw,geom,point,bit,interval,bignumeric,hll;varchar2,nchar,clob,guid,uniqueidentifierandenumstayVARCHAR.Borrow
_ALIASESinengines/dbt/_types.py, extended rather than replaced; BigQuery's types from its IaC emitter (iac/providers/gcp.py::_bq_sql_type). The ODCS exporter's physical-type tables (providers/odcs/mappers/types.py) cover BigQuery, Snowflake and Kafka only, and foldbitto a boolean andbignumericto SnowflakeNUMBER, which a dbt build would narrow, so they are not reused.DataType.build(...).sql(dialect)agrees with these targets where it translates (int64toBIGINT,byteatoBINARY,BLOBorVARBYTE,uniqueidentifiertoSTRINGon Databricks andUUIDelsewhere). It needs each spelling's source dialect, which the enum mixes, fails to parseguid,raw,year,longint,hllandgeom, and passessuper,enum,yearandbitthrough unchanged. Not used. It writesdatetime2asTIMESTAMP, which Databricks reads in the session time zone; this maps it toTIMESTAMP_NTZ.datacontract/export/sql_type_converter.py): one converter per server type, the pattern followed here, but it maps almost none of these spellings and writes an unknown type through verbatim, except on BigQuery, where it raises. The refusal here takes that BigQuery path for every adapter.base/column.pyand the adapters'column.py):translate_typerelabels a few names and returns an unknown type unchanged.VARCHAR, the silent fallback this removes.Validation
tests/engines/test_dbt_dialect_types.py): every 0.7.7 enum value on each of BigQuery, Redshift, DuckDB and Databricks maps or is refused by a realfluid validaterun naming the column; dialect types never narrow (int64is neverinton Databricks,float64nevernumericon DuckDB); the generic table follows the chains;fluid generate transformationkeeps BigQuery'sint64andfloat64casts; Snowflake'ssql_typeandknown_typefor every enum value and three parameterized forms equal a golden taken before the change; BigQuery's types for what its emitter refuses equal theirs before, androwis refused; an embedded-logic or multi-stage build is judged only under--model-contracts, andgenerate transformation --model-contractsrefuses it while plaingeneratewrites it; an expose bound to another warehouse, or not in the build'soutputs, is not judged.fluid validateexits 0 on each adapter with a mapped type).contract_dbt_column_type(fix and example), anderror-codes.mdis regenerated (scripts/gen_agent_skill_references.py).mainand this change when it was written: no type that mapped before changed, so no existing Unity Catalog column changes type.Reviews
sql_typeandknown_typeequalmain's for every enum value and 18 parameterized forms; every type that changed on Redshift, DuckDB, Databricks and the generic table moved from the catch-all to a native type, and none narrowed; realfluid validateandfluid generate transformationruns behave as described.outputswere judged, and BigQueryrowfolded tojson; all three fixed. Round 2: adbt-postgresordbt-gluebuild was judged against Redshift's table and named Redshift, and anexposeIdthat is not a string crashed the scope check; both fixed with failing-first tests. Its other findings are under known limits.Known limits
int64tointegerandfloat64tonumeric, as it already did forbigintandfloat.clob,varchar2,ncharandenumas a barevarchar(256 characters), as it does forvarchar.rowandsuperasvarchar, as it does forstruct.fluid validatecannot see--modelor--model-contracts: a hybrid-reference build rendered from a model sidecar writes no casts but is still judged, and an embedded-logic or multi-stage build is judged only bygenerate --model-contracts.fluid generate transformationstill writes a model for every expose in the contract, so a generated project can hold a catch-all column for an expose another build writes. The generator's scope is unchanged here.double precision), which the schema admits, is refused instead of mapped.dbt-postgres,dbt-spark,dbt-athenaanddbt-glue),datetime2(7)now becomestimestamp(7)where it becamevarchar, andtimestamp(7)already passed its precision through; an adapter that takes no precision says so when dbt runs.2. A dbt build for a Databricks expose needs a runtime platform
What
A dbt build that sets no
execution.runtime.platformis not a Databricks job build (util.contract.is_databricks_job_build), sofluid applyhands it to the local dbt runner. When the build writes a Databricks expose, the runner ran it on DuckDB (unless the dbt project carried its ownprofiles.yml), whilefluid generatetyped its models for Databricks, and nothing said so.fluid validatenow refuses such a build (eventcontract_dbt_runtime_platform). The error names the build by its id (orbuilds[i]) and the field,builds[i].execution.runtime.platform, with the two values to choose from:databricksto run it as a Databricks job,localto keep running it on this machine.outputsname, or every expose when it declares nooutputslist, the rule the dialect type check uses (_written_exposes) andutil.contract.builds_writing_exposestates. A build whose outputs are all local is not refused, nor is one withoutputs: [].fluid validate's two dbt checks share one helper that records each build's findings once and fails closed: a crash in either is an error saying what the contract was NOT checked for.fluid import dbtwritesexecution.runtime.platform: localon the build it makes for a Databricks project, and says so in its report: it is what that build did before (dbt on this machine, with the project's own profile), and without it the importer's own output would be refused. Other adapters get noexecutionblock.engines/dbt/_types.py::engine_issues), sofluid generate transformationrefuses the build too.contract_dbt_runtime_platform(fix and example), anderror-codes.mdis regenerated.Borrow
util.contract.is_databricks_job_build(what makes a build a Databricks job),engines/dbt/_types.py::build_platformandadapter_for_build(where the models are typed for),util.contract.builds_writing_expose(which exposes a build writes), and_add_findingsincli/validate.pyfor the finding's pointer and catalog guidance.profiles.yml(--target); it has no notion of the contract's binding, so there is nothing to reuse for a contract-level check.Validation
tests/engines/test_dbt_databricks.py::TestRuntimePlatformRequired): a realfluid validaterun refuses the build and names the field;databricksandlocalruntimes are not refused; local-only exposes are not judged; a build whoseoutputsname only local exposes is not refused, and one whoseoutputsname the Databricks expose is; adbt-databricksengine is refused too; the message names the build id and no other contract value.tests/engines/test_dbt_adapter_engines.py,tests/cli/test_validate_notes.py).tests/cli/test_dbt_manifest_importer.py::TestDatabricksRuntimePlatform(the importer's Databricks build names its platform; the other adapters get none),test_an_id_is_spelled_out_when_unprintable_and_cut_when_longand, for change 1,test_a_long_or_unprintable_value_is_spelled_out_and_cut_in_the_message.Reviews
fluid validateandfluid generate transformation: refused with the platform unset, fordbt-databricksanddbt-core, an embedded-logic build,outputsmissing, a second build, a numeric id; not refused forlocal, asparkengine,outputs: []or local-only outputs.outputsname only local exposes was refused; fixed (outputs-scoped).tests/cli/test_apply_simple_provider.pyandtests/test_global_provider_flag.py, all on one worker, with the provider registry left holding aws, gcp and local and databricks blocked by a plugin policy. That is order-dependent state from tests that change the registry (tests/providers/test_lazy_provider_registry.pyleaves gcp and local with the rest blocked); the victims' guard only checks forlocal. The same tests pass with this change in one process.Known limits
runtime.platformis refused here and by the schema, so it reads as two errors. The schema refuses a build id that is not a string, which the label falls back from.build_platform), so a build whose outputs are local while a Databricks expose is listed first is typed for Databricks and not refused.fluid import dbtwrote for a Databricks project before this change has noexecution.runtime.platform, sofluid validatenow refuses it; the error names the field to set.3. The column type table moves to a leaf
What
The Snowflake and Databricks IaC emitters, the Databricks dbt test emitter and the Databricks provider typed their columns by importing the dbt engine's type module (
engines/dbt/_types.py), so writing a table loaded the project generator, and an emitter depended on an engine.fluid_build/util/type_table.py: the per-adapter maps, the alias chains,split_parameterized,sql_type,known_typeand the decimal argument check. Besidesutil/column_type.pyit imports only the BigQuery emitter, and only when asked for a BigQuery type, as before.engines/dbt/_types.py:adapter_for_build,build_platform,engine_issues,unmapped_column_types, the decimal refusal and the precision warnings. It reads the table throughbigquery_type(was_bigquery_type) and three new public names,ADAPTERS,fallback_typeandINTEGER_SPELLINGS, instead of the table's private names.models.pyandschema_yml.py, the three emitters, the provider and the tests.AGENTS.mdand two comments in the BigQuery emitter name the new file, and the IaC workflow's path filter adds it beside the engine module, whose checksfluid validatestill runs on the dbt builds the Databricks tests declare.iac/providers/databricks.pyit changes only the table's function-local imports, the lines that name it (dbt_types.becomestype_table.), and two docstrings.fluid_build.iacandfluid_build.providersfrom importingfluid_build.enginesdirectly. Indirect chains stay allowed: the Databricks job emitter reads the dbt runner's selectors and project path, the runner's profiles reach the engine's Glue text rule, and the schedulers build on the engine base class.Nothing a user sees changes, so there is no CHANGELOG entry for this change.
Borrow
util/column_type.py, which "imports nothing fromfluid_build, so any mapper can use it without pulling a provider in", andutil/dbt_engine.py, shared by the dbt engine and the dbt runner), and the import-linter contracts inpyproject.tomlthat guard the other leaves (import-linter, BSD-2, already a dev dependency).export/sql_type_converter.pythat both its dbt exporter (dbt_exporter.py) and its SQL DDL exporter (sql_exporter.py) import, the shape this takes.Validation
engines.dbt._types) and holds after the move. Pointing one Snowflake emitter import back at the engine breaks it again.sql_type,known_type,split_parameterized,decimal_argument_problemand the BigQuery function give the same answers before and after for 1,326 type spellings (every key and value of the tables and alias maps, with 13 argument suffixes) on ten adapter names: 41,106 answers, byte-identical.Reviews
fluid generate transformation(plain and--model-contracts),fluid generate iacandfluid validategive the same output on both trees (diff -r) for contracts with 19 column types on Snowflake, Databricks, BigQuery, Redshift and local, as hybrid-reference and embedded-logic builds. After a column is typed through each emitter,fluid_build.enginesis not imported. Its one note, that the path filter had dropped the engine modulefluid validatestill uses, is fixed.Known limits
Grouped head
The three changes were checked alone before they were grouped. Grouped, they sit on
mainas six commits: the three above, then three that came out of the grouped review (the importer's runtime platform, the cut and spelled-out values in the two dbt messages, and the CHANGELOG wording). The CHANGELOG entries for changes 1 and 2 end[Unreleased]/### Changed, and one.secrets.baselineline number moved with the path filter in change 3.lint-imports(both configs), import cycles and the fences: clean.mypy --strictreports only its 3sqlglotrows inprofiler/consumer_queries/check.py, as onmain; bare mypy on the changed files reports the same 155 lines as onmain, one of them moved with its code.pytest -n 3): 56,562 passed, 6 failed, 1,133 skipped, on the head before its last rebase ontomain(the one newmaincommit changes no file of this change butCHANGELOG.md). None of the 6 is in code these changes touch; all six fail on this machine without them: four DuckDB sandbox tests (tests/providers/test_duckdb_sandbox*.py),test_dbt_does_not_reload_the_project_dotenvandtest_an_operator_exported_aws_endpoint_is_used. After that rebase: the fences, the startup budget and the touched tests (tests/engines, validate issues and notes, the dbt importer, the skill pack, the type-table drift, the 0.7.7 enum levels and the security tests): 1,488 passed, 9 skipped.ripwire --quality-delta(the diff applied on a fresh tree at its base; a no-op control there reports no rows): each change alone gave these rows, all expected, each with a no-op control of 0 rows. Change 1: 5 rows, four token clones of 21 to 30 tokens against unrelated test helpers and short-horizon churn onengine_issues. Change 2: two thin rows, an 89-token likeness between the two check functions and a 27-token closure. Change 3: 16 rows from the move, 15 short-horizon churn on functions whose references were renamed and an 18-token clone. The run on the grouped diff (control 0 rows) gives 18 rows, none a defect: 16 short token clones between new functions or tests and unrelated existing code (the twofindingsclosures,writes_column_types,bigquery_type, the importer test's_importhelper, one-line parametrized asserts), short-horizon churn onengine_issues, which the two new checks hook into, and_VALIDATION_GUIDANCEgrowing by the 15 lines of the two new catalog entries.fluid validateonmainand on this branch gave identical exit codes and output for every contract in the demo environment (67 runs with and without its Databricks overlay), the example contracts and wizard output of the web console that drives forge-cli, the forge-cli examples and the forge templates' output, andfluid generate transformation --model-contractsdid the same on 53 dbt contracts; a contract without the runtime platform and one with abitcolumn on DuckDB show that both new errors fire.main: PASS WITH LOWS. About 3,000 type results (the 79 spellings and their argument forms on six adapter names) match betweenmainand the head for Snowflake and BigQuery, and every change on Redshift, DuckDB and Databricks moves from the catch-all to a native type of the same family. Change 3 is byte-identical to its parent on 12,473 table keys, the new import contract breaks when an emitter's import points at the engine again, and realfluid validateandfluid generate transformationruns behave as described above.fluid generate transformationrefuses the same builds. A fifth,datetime2(7)becomingtimestamp(7)on the generic table, is under known limits. Round 2 re-verified the fixes (the message text is identical for ordinary values, 30 contracts compared, and no raw control character reaches a message, 20,000 generated cases): PASS WITH LOWS.Known limits of the review fixes
/exposes,/builds) and not the item.repr.Documentation
What the docs PR covers
fluid validaterefuses, and say that a Snowflake dbt build is not judged and keeps its mapping while BigQuery keeps its mapping and refuses onlyrow(change 1).execution.runtime.platform:databricksfor a Databricks job,localto run it on the machine that runsfluid apply(change 2).