Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ on:
paths:
- 'python/**'
- 'core-spec/**'
- 'extensions/**'
- '.github/workflows/python-ci.yml'
pull_request:
branches: [ "main" ]
paths:
- 'python/**'
- 'core-spec/**'
- 'extensions/**'
- '.github/workflows/python-ci.yml'

permissions:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/validation-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ on:
- "validation/**"
- "python/**"
- "core-spec/**"
- "extensions/**"
- "ontology/**"
- "examples/flights*.yaml"
- "examples/tpcds_semantic_model.yaml"
Expand All @@ -37,6 +38,7 @@ on:
- "validation/**"
- "python/**"
- "core-spec/**"
- "extensions/**"
- "ontology/**"
- "examples/flights*.yaml"
- "examples/tpcds_semantic_model.yaml"
Expand Down
1 change: 1 addition & 0 deletions extensions/vendors.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ community uses (see [`README.md`](README.md) for how these lists are used).
| `DBT` | dbt-specific attributes |
| `DATABRICKS` | Databricks-specific attributes |
| `GOODDATA` | GoodData-specific attributes |
| `SEMANTIDO` | Semantido-specific attributes |
| `HONEYDEW` | Honeydew-specific attributes |
| `WISDOM` | WisdomAI-specific attributes |
| `POWER_BI` | Microsoft Power BI-specific attributes |
Expand Down
3 changes: 3 additions & 0 deletions python/src/ossie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ class OssieVendor(str, Enum):
DATABRICKS = "DATABRICKS"
GOODDATA = "GOODDATA"
SEMANTIDO = "SEMANTIDO"
HONEYDEW = "HONEYDEW"
WISDOM = "WISDOM"
POWER_BI = "POWER_BI"
SIGMA = "SIGMA"
THOUGHTSPOT = "THOUGHTSPOT"
HEX = "HEX"
ATACCAMA = "ATACCAMA"

Expand Down
26 changes: 26 additions & 0 deletions python/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import json
import re
from collections.abc import Callable
from pathlib import Path

Expand All @@ -37,6 +38,7 @@
OssieMetric,
OssieRelationship,
OssieSemanticModel,
OssieVendor,
)


Expand All @@ -56,6 +58,30 @@ def test_dialect_is_free_form_in_core_schema() -> None:
assert "OSSIE_SQL_2026" in dialect["examples"]


def _registered_tokens(registry: str) -> set[str]:
"""The tokens in the table of extensions/<registry>.md."""
path = Path(__file__).parents[2] / "extensions" / f"{registry}.md"
return {
match.group(1)
for line in path.read_text(encoding="utf-8").splitlines()
if (match := re.match(r"^\|\s*`([^`]+)`\s*\|", line))
}


def test_dialect_enum_matches_the_registry() -> None:
# The field accepts any string; the enum is the well-known values, so it
# carries exactly what extensions/dialects.md registers.
assert {member.value for member in OssieDialect} == _registered_tokens("dialects"), (
"OssieDialect and extensions/dialects.md do not list the same dialects"
)


def test_vendor_enum_matches_the_registry() -> None:
assert {member.value for member in OssieVendor} == _registered_tokens("vendors"), (
"OssieVendor and extensions/vendors.md do not list the same vendors"
)


@pytest.mark.parametrize(
"dialect",
["ANSI_SQL", OssieDialect.ANSI_SQL],
Expand Down
44 changes: 44 additions & 0 deletions validation/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import copy
import json
import re
import urllib.request
from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path
Expand Down Expand Up @@ -348,6 +349,49 @@ def test_holistics_aql_is_skipped_rather_than_parsed_as_sql() -> None:
assert "HOLISTICS_AQL" not in _VALIDATE.SQLGLOT_DIALECTS


def _registered_dialects() -> set[str]:
"""The tokens in the table of extensions/dialects.md."""
registry = Path(__file__).parents[2] / "extensions" / "dialects.md"
return {
match.group(1)
for line in registry.read_text(encoding="utf-8").splitlines()
if (match := re.match(r"^\|\s*`([^`]+)`\s*\|", line))
}


def test_the_dialect_tables_match_the_registry() -> None:
# A dialect registered in extensions/dialects.md has to be listed here as
# well, as the sqlglot reader that parses it or as one sqlglot cannot read,
# or the validator warns about a token the registry says is fine. A dialect
# listed here but not in the registry is a registration someone skipped.
known = set(_VALIDATE.SQLGLOT_DIALECTS) | _VALIDATE.NON_SQL_DIALECTS

assert known == _registered_dialects(), (
"extensions/dialects.md and SQLGLOT_DIALECTS / NON_SQL_DIALECTS in"
" validate.py do not list the same dialects; register a dialect in both"
)
Comment on lines +369 to +372

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.

(non-blocking) it might be easier for people adding / modifying the dialects/extensions if we printed the diffs - could be a followup pr

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in #670: the message now names the file each missing token belongs in.

assert set(_VALIDATE.SQLGLOT_DIALECTS) & _VALIDATE.NON_SQL_DIALECTS == set()


def test_only_the_portable_dialects_use_the_default_reader() -> None:
# A None reader is sqlglot's default, which only ANSI_SQL and the portable
# language are meant to be parsed with.
default_reader = {d for d, reader in _VALIDATE.SQLGLOT_DIALECTS.items() if reader is None}

assert default_reader == {"ANSI_SQL", _VALIDATE.PORTABLE_DIALECT}


def test_every_sqlglot_reader_exists() -> None:
# Separate from the registry checks so that those still run without
# sqlglot. A misspelled reader passes them and then makes sqlglot raise
# ValueError, which _parse_sql_expression does not catch.
sqlglot = pytest.importorskip("sqlglot")

for reader in _VALIDATE.SQLGLOT_DIALECTS.values():
if reader is not None:
sqlglot.Dialect.get_or_raise(reader)


def test_a_holistics_aql_expression_is_not_reported_as_invalid_sql() -> None:
# `|` is AQL's pipe operator. Parsed as SQL it is a bitwise OR over two
# names, which sqlglot accepts, so the skip is asserted through a body that
Expand Down
8 changes: 5 additions & 3 deletions validation/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,11 @@ def validate_sql(data: dict) -> list[str]:

model_name = data.get("name", "<unnamed>")
errors = []
# A dialect outside both sets is one this validator cannot parse. It may be a
# legitimate entry from extensions/dialects.md, so warn once that its
# expressions went unchecked rather than treat it as an error.
# A dialect outside both sets is one this validator does not know. The two
# sets are pinned to extensions/dialects.md, so this is a token the registry
# does not have either; it is still legitimate (dialect is free-form), so
# warn once that its expressions went unchecked rather than treat it as an
# error.
unsupported_dialects = Counter()

for expression in iter_expressions(data):
Expand Down
Loading