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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [configuration, native-wheel, native-test-ops]
services:
postgres: *postgres-service
env:
CELL: ref-pandas3
CELL_PINS: pandas==3.0.6 pyarrow==25.0.1 numpy==2.5.3
Expand Down Expand Up @@ -872,6 +874,9 @@ jobs:
"$RUNNER_TEMP/kit/bin/python" -I -c 'import sdm_client._native as n; assert n.TEST_OPS'
echo "SDM_KIT_PYTHON=$RUNNER_TEMP/kit/bin/python" >> "$GITHUB_ENV"
- name: The runner's controls and the route tests
env:
SDM_POSTGRES_TEST_DSN: postgresql://postgres:postgres@localhost:5432/sdm_test
SDM_REQUIRE_POSTGRES: '1'
run: python -m pytest contract/tests -q -m 'not tooling' -n auto --dist loadfile --timeout=600 --max-worker-restart=0
# Observe the installed native client in each supported dependency cell.
- &contract-gate
Expand Down
9 changes: 0 additions & 9 deletions contract/fixtures/maintained/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
These fixtures hold independent expected facts for current correctness tests.
Tests need only this checkout; historical clients, archives and recording tools are not dependencies.

- `label-expectations.json` contains only the four label cases' expected context rows and counts.
Write-guard and provider-layout tests exercise these facts without loading full driver result logs.
- `snowflake.json` contains the statements and result references for the 14 cases used by the public Python Snowflake tests.
`snowflake/` shares identical Arrow IPC streams by their SHA-256 names.
Original driver Arrow bytes are preserved, including their types and metadata.
Expand All @@ -18,13 +16,6 @@ Tests need only this checkout; historical clients, archives and recording tools
- `consumers.json` names the current consumers and reviewed byte limits for large retained fixtures.
New oversized fixtures require an explicit entry and explanation.

Eight fixtures elsewhere under `contract/` use `sdm-shared-fixture/1`.
Named fields have dictionaries of literal values; ordered rows reference those dictionaries, with `-1` for an absent field.
Nested tables can reference only earlier tables.
This shares repeated inputs and expected results while preserving every case, its order, nulls and JSON types.
The expanded SHA-256 binds the complete original logical JSON document.
The Python and Rust test helpers expand these literals without calling product code to compute expectations.

The original extraction tool and recording-completeness tests were migration-only and have been removed.
Git history retains their implementation and original fixtures.
Maintain expected values from documented behavior and independently calculated examples; do not regenerate expected answers from the product under test.
Expand Down
46 changes: 24 additions & 22 deletions contract/tests/test_column_name_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ def _module(name: str, path: Path) -> ModuleType:
ROOT / 'contract/support/column_name_scenarios.py',
)

MESSAGES = {
'task': (
"[INVALID_REQUEST] task='regression' settles what a single-table "
'question is asking, which is the only route that has to decide. A '
'relational query resolves to its own kind, so state it in the '
'query rather than beside it'
),
'typo': (
"[INVALID_REQUEST] '<pql>' is not a query a relational model can "
"answer: row 1, column 12: Column 'pricee' does not exist in table "
"'orders'. Please be mindful of case sensitivity and ensure that the "
'name is spelled correctly.'
),
'parts': (
'[INVALID_REQUEST] 2 forecast steps means 2 calls, one for each, '
'because the model has no task that answers them together. That is '
'past the 1 this will do without being told to; ask about fewer, or '
'raise sdm_client.decompose.MOST_PARTS if the wait is what you want.'
),
}


def reachable(database: str) -> bool:
if database != 'postgres' or os.environ.get('SDM_POSTGRES_TEST_DSN'):
Expand All @@ -59,25 +80,6 @@ def test_column_names_preserve_actionable_diagnostics(vector) -> None:
'StructuredDataError',
'INVALID_REQUEST',
)
fragments = {
'task': [
"task='regression'",
'single-table',
'relational query',
'state it in the query',
],
'typo': [
vector['pql'],
"Column 'pricee' does not exist in table 'orders'",
'case sensitivity',
'spelled correctly',
],
'parts': [
'2 forecast steps means 2 calls',
'past the 1 this will do',
'ask about fewer',
'raise sdm_client.decompose.MOST_PARTS',
],
}
for fragment in fragments[vector['kind']]:
assert fragment in got['message']
assert got['message'] == MESSAGES[vector['kind']].replace(
'<pql>', vector['pql']
)
56 changes: 40 additions & 16 deletions contract/tests/test_decimal_semantic_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ def case() -> tuple[dict[str, Any], str]:
return loaded, digest


def column_d(line: dict[str, Any]) -> dict[str, Any]:
r"""``orders.d`` in a line's public schema."""
[orders] = [
t for t in line['public']['schema']['tables'] if t['name'] == 'orders'
]
[d] = [c for c in orders['columns'] if c['name'] == 'd']
return d


def test_the_case_is_a_scaled_decimal_past_float64() -> None:
r"""The case is what it names: one setup statement adding ``orders.d``,
a ``DECIMAL(38, 18)`` stepping by 1e-18 over the shop base's 80 orders,
Expand Down Expand Up @@ -129,10 +120,43 @@ def test_decimal_column_has_connector_specific_semantic_type(
assert 'describe_source' in line['identity']['operations']
assert line['outcome']['result'] == 'success'
assert line['outcome']['stage'] == 'from_source'
expected = (
{'dtype': 'string', 'stype': 'text'}
if database == 'sqlite'
else {'dtype': 'float64', 'stype': 'categorical'}
)
column = column_d(line)
assert {name: column[name] for name in expected} == expected
sqlite = database == 'sqlite'

def column(name: str, dtype: str, stype: str) -> dict[str, str]:
return {'dtype': dtype, 'name': name, 'stype': stype}

assert line['public']['schema'] == {
'links': [['orders', 'user_id', 'users', 'user_id']],
'tables': [
{
'columns': [
column('order_id', 'int64', 'ID'),
column('user_id', 'int64', 'ID'),
column('price', 'float64', 'numerical'),
column(
'ts',
'string' if sqlite else 'timestamp[us]',
'timestamp',
),
column('d', 'string', 'text')
if sqlite
else column('d', 'float64', 'categorical'),
],
'duplicate_keys': 0,
'name': 'orders',
'primary_key': 'order_id',
'time_column': 'ts',
},
{
'columns': [
column('user_id', 'int64', 'ID'),
column('age', 'int64', 'numerical'),
column('country', 'string', 'categorical'),
],
'duplicate_keys': 0,
'name': 'users',
'primary_key': 'user_id',
'time_column': None,
},
],
}
65 changes: 40 additions & 25 deletions contract/tests/test_public_error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ def test_public_refusal_names_the_invalid_input(case_key: str) -> None:
'INVALID_REQUEST',
)
required_words = ['users.d', 'type string', 'constant', 'quotes']
elif case_key == 'key.uint64-above-int64-max@sqlite':
# The maintained SQLite path now handles this input successfully.
elif case_key in {
'key.uint64-above-int64-max@sqlite',
'key.uint64-above-int64-max@postgres',
}:
# SQLite and PostgreSQL read these keys as exact text and succeed.
assert _outcome(got['outcome']) == ('success', 'predict', None, None)
return
elif case_key == 'key.uint64-above-int64-max@postgres':
expected = ('refusal', 'from_source', 'OverflowError', None)
required_words = ['int']
assert same_outcome(expected, _outcome(got['outcome'])), case_key
said = _words(got['message'])
assert not said.startswith(GENERIC), (
Expand Down Expand Up @@ -349,24 +349,33 @@ def test_public_warnings_name_source_bounds_and_index_requirements(
assert len(warnings) == count, (case_key, label, got['warnings'])
if not count:
return
message = warnings[0][1]
if label == 'context-before-data':
bounds = (
('2023-12-03', '2024-01-01')
if case_id == 'shape.star.customers'
else ('2022-12-31', '2023-01-01')
)
assert all(bound in message for bound in bounds), message
elif label == 'anchor-after-data':
assert '2030-01-01' in message and '2024-07-07' in message
elif label == 'missing-indices':
counts = ('7', '4') if case_id == 'shape.star.customers' else ('3', '2')
assert (
f'Missing {counts[0]} indices in {counts[1]} tables' in message
), message
assert 'primary' in message and 'foreign' in message, message
else:
assert message == 'overflow encountered in cast'
star = case_id == 'shape.star.customers'
expected_message = {
'context-before-data': (
'Context anchor timestamp is too early or aggregation time range '
'is too large. To form proper input data, we would need data back '
"to '{}', however, your data only contains data back to '{}'."
).format(
*(
('2023-12-03 00:00:00', '2024-01-01 00:00:00')
if star
else ('2022-12-31 00:00:00', '2023-01-01 00:00:00')
)
),
'anchor-after-data': (
"Anchor timestamp '2030-01-01 00:00:00' is after the latest "
"timestamp '2024-07-07 00:00:00' in the data. Please make sure "
'this is intended.'
),
'missing-indices': (
'Missing {} indices in {} tables for optimal database querying. '
'For improving runtime, we strongly suggest to create indices for '
'primary and foreign keys, e.g., automatically by instantiating '
'Kumo Relational via `KumoRelational(graph, optimize=True)`.'
).format(*((7, 4) if star else (3, 2))),
'runtime-warning': 'overflow encountered in cast',
}[label]
assert warnings[0][1] == expected_message


@pytest.mark.parametrize('name', sorted(INFINITY_SHOWN))
Expand All @@ -383,8 +392,14 @@ def test_infinite_timestamp_bounds_have_actionable_warning(name: str) -> None:
warning for warning in got['warnings'] if 'time column' in warning[1]
]
assert len(guessed) == 1
assert guessed[0][0] == 'SDMWarning'
assert INFINITY_SHOWN[name] in guessed[0][1]
assert guessed[0] == [
'SDMWarning',
'Some time columns were inferred, or refused, on a guess about what '
'a column holds:\n- events.f was not taken as the time column because '
f'every row that holds a value holds {INFINITY_SHOWN[name]}. If it '
'does say when a row became true, name it: '
"time_columns={'events': 'f'}.",
]


def test_diagnostic_cases_and_connector_selectors_are_complete() -> None:
Expand Down
87 changes: 87 additions & 0 deletions rust/crates/sdm-core/tests/view_words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,93 @@ fn unsafe_text_and_untrusted_calls_are_worded_by_name() {
);
}

#[test]
Comment thread
adi-kumo marked this conversation as resolved.
Resolved
fn every_expression_refusal_reason_keeps_its_wording() {
for (expr, dialect, expected) in [
(
"\u{1c}select\u{1c}1",
None,
"it contains the SQL keyword 'select'",
),
("x --", None, "it contains '--'"),
(
"X FROM PAYROLL //",
Some(ExprDialect::Snowflake),
"it contains '//'",
),
("x)", None, "it closes a '(' it never opened"),
("(x", None, "it leaves a '(' unclosed"),
(
"a$$ + secret(x) + b$$",
None,
"it leaves '$$' unpaired, so which part of it is quoted text cannot be established",
),
(
"$$x$$",
Some(ExprDialect::Databricks),
"it contains '$$', which Databricks SQL does not quote with",
),
(
"\"MY\\COL\" * 2",
Some(ExprDialect::Snowflake),
"it has a backslash inside a double-quoted name",
),
] {
let reason = view_expr::unsafe_reason(expr, dialect, spaces())
.map(|r| view_words::expr_reason(&r, dialect_words(&r)));
assert_eq!(reason.as_deref(), Some(expected), "{expr:?}");
}
let wide = ["a", "col", "d", "name", "order_date", "x", "y", "z"];
for (expr, dialect, columns, expected) in [
(
"cat.sch.f(x)",
ExprDialect::Databricks,
&wide[..],
"it calls the qualified function 'f'",
),
(
"`f`(x)",
ExprDialect::Databricks,
&wide[..],
"it calls a function by a quoted name",
),
(
"a[0](x)",
ExprDialect::Databricks,
&wide[..],
"it calls the result of an expression",
),
(
"identifier(x)",
ExprDialect::Databricks,
&["x"][..],
"it names a function through IDENTIFIER()",
),
(
"user",
ExprDialect::Databricks,
&["x"][..],
"it reads the session value 'user'",
),
(
"`user`",
ExprDialect::Databricks,
&["x"][..],
"it reads the session value `user`",
),
(
"\"user\"",
ExprDialect::Snowflake,
&["x"][..],
"it reads the session value \"user\"",
),
] {
let reason = view_expr::untrusted_call_reason(expr, dialect, columns, spaces())
.map(|r| view_words::expr_reason(&r, dialect_words(&r)));
assert_eq!(reason.as_deref(), Some(expected), "{expr:?}");
}
}

#[test]
fn yaml_defaults_have_explicit_values_and_refusals() {
for (kind, input, expected) in [
Expand Down
27 changes: 22 additions & 5 deletions rust/crates/sdm-data/tests/databricks_plans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,30 @@ fn qualified_identifiers_preserve_each_part_and_escape_backticks() {

#[test]
fn keyed_reads_unpack_the_bound_json_parameter_by_position() {
for kind in ["lookup", "neighbors"] {
let cte = |columns: &str, element: &str| {
format!(
"WITH TMP AS (\n SELECT CAST(pos AS BIGINT) AS `batch`, {columns}\n FROM posexplode(from_json(?, 'array<{element}>'))\n)\n"
)
};
let cases = [
("lookup", "int64", cte("col AS `key`", "bigint")),
("lookup", "float64", cte("col AS `key`", "double")),
("lookup", "utf8", cte("col AS `key`", "string")),
(
"neighbors",
"int64",
cte(
"col.id AS `key`, col.e AS `end`",
"struct<id:bigint,e:string>",
),
),
];
for (kind, key_type, expected) in cases {
let mut input = serde_json::json!({
"request":kind,"table":{"source":["main","shop","users"]},
"key":["id"],"columns":["id","at"],
"seeds":{"attachment":7,"columns":[
{"name":"key","nullable":false,"type":{"type":"int64"}},
{"name":"key","nullable":false,"type":{"type":key_type}},
{"name":"batch","nullable":false,"type":{"type":"int64"}}
]}
});
Expand All @@ -157,11 +175,10 @@ fn keyed_reads_unpack_the_bound_json_parameter_by_position() {
assert_eq!(bound.len(), 1);
let statement = bound[0];
assert!(
statement.text.contains("posexplode(from_json(?, 'array<"),
"{}",
statement.text.starts_with(&expected),
"{kind} {key_type}: {}",
statement.text
);
assert!(statement.text.contains("key") && statement.text.contains("batch"));
let SqlParam::KeySet { keys, .. } = &statement.params[0] else {
panic!("key parameter")
};
Expand Down
Loading
Loading