Skip to content

Commit d871658

Browse files
committed
Version schema-changing SPSS frontend submissions
1 parent be1ed43 commit d871658

6 files changed

Lines changed: 54 additions & 6 deletions

File tree

src/openstatspec/frontends/spss/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
"""SPSS syntax frontend for canonical OpenStatSpec transformation plans."""
22

33
from .binding import bind_spss_syntax
4-
from .compiler import SpssFrontendCompilation, compile_spss_syntax
4+
from .compiler import (
5+
SPSS_FRONTEND_CONTRACT,
6+
SPSS_FRONTEND_SCHEMA_CHANGE_CONTRACT,
7+
SpssFrontendCompilation,
8+
compile_spss_syntax,
9+
)
510
from .syntax import (
611
SpssSyntaxProgram,
712
normalize_spss_source,
@@ -11,10 +16,9 @@
1116
)
1217

1318

14-
SPSS_FRONTEND_CONTRACT = "openstatspec-spss-syntax-frontend-v0.2"
15-
1619
__all__ = [
1720
"SPSS_FRONTEND_CONTRACT",
21+
"SPSS_FRONTEND_SCHEMA_CHANGE_CONTRACT",
1822
"SpssFrontendCompilation",
1923
"SpssSyntaxProgram",
2024
"bind_spss_syntax",

src/openstatspec/frontends/spss/compiler.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
from dataclasses import dataclass
66

7-
from ...transform.plan import TransformationPlan
7+
from ...transform.plan import (
8+
TRANSFORMATION_PLAN_SCHEMA_CHANGE_CONTRACT,
9+
TransformationPlan,
10+
)
811
from ...transform.schema import BoundTransformation, VariableSchema
912
from .binding import bind_spss_syntax
1013
from .syntax import (
@@ -14,6 +17,10 @@
1417
)
1518

1619

20+
SPSS_FRONTEND_CONTRACT = "openstatspec-spss-syntax-frontend-v0.2"
21+
SPSS_FRONTEND_SCHEMA_CHANGE_CONTRACT = "openstatspec-spss-syntax-frontend-v0.3"
22+
23+
1724
@dataclass(frozen=True)
1825
class SpssFrontendCompilation:
1926
"""One source artifact and its fully bound canonical plan."""
@@ -30,6 +37,12 @@ def plan(self) -> TransformationPlan:
3037
def plan_hash(self) -> str:
3138
return self.plan.sha256()
3239

40+
@property
41+
def frontend_contract(self) -> str:
42+
if self.plan.contract == TRANSFORMATION_PLAN_SCHEMA_CHANGE_CONTRACT:
43+
return SPSS_FRONTEND_SCHEMA_CHANGE_CONTRACT
44+
return SPSS_FRONTEND_CONTRACT
45+
3346

3447
def compile_spss_syntax(
3548
source: str,

src/openstatspec/frontends/spss/execution.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
_run_in_place_submission,
1111
load_transformation_schema,
1212
)
13-
from . import SPSS_FRONTEND_CONTRACT
1413
from .compiler import compile_spss_syntax
1514

1615

@@ -37,7 +36,7 @@ def prepare(connection: Any, live_dataset_id: str) -> InPlacePlanSubmission:
3736
plan=compilation.plan,
3837
source_kind="spss_syntax",
3938
source_hash=compilation.source_hash,
40-
frontend_contract=SPSS_FRONTEND_CONTRACT,
39+
frontend_contract=compilation.frontend_contract,
4140
)
4241

4342
return _run_in_place_submission(

src/openstatspec/transform/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"BoundTransformation",
2525
"RecodeMatch", "RecodeOperation", "RecodeResult",
2626
"RecodeRule", "ReplaceValueLabelsOperation", "SPSS_FRONTEND_CONTRACT",
27+
"SPSS_FRONTEND_SCHEMA_CHANGE_CONTRACT",
2728
"SetFormatOperation", "SetMeasurementLevelOperation",
2829
"SetVariableLabelOperation", "SourcePosition", "SourceSpan", "StorageKind",
2930
"SpssFrontendCompilation",
@@ -42,6 +43,7 @@
4243

4344
_SPSS_COMPAT_EXPORTS = {
4445
"SPSS_FRONTEND_CONTRACT",
46+
"SPSS_FRONTEND_SCHEMA_CHANGE_CONTRACT",
4547
"SpssFrontendCompilation",
4648
"SpssSyntaxProgram",
4749
"bind_spss_syntax",

tests/test_inplace_transform.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,25 @@ def test_public_apply_supports_non_dolt_without_building_undo(catalog) -> None:
447447
)
448448

449449

450+
def test_schema_commands_record_the_v03_frontend_contract(catalog) -> None:
451+
url, path, dataset_id, _table_name = catalog
452+
453+
openstatspec.apply_spss_in_place(
454+
database_url=url,
455+
dataset_id=dataset_id,
456+
source_text="STRING note (A4).",
457+
actor="test-agent",
458+
)
459+
460+
audit = sqlite3.connect(path).execute(
461+
"SELECT source_kind, frontend_contract FROM transformation_apply"
462+
).fetchone()
463+
assert audit == (
464+
"spss_syntax",
465+
"openstatspec-spss-syntax-frontend-v0.3",
466+
)
467+
468+
450469
@pytest.mark.parametrize("as_mapping", [False, True])
451470
def test_public_generic_plan_apply_accepts_object_and_mapping(
452471
catalog, as_mapping,

tests/test_transform_frontend.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,17 @@ def test_source_normalization_hash_and_positions_are_stable() -> None:
368368
assert compilation.source_text_lf == lf
369369
assert compilation.source_hash == spss_source_hash(lf)
370370
assert compilation.plan_hash == compilation.plan.sha256()
371+
assert compilation.frontend_contract == "openstatspec-spss-syntax-frontend-v0.2"
372+
373+
374+
def test_schema_commands_use_the_v03_frontend_contract() -> None:
375+
compilation = compile_spss_syntax(
376+
"STRING note (A4).",
377+
_schema(VariableDefinition("q1", "numeric")),
378+
)
379+
380+
assert compilation.plan.contract == "openstatspec-transformation-plan-v0.3"
381+
assert compilation.frontend_contract == "openstatspec-spss-syntax-frontend-v0.3"
371382

372383
def test_string_comparison_fails_closed_until_exact_collation_is_supported() -> None:
373384
error = _error(

0 commit comments

Comments
 (0)