sunstone-data-platform 1.5.0__tar.gz → 1.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/.gitignore +0 -2
  2. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/PKG-INFO +8 -3
  3. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/README.md +7 -2
  4. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/_version.py +2 -2
  5. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/prov.py +8 -3
  6. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/refs.py +35 -1
  7. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/conceptmap.py +6 -1
  8. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/graph/client.py +29 -2
  9. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/graph/dataset.py +15 -1
  10. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/graph/terms.py +16 -1
  11. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/publish.py +5 -2
  12. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/query.py +22 -12
  13. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/pyproject.toml +0 -0
  14. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/__init__.py +0 -0
  15. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/auth/__init__.py +0 -0
  16. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/auth/client_creds.py +0 -0
  17. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/auth/pkce.py +0 -0
  18. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/auth/stepup.py +0 -0
  19. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/auth/store.py +0 -0
  20. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/branch.py +0 -0
  21. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/catalog.py +0 -0
  22. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/__init__.py +0 -0
  23. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/_app.py +0 -0
  24. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/_errors.py +0 -0
  25. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/__init__.py +0 -0
  26. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/conceptmap.py +0 -0
  27. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/data_auth.py +0 -0
  28. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/data_import.py +0 -0
  29. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/data_info.py +0 -0
  30. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/data_publish.py +0 -0
  31. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/ls.py +0 -0
  32. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/show.py +0 -0
  33. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/snapshots.py +0 -0
  34. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/commands/sparql.py +0 -0
  35. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/cli/main.py +0 -0
  36. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/config.py +0 -0
  37. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/discovery.py +0 -0
  38. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/env_commands.py +0 -0
  39. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/env_section.py +0 -0
  40. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/graph/__init__.py +0 -0
  41. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/identifiers.py +0 -0
  42. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/import_/__init__.py +0 -0
  43. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/import_/fetcher.py +0 -0
  44. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/import_/owner.py +0 -0
  45. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/import_/parser.py +0 -0
  46. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/import_/pipeline.py +0 -0
  47. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/import_/storage.py +0 -0
  48. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/metadata/__init__.py +0 -0
  49. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/metadata/builder.py +0 -0
  50. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/metadata/models.py +0 -0
  51. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/metadata/provenance.py +0 -0
  52. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/metadata/provenance_rdf.py +0 -0
  53. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/plugin.py +0 -0
  54. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/push.py +0 -0
  55. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/queries/conceptmap-mappings.rq +0 -0
  56. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/resolve.py +0 -0
  57. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/sssom.py +0 -0
  58. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/url.py +0 -0
  59. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/utils/__init__.py +0 -0
  60. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/utils/checksum.py +0 -0
  61. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/utils/encoding.py +0 -0
  62. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/utils/naming.py +0 -0
  63. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/versioning/__init__.py +0 -0
  64. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_data/versioning/schema_evolution.py +0 -0
  65. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/__init__.py +0 -0
  66. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/assets/__init__.py +0 -0
  67. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/assets/mirrors.py +0 -0
  68. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/assets/transforms.py +0 -0
  69. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/definitions.py +0 -0
  70. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/io_manager.py +0 -0
  71. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/resources/__init__.py +0 -0
  72. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/resources/iceberg.py +0 -0
  73. {sunstone_data_platform-1.5.0 → sunstone_data_platform-1.8.0}/src/sunstone_pipeline/resources/refs.py +0 -0
@@ -11,8 +11,6 @@ src/sunstone_data/_version.py
11
11
  .planning/
12
12
  old-stuff/
13
13
 
14
- # Security prompts
15
- security-prompts/
16
14
  .DS_Store
17
15
  .claude/*.local.*
18
16
  .worktrees
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sunstone-data-platform
3
- Version: 1.5.0
3
+ Version: 1.8.0
4
4
  Summary: Sunstone Data Platform - Data lakehouse with semantic metadata
5
5
  Author-email: Sunstone Institute <stig@sunstone.institute>
6
6
  License-Expression: MIT
@@ -85,11 +85,16 @@ uv sync
85
85
 
86
86
  ### 2. Configure environment
87
87
 
88
+ Create `.env` with a fresh random password for every `CHANGE_ME` value:
89
+
88
90
  ```bash
89
- cp .env.example .env
90
- # Edit .env if you want to change default credentials
91
+ perl -pe 's/CHANGE_ME/`openssl rand -hex 16`/ge' .env.example > .env
91
92
  ```
92
93
 
94
+ The compose stack is for local development only. It publishes its ports on
95
+ `127.0.0.1`, so other machines cannot reach it. Do not expose it to a shared
96
+ network or use it in production.
97
+
93
98
  ### 3. Start the infrastructure
94
99
 
95
100
  ```bash
@@ -57,11 +57,16 @@ uv sync
57
57
 
58
58
  ### 2. Configure environment
59
59
 
60
+ Create `.env` with a fresh random password for every `CHANGE_ME` value:
61
+
60
62
  ```bash
61
- cp .env.example .env
62
- # Edit .env if you want to change default credentials
63
+ perl -pe 's/CHANGE_ME/`openssl rand -hex 16`/ge' .env.example > .env
63
64
  ```
64
65
 
66
+ The compose stack is for local development only. It publishes its ports on
67
+ `127.0.0.1`, so other machines cannot reach it. Do not expose it to a shared
68
+ network or use it in production.
69
+
65
70
  ### 3. Start the infrastructure
66
71
 
67
72
  ```bash
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '1.5.0'
22
- __version_tuple__ = version_tuple = (1, 5, 0)
21
+ __version__ = version = '1.8.0'
22
+ __version_tuple__ = version_tuple = (1, 8, 0)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -18,13 +18,16 @@ from sunstone_data.cli._errors import cli_errors
18
18
  _QUERY = """PREFIX dcat: <{dcat}>
19
19
  PREFIX prov: <{prov}>
20
20
  PREFIX si: <{si}>
21
+ PREFIX si-legacy: <{si_legacy}>
21
22
 
22
- SELECT ?version ?snapshot ?activity ?generatedAt WHERE {{
23
+ # DISTINCT: a version node may link its snapshot under both dcat-si
24
+ # namespaces, and the property-path alternative then matches it twice.
25
+ SELECT DISTINCT ?version ?snapshot ?activity ?generatedAt WHERE {{
23
26
  GRAPH <{iri}> {{
24
27
  <{iri}> dcat:hasVersion ?node .
25
28
  ?node dcat:version ?version .
26
29
  OPTIONAL {{
27
- ?node si:hasSnapshot ?snapshot .
30
+ ?node si:hasSnapshot|si-legacy:hasSnapshot ?snapshot .
28
31
  OPTIONAL {{ ?snapshot prov:wasGeneratedBy ?activity }}
29
32
  OPTIONAL {{ ?snapshot prov:qualifiedGeneration/prov:atTime ?generatedAt }}
30
33
  }}
@@ -54,5 +57,7 @@ def lineage_cmd(
54
57
  # The dataset IRI is minted from the ref's namespace and table name,
55
58
  # both already validated by TableRef.parse, so it is safe to inline.
56
59
  iri = dataset_iri(TableRef.parse(table))
57
- query = _QUERY.format(dcat=terms.DCAT, prov=terms.PROV, si=terms.DCAT_SI, iri=iri)
60
+ query = _QUERY.format(
61
+ dcat=terms.DCAT, prov=terms.PROV, si=terms.DCAT_SI, si_legacy=terms.DCAT_SI_LEGACY, iri=iri
62
+ )
58
63
  execute_query(query, json_output, empty_message="No lineage recorded for this dataset")
@@ -1,4 +1,4 @@
1
- """graph-server refs: ``branches``, ``branch create|delete|merge``, ``tags``,
1
+ """graph-server refs: ``branches``, ``branch create|delete|merge|rebase``, ``tags``,
2
2
  ``tag create|delete`` (spec 180 §8).
3
3
 
4
4
  Branch and tag names go into a URL path, so they are validated here before
@@ -140,6 +140,40 @@ def branch_merge_cmd(
140
140
  raise typer.Exit(2)
141
141
 
142
142
 
143
+ @branch_app.command("rebase")
144
+ def branch_rebase_cmd(
145
+ name: str = typer.Argument(..., help="Name of the branch to rebase onto main's head"),
146
+ json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
147
+ ) -> None:
148
+ """Rebase a branch onto main's head, so it reads main's newer commits.
149
+
150
+ Refused when a graph changed on both main and the branch since the fork.
151
+ Exits 2 then, like merge with conflicts.
152
+ """
153
+ with cli_errors(json_output):
154
+ from sunstone_data.identifiers import validate_ref_name
155
+
156
+ validate_ref_name(name, "branch")
157
+ result = _client().rebase_branch(name)
158
+
159
+ conflicts = result.get("conflicts", [])
160
+ if json_output:
161
+ print(json.dumps(result, indent=2))
162
+ elif conflicts:
163
+ console.print(f"[yellow]Not rebased[/yellow] {name}: {len(conflicts)} graph(s) changed on both sides")
164
+ for e in conflicts:
165
+ console.print(f" [red]conflict[/red] {e.get('table') or e['graph']}")
166
+ elif result.get("rebased"):
167
+ console.print(
168
+ f"[green]Rebased[/green] {name} onto main: fork point "
169
+ f"{result.get('previous_branch_point_txn')} -> {result.get('branch_point_txn')}"
170
+ )
171
+ else:
172
+ console.print(f"[green]Up to date[/green] {name} already forks from main's head")
173
+ if conflicts:
174
+ raise typer.Exit(2)
175
+
176
+
143
177
  @data_app.command("tags")
144
178
  def tags_cmd(
145
179
  json_output: bool = typer.Option(False, "--json", help="Output as JSON"),
@@ -53,7 +53,10 @@ _CONCEPTMAP = re.compile(r"^(https?://[^/]+)/conceptmap/(\d+)(?=[/#]|$)")
53
53
  _BASE_DECL = re.compile(r"^\s*(@base|base)\s*<", re.MULTILINE | re.IGNORECASE)
54
54
  #: The local stand-in for the graph IRI before a push (scope tools, SSSOM `curie_map`).
55
55
  PLACEHOLDER = "https://data.sunstone.institute/conceptmap/0"
56
- CMAP = "https://sunstone.institute/rdf/conceptmap#"
56
+ #: The `cmap:` research-record vocabulary (rdf-registry `rdf/conceptmap/core.ttl`).
57
+ CMAP = "https://sunstone.institute/rdf/conceptmap/core#"
58
+ #: The namespace kg:map-concepts wrote before it matched the registry; rewritten to `CMAP` on push.
59
+ LEGACY_CMAP = "https://sunstone.institute/rdf/conceptmap#"
57
60
 
58
61
 
59
62
  class ConceptMapError(ValueError):
@@ -141,6 +144,8 @@ def build(files: list[Path], graph_iri: str, mappings: Path | None = None) -> Gr
141
144
  return graph_iri + ("" if kind == "concept" else "/ontology") + rest
142
145
  if iri == PLACEHOLDER or iri.startswith(PLACEHOLDER + "/"):
143
146
  return graph_iri + iri[len(PLACEHOLDER) :]
147
+ if iri.startswith(LEGACY_CMAP):
148
+ return CMAP + iri[len(LEGACY_CMAP) :]
144
149
  return iri
145
150
 
146
151
  def rewrite(term):
@@ -24,7 +24,7 @@ from sunstone_data.auth.stepup import StepUpChallenge, StepUpRequired, parse_cha
24
24
  from sunstone_data.config import current_environment_name, get_settings
25
25
  from sunstone_data.identifiers import validate_ref_name
26
26
 
27
- #: Merge reads and writes many graphs under main's lock, so it gets a longer timeout.
27
+ #: Merge and rebase read many graphs under main's lock, so they get a longer timeout.
28
28
  MERGE_TIMEOUT_SECONDS = 300.0
29
29
 
30
30
  #: graph-server rejects request bodies larger than this.
@@ -92,6 +92,10 @@ class MergeRejected(RuntimeError):
92
92
  """graph-server refused a merge (400 or 409). The message is the server's reason."""
93
93
 
94
94
 
95
+ class RebaseRejected(RuntimeError):
96
+ """graph-server refused a rebase (400 or 409). The message is the server's reason."""
97
+
98
+
95
99
  class PushRejected(RuntimeError):
96
100
  """graph-server refused a push manifest or commit (400 or 409).
97
101
 
@@ -147,6 +151,7 @@ def _server_message(resp: httpx.Response) -> str:
147
151
  DEFAULT_PROTECTED_PATTERNS = ("main", "v[0-9]*")
148
152
  _BRANCH_WRITE_PATH = re.compile(r"^/branches/([^/]+)(/graphs)?$")
149
153
  _MERGE_PATH = re.compile(r"^/branches/[^/]+/merge$")
154
+ _REBASE_PATH = re.compile(r"^/branches/([^/]+)/rebase$")
150
155
 
151
156
 
152
157
  def _is_protected(branch: str) -> bool:
@@ -162,7 +167,7 @@ def _required_role(method: str, path: str) -> str:
162
167
  """Mirror graph-server's own role classifier (graph-core ``auth.rs``)."""
163
168
  if method not in ("GET", "HEAD"):
164
169
  bare = path.split("?", 1)[0]
165
- m = _BRANCH_WRITE_PATH.match(bare)
170
+ m = _BRANCH_WRITE_PATH.match(bare) or _REBASE_PATH.match(bare)
166
171
  if _MERGE_PATH.match(bare) or (m and _is_protected(m.group(1))):
167
172
  return "protected-write"
168
173
  if path == "/sparql" and method in ("GET", "HEAD", "POST"):
@@ -347,6 +352,28 @@ class GraphClient:
347
352
  raise MergeRejected(e.response.text) from e
348
353
  raise
349
354
 
355
+ def rebase_branch(self, name: str) -> dict:
356
+ """Move a branch's fork point to ``main``'s head (DP-REQ-58).
357
+
358
+ Args:
359
+ name: Branch to rebase. Its parent must be ``main``.
360
+
361
+ Returns:
362
+ ``{"rebased": bool, "previous_branch_point_txn": int,
363
+ "branch_point_txn": int, "conflicts": [...]}``. Any conflict
364
+ refuses the whole rebase.
365
+
366
+ Raises:
367
+ RebaseRejected: The request was refused, e.g. rebasing ``main`` or
368
+ a branch whose parent is not ``main``.
369
+ """
370
+ try:
371
+ return self._request("POST", f"/branches/{name}/rebase", timeout=MERGE_TIMEOUT_SECONDS).json()
372
+ except httpx.HTTPStatusError as e:
373
+ if e.response.status_code in (400, 409):
374
+ raise RebaseRejected(e.response.text) from e
375
+ raise
376
+
350
377
  # --- Push API (DP-SPEC-27 section 10.1) ---
351
378
 
352
379
  def create_push(self, manifest: dict) -> dict:
@@ -379,6 +379,18 @@ def snapshot_already_has_generation(graph: Graph, dataset_iri: str, snapshot_id:
379
379
  return any(t.subject == snapshot and t.predicate == _PROV_WAS_GENERATED_BY for t in graph)
380
380
 
381
381
 
382
+ def with_legacy_terms(graph: Graph) -> Graph:
383
+ """`graph` plus a copy of each triple with dcat-si IRIs in the legacy namespace.
384
+
385
+ For matching triples written before the dcat-si rename, never for writing.
386
+ """
387
+
388
+ def legacy(term: Term) -> Term:
389
+ return IRI(terms.to_legacy(term.value)) if isinstance(term, IRI) else term
390
+
391
+ return graph | build_graph(Triple(t.subject, legacy(t.predicate), legacy(t.obj)) for t in graph)
392
+
393
+
382
394
  def graph_to_description(graph: Graph, dataset_iri: str) -> DatasetDescription:
383
395
  """Read a dataset graph back into a `DatasetDescription`.
384
396
 
@@ -423,7 +435,9 @@ def _read_version(graph: Graph, dataset_iri: str, node: IRI) -> DatasetVersion:
423
435
 
424
436
 
425
437
  def _matches(graph: Graph, subject: IRI, predicate: IRI) -> Iterable[Term]:
426
- return (t.obj for t in graph if t.subject == subject and t.predicate == predicate)
438
+ """Objects of `subject` `predicate`. A dcat-si predicate matches in either namespace."""
439
+ predicates = terms.dcat_si_variants(predicate.value)
440
+ return (t.obj for t in graph if t.subject == subject and t.predicate.value in predicates)
427
441
 
428
442
 
429
443
  def _literal(graph: Graph, subject: IRI, predicate: IRI) -> str | None:
@@ -5,6 +5,9 @@ These constants must match `PREFIXES` in
5
5
  and write the same graph; a mismatched namespace IRI would silently break
6
6
  CURIE reflection between RDF predicates and Iceberg property keys
7
7
  (`sunstone.{prefix}.{local}`, spec §10.1) instead of failing loudly.
8
+
9
+ Writers use `DCAT_SI` only. Readers also match `DCAT_SI_LEGACY`: triples
10
+ written before the dcat-si ontology moved from `/rdf/data` stay in the store.
8
11
  """
9
12
 
10
13
  DCAT = "http://www.w3.org/ns/dcat#"
@@ -13,7 +16,8 @@ FOAF = "http://xmlns.com/foaf/0.1/"
13
16
  PROV = "http://www.w3.org/ns/prov#"
14
17
  VCARD = "http://www.w3.org/2006/vcard/ns#"
15
18
  XSD = "http://www.w3.org/2001/XMLSchema#"
16
- DCAT_SI = "https://sunstone.institute/rdf/data#"
19
+ DCAT_SI = "https://sunstone.institute/rdf/dcat#"
20
+ DCAT_SI_LEGACY = "https://sunstone.institute/rdf/data#"
17
21
  ORG = "http://www.w3.org/ns/org#"
18
22
  SKOS = "http://www.w3.org/2004/02/skos/core#"
19
23
  RDFS = "http://www.w3.org/2000/01/rdf-schema#"
@@ -32,3 +36,14 @@ PREFIXES: dict[str, str] = {
32
36
  "rdfs": RDFS,
33
37
  "csvw": CSVW,
34
38
  }
39
+
40
+
41
+ def to_legacy(iri: str) -> str:
42
+ """`iri` in the legacy dcat-si namespace if it is a dcat-si IRI, else unchanged."""
43
+ return DCAT_SI_LEGACY + iri.removeprefix(DCAT_SI) if iri.startswith(DCAT_SI) else iri
44
+
45
+
46
+ def dcat_si_variants(iri: str) -> tuple[str, ...]:
47
+ """Every IRI the store may hold for `iri`: both dcat-si namespace forms, or `iri` alone."""
48
+ legacy = to_legacy(iri)
49
+ return (iri,) if legacy == iri else (iri, legacy)
@@ -13,7 +13,9 @@ Two modes, and the difference matters:
13
13
  Which triples the package owns is not a hand-maintained predicate list.
14
14
  `description_to_graph` and `graph_to_description` are inverses, so reading the
15
15
  visible graph back into a description and re-serializing it reproduces exactly
16
- the triples this mapping wrote before — no more. A predicate list would be
16
+ the triples this mapping wrote before — no more. `with_legacy_terms` adds the
17
+ same triples in the pre-rename dcat-si namespace, so triples written before
18
+ the rename are retracted too. A predicate list would be
17
19
  wrong anyway: `rdf:type` appears on our version nodes *and* on the catalog's
18
20
  own descriptor.
19
21
 
@@ -33,6 +35,7 @@ from sunstone_data.graph.dataset import (
33
35
  graph_to_description,
34
36
  parse_ntriples,
35
37
  serialize,
38
+ with_legacy_terms,
36
39
  )
37
40
 
38
41
  _EMPTY: Graph = build_graph([])
@@ -78,7 +81,7 @@ def _attempt(client: GraphClient, description: DatasetDescription, branch: str,
78
81
  if not replace:
79
82
  return client.post_graph(branch, iri, serialize(ours), if_match=if_match, content_type=N_TRIPLES)
80
83
 
81
- previously_ours = description_to_graph(graph_to_description(visible, iri)) if visible else _EMPTY
84
+ previously_ours = with_legacy_terms(description_to_graph(graph_to_description(visible, iri))) if visible else _EMPTY
82
85
  payload = (visible - previously_ours) | ours
83
86
  return client.put_graph(branch, iri, serialize(payload), if_match=if_match, content_type=N_TRIPLES)
84
87
 
@@ -24,6 +24,7 @@ Example (application):
24
24
 
25
25
  from __future__ import annotations
26
26
 
27
+ import operator
27
28
  import os
28
29
  import threading
29
30
  from dataclasses import dataclass, replace
@@ -43,6 +44,8 @@ from sunstone_data.identifiers import (
43
44
  # The only branch DuckDB can read; see QuerySession._ensure_branch_attached.
44
45
  _DUCKDB_BRANCH = "main"
45
46
 
47
+ _SAMPLE_METHODS = frozenset({"reservoir", "bernoulli", "system"})
48
+
46
49
 
47
50
  def _resolve_token(settings: Settings) -> str | None:
48
51
  """Return a bearer token for iceberg-catalog, or None if none is configured.
@@ -189,6 +192,7 @@ class TablePreview:
189
192
 
190
193
  def tail(self, n: int = 5) -> duckdb.DuckDBPyRelation:
191
194
  """Get last n rows (lazy). Note: requires full scan for offset calculation."""
195
+ n = operator.index(n)
192
196
  conn = self._session._ensure_connection()
193
197
  view_name = f"_tail_temp_{id(self._relation)}"
194
198
  conn.register(view_name, self._relation)
@@ -216,20 +220,26 @@ class TablePreview:
216
220
  DuckDBPyRelation for lazy evaluation.
217
221
 
218
222
  Raises:
219
- ValueError: If neither n nor frac specified, or both specified.
223
+ ValueError: If neither or both of n and frac are given, frac is
224
+ outside 0.0-1.0, or method is unknown.
225
+ TypeError: If n is not an integer.
220
226
  """
221
- if (n is None) == (frac is None):
227
+ if method not in _SAMPLE_METHODS:
228
+ raise ValueError(f"Unknown sampling method {method!r}; use one of {sorted(_SAMPLE_METHODS)}")
229
+ if n is not None and frac is None:
230
+ clause = f"{operator.index(n)} ROWS"
231
+ elif frac is not None and n is None:
232
+ frac = float(frac)
233
+ if not 0.0 <= frac <= 1.0:
234
+ raise ValueError(f"frac must be between 0.0 and 1.0, got {frac}")
235
+ clause = f"{frac * 100}%"
236
+ else:
222
237
  raise ValueError("Specify exactly one of n or frac")
223
238
 
224
239
  conn = self._session._ensure_connection()
225
240
  view_name = f"_sample_temp_{id(self._relation)}"
226
241
  conn.register(view_name, self._relation)
227
-
228
- if n is not None:
229
- return conn.sql(f"SELECT * FROM {view_name} USING SAMPLE {n} ROWS ({method})")
230
- else:
231
- pct = frac * 100
232
- return conn.sql(f"SELECT * FROM {view_name} USING SAMPLE {pct}% ({method})")
242
+ return conn.sql(f"SELECT * FROM {view_name} USING SAMPLE {clause} ({method})")
233
243
 
234
244
  def describe(self) -> duckdb.DuckDBPyRelation:
235
245
  """Get summary statistics for all columns (lazy).
@@ -319,12 +329,12 @@ class QuerySession:
319
329
  endpoint = settings.s3_endpoint.replace("http://", "").replace("https://", "")
320
330
  use_ssl = settings.s3_endpoint.startswith("https://")
321
331
  conn.execute("INSTALL httpfs; LOAD httpfs;")
322
- conn.execute(f"SET s3_endpoint = '{endpoint}'")
323
- conn.execute(f"SET s3_access_key_id = '{settings.s3_access_key}'")
324
- conn.execute(f"SET s3_secret_access_key = '{settings.s3_secret_key}'")
332
+ conn.execute("SET s3_endpoint = ?", [endpoint])
333
+ conn.execute("SET s3_access_key_id = ?", [settings.s3_access_key])
334
+ conn.execute("SET s3_secret_access_key = ?", [settings.s3_secret_key])
325
335
  conn.execute("SET s3_region = 'us-east-1'")
326
336
  conn.execute("SET s3_url_style = 'path'")
327
- conn.execute(f"SET s3_use_ssl = {str(use_ssl).lower()}")
337
+ conn.execute("SET s3_use_ssl = ?", [use_ssl])
328
338
 
329
339
  @staticmethod
330
340
  def _register_fake_gcs_filesystem(conn: duckdb.DuckDBPyConnection) -> None: