Skip to content

feat(import): read Apache Ossie 0.3.0.dev0 files and translate their SQL to BigQuery - #692

Merged
feixufeixu merged 48 commits into
mainfrom
feat/import/ossie-0.3
Nov 16, 2026
Merged

feixufeixu merged 48 commits into
mainfrom
feat/import/ossie-0.3

Conversation

@feixufeixu

@feixufeixu feixufeixu commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

kcmd import now reads a third-party Apache Ossie file that holds its model at the document root: a 0.3.0.dev0 file, or an unwrapped 0.2.0.dev0 file, which follows the same rules. It writes the model as 0.2.0.dev0 or 0.2.0.dev0/google, as --flavor names. Each Ossie sql text becomes a dialects entry in the new dialect OSSIE_SQL_2026, and kcmd import --transpile translates it to BigQuery.

What import reads

  1. A 0.3.0.dev0 file, and an unwrapped 0.2.0.dev0 file, with datasets at the document root and no semantic_model list. A wrapped 0.2.0.dev0 file is read as before.
  2. Import writes nothing and stops on such a file under --input first-party, on a GOOGLE block in one, on a 0.3.0.dev0 file with a semantic_model list, and on a model name that is missing, is not a string, or that hyphens cannot make valid. It also stops on a dataset, field, metric or relationship name that kcmd's name rules refuse, and lists every such name.
  3. Push, kcmd profiles and the other commands that load a model refuse such a file, and the error ends with Run 'kcmd import <file> --flavor <ossie|google>' to convert it. A 0.3.0.dev0 document with no datasets, such as an Ossie ontology or mapping file, gets an error saying it holds no Ossie semantic model.

What import converts

Import reports each edit.

  1. It wraps the model in a semantic_model list and sets version.
  2. It removes the editor schema line (# yaml-language-server: $schema=...), since the line names the input's schema. It does so for every root-model file, and for a wrapped file it writes in the other flavor.
  3. It renames nonportable_extensions to custom_extensions, writing object data as compact JSON in a string.
  4. It moves each sql into a dialects entry named OSSIE_SQL_2026.
  5. It converts names to kcmd's naming. In a field text, Ossie reads every name as a column, so a qualifier naming the field's own dataset is removed. An OSSIE_SQL_2026 text, read with Ossie's grammar, gets every dataset and field name in its declared spelling. A text in another dialect gets only its dataset qualifiers in their declared spelling. A relationship's from and to get it too.
  6. It moves each dataset metric to the model's metrics, anchored on its dataset. In an Ossie text, bare field names become dataset.field, and source.column becomes the field that reads that column, added when none does. A moved metric whose name is taken becomes <dataset>_<metric>. AGG(dataset.metric) in a model metric becomes that metric's text.
  7. It rewrites a key or join entry that names a field to the column that field reads.
  8. It writes the model name with a hyphen for each character kcmd's model-name rule refuses, in every third-party import.

What import leaves for the author

What kcmd's spec lists as unsupported is removed and reported, as before: a second model, an unanchored metric that reaches no entity or several, a non-SQL dialect entry, a query-valued source. What the conversion itself cannot convert stays as written, with a warning, for the author to edit: an AGG over a metric that names no field, a key on a computed field, a vendor text in a moved dataset metric.

The OSSIE_SQL_2026 dialect

A model file may now hold OSSIE_SQL_2026 entries. Push, kcmd profiles, import and the loader read them with a parser of Ossie's expression grammar, never with the SQL engine.

--transpile

An OSSIE_SQL_2026 text translates to the BigQuery SQL an author would write by hand. Beyond the direct forms, the translator adds only casts between DATE, DATETIME and TIMESTAMP values, a typed NULL, constant folding where BigQuery takes only a literal, the NULL placement Ossie's spec requires in a window, parentheses that kcmd's own SQL reader needs, and backticks on a name that kcmd's reader or BigQuery would misread bare. fidelity.md lists where the BigQuery value can differ, and import prints a reminder line for the differences an author should check. A construct BigQuery has no form for stays untranslated, with a warning. So does a date part BigQuery refuses on a value the translator can see is a DATE or a TIMESTAMP, and a RANGE frame offset beside a value it can see is not a number. Other dialects translate as before, apart from the fixes below.

Fixes to existing code

  1. When a flow mapping held a key with no value, which an unquoted comma makes, the YAML writer put null in front of the file, and import stopped with "missing 'version'" and wrote nothing. Import now keeps the entry, and the load error says to quote a text that holds a comma, in model files and profile files. The writer also no longer writes an item onto the line of a key with an empty value, and when import sets a key written with no value, the writer writes the value after the key instead of at the start of the file.
  2. Import dropped datatype: Opaque only in some cases. It now drops it in every third-party import, with a report, as kcmd's spec says.
  3. A third-party import stopped on a metric written only in a non-SQL dialect. It now removes that metric and reports it.
  4. Push read the date part of SAFE.TIMESTAMP_TRUNC(ts, MONTH, 'zone') as a column.
  5. Push hung on a text cut off inside a type's parentheses, such as CAST(amount AS NUMBER(10, 2, and printed a Rust panic on a SQL Server IF(.
  6. --transpile wrote PI() and Snowflake RANDOM() unchecked, a column name such as größe without backticks, a comment twice, a quoted name holding a backtick in a form BigQuery misreads, and a text starting with a column named like a statement word, such as copy or call, as a statement.
  7. Push matched a lambda parameter, such as I in FILTER(orders.items, I -> i:qty > 1), in exact letter case.
  8. The YAML writer crashed with "Overlapping edits" on one kind of update, and took quadratic time: a 10,000-field import took 166 seconds on main and takes 40 now.
  9. Import dropped a metrics entry that is not a mapping.
  10. Push now refuses a field or metric text that holds a subquery or a CTE, which kcmd does not support. An OSSIE_SQL_2026 text cannot hold one, since Ossie's grammar has none, and push reports such a text as one it cannot read.
  11. When pull writes over a local model file that does not load, its warning no longer tells the author to run kcmd import on that file.
  12. A YAML alias inside the value its anchor names, which JSON cannot hold, made import run out of stack, in a model file or a profile file. Import, push and the other commands that read those files now refuse it with a load error that names the alias.

How it was tested

  1. Unit test rows cover each conversion, translation and fix, apart from the writer's speed, and the full suite passes.
  2. kcmd's Ossie parser agrees with ANTLR's reference parser on acceptance and tree for all 5.3 million texts of a harness that includes every Ossie text in the tests, apart from texts nested deeper than kcmd's 250-level limit.
  3. Every Ossie example, every Ossie compliance model and the Ossie converters' fixtures, 49 files, were imported in both flavors, with and without --transpile. In the google flavor, import writes every model file. The Cube fixtureA, Holistics ecommerce and ThoughtSpot TPC-DS fixtures stop in the ossie flavor, which requires a table source and a SQL expression for every field that these fixtures lack once import removes what kcmd does not support. Their error points to --flavor google. Files that hold no model, such as Ossie's ontology and mapping files, stop as designed. Every OSSIE_SQL_2026 text in the corpus translates, and a second import of each 0.2.0.dev0/google output changes nothing.
  4. No expected BigQuery text in the tests fails a BigQuery dry run for every column type. Those that fail for some column types are the type-dependent refusals fidelity.md lists.
  5. A live push and pull on production Knowledge Catalog round-trips every imported file push accepts, OSSIE_SQL_2026 entries included, and deploys its BigQuery graph.

@merr1988 merr1988 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks Fei. I'm approving this as is given the urgency, but it would be better broken into smaller chunks (the parser fixes, the graph-properties refusal, the transpile fixes, the YAML fixes, and the Ossie import with its dialect). At 9.7k lines it is hard to review and to revert.

A lot holds up: the conversion matches upstream Ossie's schema, spec and grammar, 216 imports of the upstream corpus ran clean, and 479 of the 480 expected BigQuery texts pass a dry run. Re-checked at 00f4c59: tsc and all suites pass, and 684f3c2 fixes the field-name case I had found (Snowflake SUM(AMOUNT) now becomes orders.amount). Findings to address in follow-ups:

  1. Upstream moved: apache/ossie#703 (merged after your pin) allows AGG(dataset.metric) in model metrics. Import renames moved dataset metrics but not those references, so AGG(orders.cnt) ends up pointing at the wrong metric with ok:true (import_model.ts:1252). fidelity.md's "AGG, which Ossie reserves" is out of date too.
  2. GREATEST/LEAST: beside a TIMESTAMP they get no cast (returned(), transpile.ts:2674). Row 325's expected text fails a BigQuery dry run.
  3. model_spec.md:493: OSSIE_SQL_2026 is Ossie's own dialect (apache/ossie#439, #617), so "six added dialects" and "not valid Ossie 0.2.0.dev0" don't hold.
  4. Weeks: EXTRACT/DATE_PART week becomes ISOWEEK (ISO numbering: 2021-01-01 gives 53). That is neither "Monday weeks" nor BigQuery's value. Use WEEK(MONDAY), or document ISO.
  5. CTEs (sql_parser.ts:574): a CTE that names itself without RECURSIVE is valid in SQL Server (no such keyword) and Snowflake (optional), and push now refuses it.
  6. MySQL aliases (sql_identifiers.ts:361): they're case-sensitive by default on Linux, so FROM t AS Customer … customer.id should stay refused.
  7. Window refusal (validate.ts:350): it refuses a keyless entity the graph generator skips. Reading generatePropertyGraph(model).elements[].properties would match what deploys. BigQuery also refuses MAX() and subqueries there, so the same loop could cover them.
  8. Nit: bareExtractParts (transpile.ts:546) still defines its own word test, though 00f4c59 says every copy now calls isWordChar.

Questions:

  • go/semantic-ontology-spec §3.5.2 says each dialect names an engine. Does accepting OSSIE_SQL_2026 everywhere need a spec change or owner sign-off?
  • Is the DATE-to-TIMESTAMP cast kcmd's own choice? Then it's not "BigQuery's value".

Comment on lines +999 to +1002
const valueEnd =
(list as yaml.Node|null)?.range?.[1] ?? colon + 1;
edits.push([colon + 1, Math.max(colon + 1, valueEnd), '']);
at = nextLine(text, valueEnd);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When target already declares key with an implicit empty value and an inline comment (e.g., metrics: # model metrics), eemeli/yaml gives the empty Scalar(null) node a zero-width range at the # character (v0 === v1 with text[v1] === '#', the same case rangeOf guards against at lines 1348-1354). Setting valueEnd = list.range[1] and deleting [colon + 1, valueEnd] strips all whitespace between : and #, emitting metrics:# model metrics.

  1. Direct callers of exported movedItems get syntactically invalid YAML (Implicit map keys need to be followed by map values, since YAML 1.2 requires whitespace before # to start a comment).
  2. During kcmd import on a root-level Ossie file with metrics: # ... at the root and dataset-level metrics, reading(metricsText, moved) in rootModelText (import_model.ts:737) rejects the unparseable text edit and falls back to the JS-value path (movedDatasetMetrics + updateText), silently dropping comments on and above the moved dataset metrics.

Action item: Preserve the whitespace before # when list has a zero-width range at #:

Suggested change
const valueEnd =
(list as yaml.Node|null)?.range?.[1] ?? colon + 1;
edits.push([colon + 1, Math.max(colon + 1, valueEnd), '']);
at = nextLine(text, valueEnd);
const [v0, v1] =
(list as yaml.Node|null)?.range ?? [colon + 1, colon + 1];
const valueEnd = v0 === v1 && text[v1] === '#' ? colon + 1 : v1;
edits.push([colon + 1, Math.max(colon + 1, valueEnd), '']);
at = nextLine(text, v1);

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.

Thanks, Jun. A moved dataset metric now keeps its comments, also when the root metrics: holds only a comment or [].

…ammar, and say to run kcmd import on an Ossie file

A model file may hold an OSSIE_SQL_2026 entry, the SQL Apache Ossie
0.3.0.dev0 writes its sql texts in. ossie_parser.ts reads such a text by
Ossie's expression grammar. sql_parser.ts answers the tokens and columns of
an OSSIE_SQL_2026 text from that parser, so push, kcmd profiles and the
loader never hand an Ossie text to the SQL engine. A text the parser refuses
gets push's warning that kcmd could not read its SQL.

Every command that loads a model still refuses an Ossie 0.3.0.dev0 file and
a 0.2.0.dev0 file with its model at the document root. The error now ends
with "Run 'kcmd import <file> --flavor <ossie|google>' to convert it." Pull
leaves out each sentence that advises kcmd import when it has replaced the
local file.

For an OSSIE_SQL_2026 text, the advice for a field that names itself and for
a metric text that does not parse quotes names as Ossie does. ir.ts, the
schema's Dialect enum and model_spec.md list the dialect as Ossie's own.
…dev0 files, and convert them

A third-party import reads an Ossie file that holds its model at the
document root: a 0.3.0.dev0 file, or a 0.2.0.dev0 file as Ossie's converters
write it. Import wraps the model in semantic_model and sets the version. It
renames nonportable_extensions to custom_extensions, with each block's data
as JSON text, and moves each sql into an OSSIE_SQL_2026 entry. Where the
expression already has such an entry, the sql replaces its text, since
Ossie reads the sql as that text. Each metric a dataset lists moves to the
model's metrics, anchored on that dataset, and a dataset's empty metrics
list goes.

Names in texts take kcmd's form. A field text loses its own dataset's
qualifier, and each name takes its declared spelling. In a moved metric, a
bare field and source.<column> become <dataset>.<field>. A call of AGG
becomes the text of the metric it names. A key or join entry that names a
one-column field becomes that column. Import reports each edit. Where it
cannot make one, it leaves the text as written, with a warning. When what
it leaves keeps the written file from loading, the import stops with the
loader's error.

Every third-party import now writes a model name with a hyphen for each
character the name rule refuses. The import of a root-model file, and any
import that writes the other flavor, removes the editor schema line. Import
stops on a model whose name is missing or is not a string. It checks the
names before it converts the file, so a third-party import that stops on a
name reports only the names. It also reports any hyphens it gave the model
name, since the errors use that name. reference.md also lists what a
third-party import removes and reports, and what stops it.
…ie parser in --transpile

ossie_translate.ts reads an OSSIE_SQL_2026 text with kcmd's Ossie parser
and writes BigQuery's SQL from the tree. One table maps each construct of
Ossie's function tables that has a direct BigQuery form to that form.
MEDIAN and the percentiles become PERCENTILE_CONT and PERCENTILE_DISC over
a window, and APPROX_QUANTILES as an aggregate. A format string with a
literal format translates through a token map.

Beyond the table, the translation adds only what BigQuery needs to run the
text: a cast of a DATE or DATETIME beside a TIMESTAMP, a typed NULL where
BigQuery refuses an untyped one, a folded constant where BigQuery takes
only a literal, and the window NULL placement Ossie requires. It writes in
backticks a name that kcmd's SQL reader or BigQuery misreads bare, such as
date and current_datetime. Anything else stays untranslated, with a
warning. So does a date part BigQuery refuses for a value the text shows
to be a DATE or a TIMESTAMP: a part shorter than a day of a DATE, and a
week or longer of a TIMESTAMP in DATEADD and DATEDIFF.

transpileModel and bigQueryTranslation hand each OSSIE_SQL_2026 entry to
this translator. Every other dialect keeps the SQL engine. Import's report
adds a reminder for each form whose value can differ from the source, and
fidelity.md lists those differences. reference.md's --transpile row points
to that list.

The translator quotes a name with the backtick function of
sql_identifiers.ts. That function now escapes a backslash as well as a
backtick, as BigQuery and Spanner read a quoted name, so quoteIdentifier
does too.
… the file

YAML ends a flow-mapping entry at a comma, so a field written
{dialect: ANSI_SQL, expression: ROUND(price, 2)} holds a key `2)` with no
value. When import changed such a file, the YAML writer wrote `null` at the
start of the text, and import then reported a missing 'version'. The writer
now leaves a key with no value as written, so import reports the unknown
key itself.
A comma inside {name: total, expression: ROUND(amount, 2)} ends the entry,
so the mapping holds an unknown key `2)` with no value. The load error named
that key and the keys the mapping takes. When a model file or a profile
file holds an unknown key with no value, the error now ends with "A comma
ends an entry of a flow mapping, so if the comma belongs to the text, quote
the text."
A 0.3.0.dev0 document with no datasets, such as Apache Ossie's
flights.ontology.yaml or flights.mapping.yaml, failed to load with
"unknown version '0.3.0.dev0'". The load error now says the document holds
no Apache Ossie semantic model and that kcmd reads no other Ossie document.
…Ossie version closes dialect to an enum

model_spec.md said every Ossie 0.2.0.dev0 document is a valid kcmd model
unless it breaks a narrowing. That holds for a document with a
semantic_model list. Later Ossie schemas hold the model at the document
root and refuse that list. The section on dialects now names the Ossie
version whose dialect enum is closed and lists its ten names. It says that
a 0.3.0.dev0 file may carry a dialect kcmd does not accept.
…SAFE. has it

Under the SAFE. prefix, the SQL engine reads a BigQuery date part as a
column, and push skipped only the last argument of such a call. So push
refused SAFE.TIMESTAMP_TRUNC(orders.created_at, MONTH, 'America/Los_Angeles')
with "'MONTH' must be written as 'entity.field'". Push now skips the
argument that holds the date part in the call without SAFE.: the second for
the TRUNC functions and LAST_DAY, and the third for the DIFF functions.
…and its panic messages off the console

The SQL engine never returns on a type followed by a parenthesis the text
leaves open, as in CAST(amount AS BIGNUMERIC(40, 10. Its T-SQL parser
panics on a bare IF before a parenthesis and prints a stack trace. Every
call to the engine now goes through one wrapper in sql_parser.ts. The
wrapper hands the engine no text whose parentheses do not pair and no T-SQL
text with a bare IF before a parenthesis. Push warns that it could not read
such a text, and --transpile leaves it untranslated. The wrapper also keeps
the engine's panic messages off the console.
…ls with no arguments

--transpile passed a call with no arguments to BigQuery unchecked. PI()
stayed PI(), Snowflake's integer RANDOM() became RAND(), and a bare
ROW_NUMBER() stayed as written. PI() now becomes ACOS(-1) in the dialects
whose PI() is the double nearest pi, and stays untranslated in ANSI_SQL and
SPANNER. RANDOM() becomes RAND() for PostgreSQL, AlloyDB and Databricks,
and stays untranslated in other dialects. A bare ROW_NUMBER() stays
untranslated.
--transpile wrote a column name as the source writes it, so PostgreSQL's
größe * 2 and extract + 1 reached BigQuery bare, and BigQuery refuses both.
The translation now puts backticks on a column, table or struct field name
that is not a letter or underscore followed by letters, digits and
underscores, or that BigQuery reserves. fidelity.md says so. A variable or
a query parameter, such as SQL Server's @Threshold, stays as written.
… database does

Push compared a name with the lambda parameters, aliases and CTE names a
text binds by exact letter case. So it refused a Snowflake metric with
FILTER(orders.items, I -> i:qty > 1). Push now compares the names as the
text's database does. PostgreSQL folds an unquoted name to lower case, and
Snowflake and ANSI SQL fold it to upper case. MySQL matches a table alias
or a CTE name only in the case written. The other databases match a name
in any case.
--transpile writes a DATE literal or a cast of a date string to DATE,
compared with a column, as the plain string. Snowflake, Databricks and SQL
Server compare a text column with a date as a date, so a text column
holding '2024-01-01 10:00:00' matches the date there and not in BigQuery.
fidelity.md's list of value differences now says so. It also says that a
Databricks CAST to DATE stays SAFE_CAST, which BigQuery refuses beside a
text or TIMESTAMP column.
The SQL engine writes a comment once for each node that ends where the
comment stands, so --transpile wrote the comment of Snowflake's
status = 'done' -- finished orders two or three times. The translation now
keeps each comment as often as the text writes it. It counts the comments
it keeps by the engine's tokens, so a string is no comment, and adds each
dropped comment at the end.
…ktick or a backslash

--transpile wrote PostgreSQL's "a`b" + 1 as `a``b` + 1, which BigQuery
reads as the column a with the alias b, and "a\b" + 1 as `a\b` + 1, where
BigQuery reads \b as a backspace. BigQuery refuses a field name that holds
either character. Such a text now stays untranslated, with "kcmd does not
translate a name that holds a backtick or a backslash".
…statement word

The SQL engine reads a text that starts with a statement word as that
statement. So --transpile wrote PostgreSQL's copy IS NOT NULL as
COPY `IS` NOT NULL, which BigQuery refuses, and call = 'inbound' as
CALL=inbound. When the engine reads the text alone as another kind of node
than it reads after SELECT, or the text alone gives no BigQuery expression,
the translation now takes the reading after SELECT. A text that gives no
BigQuery expression either way stays untranslated, with a message. SQL
Server's call = 'inbound' is one, since T-SQL reads it after SELECT as an
alias.
…es where that span starts

Removing the last key of a mapping runs through the line break when that
key has no value. When the same update added a key right after the
mapping, the insertion fell inside the removed span, and the YAML writer
stopped with "Overlapping edits at offset N". kcmd import hit it on a
vanilla model converted to the Google flavor with deployments. The writer
now places such an insertion where the removed span starts.
…ter starts

The YAML writer kept every key-value pair of the input in one list and
scanned it for each key it wrote, so an import that rewrites every field
took time with the square of the file's size. The pairs now sit in two maps
built once per call: by value node, and by key and scalar value. Each
lookup keeps the scan's full test, so the output stays the same.
…t line

The YAML writer takes the end of a block list item from where its last
value ends. An empty value with no comment after it, as in `description:`,
ends before its line break, so an item the writer added after such an item
started on that line, and the file no longer parsed. Import reaches this
when it adds a field for `source.<column>` or moves a metric after such an
item. Removing such an item also left a blank line. Such an item now ends
at the start of the next line.
…hanges the file

When import changed a file, it wrote the model's metrics back from the
entries that are mappings. A stray dash left after deleting a metric by
hand disappeared with no message, under --input first-party too. Import now
removes from the model's metrics only the metrics its repairs remove. The
load check of the written file reports any other entry, as it does when
import leaves the file unchanged.
kcmd reads `datatype: Opaque` as no datatype, so import removes the key.
It removed it only when the input's flavor refused its letter case, so a
canonical Opaque, and any letter case in the Google flavor, stayed in the
written file. Every import now removes it in any letter case and reports
the removal. Under --input first-party, a letter case the input's flavor
refuses stays an error.
…f stopping

A metric whose every expression entry is in a dialect kcmd does not
accept, such as HOLISTICS_AQL or THOUGHTSPOT, is left with no SQL once
import drops those entries. Import then stopped and wrote nothing. A
third-party import now removes such a metric and reports it, as it does an
unanchored metric. Under --input first-party it stays an error. A field
keeps its behavior. The Google flavor leaves such a field unbound, and the
vanilla flavor stops.
A field expression reads only columns of its dataset's source and sibling
fields, and a metric reads only fields, so a query has no place in either.
Push refused a query only in a property of a Spanner graph. Push and kcmd
profiles now refuse a field or metric text that holds a subquery or a CTE,
in the model file and in profile bindings. This check replaces the graph's
own. It finds a query by its SELECT, so ANY and ALL over an array pass, as
in PostgreSQL's status = ANY(ARRAY['open', 'paid']). Import reports it as
it reports push's other checks. The rules that read a text's columns leave
such a text out. reference.md states the rule.
Import moves a dataset's metrics to the model's metrics when they are a
list of mappings that each have a string name, and the model's own metrics
is a list or empty. Other dataset metrics stayed as written with no
warning. The load of the written file then failed with "unknown key
'metrics'", and no line named the real problem. Import now warns for each
dataset whose metrics stay and says why: they are not a list, one of them
has no string name, or the model's metrics is not a list.
…model file

reference.md said import reads no profile file beside a root-model file.
Import does not write or check such a file, but it reads the dialect of
each table the file names, and it warns about a <model>.profiles/
directory beside the file. The sentence now says so.
…at never fires

isAggCall returned a boolean, so the loop that inlines calls of AGG tested
the node's kind again after it, only to let TypeScript read the call's
arguments. isAggCall now narrows the node to a function call, and the loop
drops the second test.
…lows it

The comment before the check of a new field's name against the model's
metrics said push refuses a field and a metric of one entity with one
name. The check covers every metric of the model, since a BigQuery graph
also refuses a metric named like a field of another entity. The comment
now states both rules.
…lookup read

Push's check for a subquery or a CTE read an ANSI_SQL text as generic SQL
when no lookup read its tables' dialect. The checks that read the text's
columns skip such a text. A text such as '''a' || (SELECT 1) || 'b''', which
Spanner reads as one string, then stopped kcmd import of a first-party file
whose Spanner lookup failed. The query check now skips such a text too, in
the model file and in profile bindings. Pull reads such a text as generic
SQL, and its check of profile bindings stays as it was.
…differ in inner white space

--transpile counted the comments of a text by their text without any white
space, so /* a b */ and /* ab */ counted as one comment. For
(x = y /* a b */) AND (z = 1 /* ab */) it dropped /* ab */ and wrote
/* a b */ twice. The count now ignores only the white space at the start and
the end of a comment's text. The engine adds a space there, and a line
comment's text is trimmed.
No test put an OSSIE_SQL_2026 text in a profile binding. The new test binds
a field of Order to Customer.key * 2 in that dialect. The profile check
reads the text with the Ossie parser and reports that a field expression
reads only its own entity.
…hecked when the text alone fails

The comment in engineTranslation said a text is translated after SELECT
only when that gives a BigQuery expression. That check runs only when the
engine reads the text alone into SQL that is not one BigQuery expression,
or the text reads as a statement. When the engine cannot read the text
alone, the code takes the translation after SELECT without the check. The
comment now says so.
Push found a query in a field or metric text only by its SELECT, so
id = (VALUES (1)) and id = (WITH c AS (VALUES (1)) VALUES (2)) passed. Main
refused both on a Spanner graph. A VALUES list now counts as a query when
it is the body of a subquery, as in those texts and in x = ANY(VALUES (1)).
ANY over an array still passes. So does a Snowflake object constant such as
{'P': 'Pending'}[status], whose values the parser gives the same key.
… DATE of PARSE_DATETIME

BigQuery's PARSE_DATE refuses a time of day in its format at run time, so
TO_DATE(s, 'YYYY-MM-DD HH24:MI:SS') failed on every value that is not
NULL. When the format has a time of day, TO_DATE now becomes
DATE(PARSE_DATETIME(format, s)). fidelity.md no longer lists the case
among the forms BigQuery refuses.
…of a comparison

A simple CASE compares its value with each WHEN value, but only got the
casts to TIMESTAMP. So CASE created_at WHEN DATE '2024-01-01' THEN 1
ELSE 0 END stayed as written, and BigQuery refuses it for a TIMESTAMP
column. It now gets the DATETIME casts that created_at = DATE
'2024-01-01' gets.
…parameters

Constant folding gave a DECIMAL or NUMERIC without parameters a scale of
0, while the cast the translator writes keeps BigQuery's 9 places. So
APPROX_PERCENTILE(x, CAST(0.25 AS DECIMAL)) became the minimum,
APPROX_QUANTILES(x, 100)[OFFSET(0)]. Folding now keeps 9 places, and the
same text becomes APPROX_QUANTILES(x, 100)[OFFSET(25)].
…value that is visibly not a number

BigQuery takes a RANGE offset only beside an ORDER BY value that is a
number. The translator checked the key's type only when it was visibly
an INT64, so a frame such as ORDER BY CAST(ts AS DATE) NULLS FIRST RANGE
BETWEEN 1 PRECEDING AND CURRENT ROW was written as it stood. When the
key's type is visible and is not a number, the offset now stays
untranslated with a warning. A key of a number type, or of a type the
translator cannot see, keeps the current behavior.
…ering in fidelity.md

BigQuery's DAYOFWEEK numbers the days from Sunday as 1 to Saturday as 7,
where Snowflake and PostgreSQL count Sunday as 0 and Saturday as 6. So
DATE_PART('dayofweek', d) IN (6, 7), as Ossie's ThoughtSpot converter
writes a weekend, is true on Friday and Saturday in BigQuery. Import now
prints a reminder line when an OSSIE_SQL_2026 text reads DAYOFWEEK in
EXTRACT or DATE_PART, and fidelity.md states the numbering.
…matches any part of the text

REGEXP_CONTAINS is true when the pattern matches any part of the text, as
in Databricks and PostgreSQL. Snowflake's REGEXP_LIKE matches the pattern
only against the whole text. fidelity.md now lists the difference.
Rows in a LAG, LEAD or NTILE argument, a frame offset and a percentile
fraction now reach every operation folding computes: the arithmetic
operators, FLOOR, CEIL, CEILING, POWER, ROUND and TRUNC with places,
GREATEST, LEAST, each comparison, IS NULL, NOT, AND and OR with NULL,
both forms of CASE, IF, IFF, COALESCE, NULLIF, and casts to each number
type. Rows also show that a cast to another type, a column and an
aggregate stay untranslated.
… and fidelity.md

Import adds the cast reminder for STRING(n) as well as VARCHAR(n), since
both become BigQuery's STRING. The reminder, the comment on the cast and
fidelity.md now name both.
…eses again for each IN in them

The parser's header said each text is read once, in time linear in its
length. When its first reading of a POSITION fails, the parser reads
POSITION's parentheses again for each IN at their top level, so a
POSITION with thousands of such INs takes seconds. The header now says
so.
…parser uses

regularNameEnd, ossieIdentifier and ossieWindowValues are used only
inside ossie_parser.ts, and no other module, test or script names them.
… key

A key written with no colon, such as `b` in `m: {a: 1, b}` or `? b` in a
block mapping, has no position for a value. When import set such a key,
the YAML writer wrote the value at the start of the file, and import
stopped with a parse error or "missing 'version'". The writer now writes
`: <value>` right after the key in a flow mapping. In a block mapping it
writes the colon on the next line, under the `?`. A key whose value stays
null keeps its text.
The YAML writer took a key's column from the key's own text. A key
written after `?`, an anchor or a tag, such as `?     datasets`, starts
to the right of its pair. When the list under such a key sat left of the
key's text, the writer computed a negative indent, and import threw a
RangeError. When such a key came first in a mapping, the writer put new
keys at the wrong column. The writer now takes each pair's column from
where the pair starts, so import converts such a file as it converts the
same file without those marks, and keeps the marks.
…ad error

A YAML alias inside the value its anchor names, such as `*a` in
`data: &a {self: *a}`, makes a value that holds itself. Import overflowed
the stack while it copied such a document, in a root-model file and in a
wrapped 0.2.0.dev0 file alike. The loader accepted such a value where it
does not check the shape, such as a custom ai_context member. Import and
the loader now read a model file through one function, which reports such
an alias as a load error that names it and gives its line and column.
…ry is

Push found a VALUES list only as the body of a subquery, so
EXISTS (WITH c AS (SELECT 1) VALUES (1)) and
o_code IN (WITH c AS (SELECT 1) VALUES (1)) passed. The parser drops that
WITH and gives the VALUES list to EXISTS or IN directly.

One rule now says what a query is: a SELECT, a VALUES list, a WITH, or a
UNION, INTERSECT or EXCEPT whose branches are queries. A text holds a
subquery when a SELECT or a WITH appears anywhere in it, or when a query is
the body of a subquery, of EXISTS or of IN, or the operand of ANY or ALL.
ANY over an array and a Snowflake object constant still pass.
…les may have

When no lookup read the dialect of a model's tables, kcmd import skipped the
query check of an ANSI_SQL text, and pull checked the text as generic SQL. So
an import whose Spanner lookup failed wrote a model with id + (SELECT 1) or
id = (VALUES (1)), while pull refused '''a' || (SELECT 1) || 'b''', which
Spanner reads as one string.

Such a text now holds a query only when it holds one in each dialect its
tables may have. These are the dialects columnsWithoutDialect takes. Import
and pull now agree, in the model file and in profile bindings: they refuse
the first two texts and accept the third.
…alue, which refuses a value that holds itself

Only the loader and import's first read refused an alias inside the value
its anchor names, such as `*a` in `executor: &a {self: *a}`. The other
readers of model and profile files called yaml.parse or toJS and got a
value that holds itself. kcmd import --transpile overflowed the stack on a
profile file with such an alias, and push accepted a profile file that
held one in its actions. These readers now take the value from
documentValue, which parses the text itself unless the caller passes a
parsed document. A file with such an alias does not parse for any of
them, and the error names the alias's line and column. The lookup of a
vanilla model's GOOGLE block profiles still reads past such an alias
outside the blocks, as it reads past a key set twice, and reports the load
error for one inside a block.
@feixufeixu
feixufeixu force-pushed the feat/import/ossie-0.3 branch from 00f4c59 to 7826406 Compare November 16, 2026 00:00
@feixufeixu
feixufeixu merged commit 10beeb9 into main Nov 16, 2026
8 checks passed
@feixufeixu

Copy link
Copy Markdown
Collaborator Author

Thanks, Miguel. I rebuilt the PR from main before merging, and it went in as 48 commits and about 5,750 added lines instead of 9,700. Your findings, in your order:

  1. AGG: import now writes AGG(dataset.metric) in a model metric as that metric's text, so the renamed metric no longer matters. fidelity.md no longer says Ossie reserves AGG.
  2. GREATEST/LEAST: the value beside a TIMESTAMP is cast in every construct now, also through COALESCE, IF, CASE, NULLIF, DATE_TRUNC and DATEADD. For example, GREATEST(COALESCE(d, CURRENT_TIMESTAMP), CURRENT_DATE) casts d and CURRENT_DATE to TIMESTAMP and runs on BigQuery.
  3. model_spec.md: the dialect paragraph now says OSSIE_SQL_2026 is the SQL Ossie 0.3.0.dev0 writes sql in, and it lists the ten dialects kcmd accepts without calling any of them added or invalid in Ossie.
  4. Weeks: fidelity.md now says week numbers are ISO weeks, so 2021-01-01 is week 53.
  5. CTEs: the CTE scoping change is gone. Push now refuses a field or metric text that holds a subquery or a CTE, which kcmd does not support.
  6. MySQL aliases stay case-sensitive.
  7. The graph-property window refusal is gone. Push's dry run of the graph DDL still reports those cases before it writes.
  8. bareExtractParts is gone with the rest of that code.

On your second question: yes, the DATE-to-TIMESTAMP cast is kcmd's choice, and fidelity.md now says so.

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.

3 participants