Skip to content

Commit a1f4e13

Browse files
committed
Catalog source table and ReadStat storage types
1 parent 102196e commit a1f4e13

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/openstatspec/spss/sav.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ def _variables(meta: Any, names: list[str]) -> list[dict[str, Any]]:
2323
value_labels = dict(getattr(meta, "variable_value_labels", {}) or {})
2424
missing_ranges = dict(getattr(meta, "missing_ranges", {}) or {})
2525
widths = dict(getattr(meta, "variable_storage_width", {}) or {})
26+
readstat_types = dict(getattr(meta, "readstat_variable_types", {}) or {})
2627
result = []
2728
for ordinal, source_name in enumerate(names, start=1):
2829
kind = "string" if str(formats.get(source_name, "")).upper().startswith("A") else "numeric"
2930
result.append({
3031
"ordinal": ordinal, "source_name": source_name,
3132
"physical_name": physical_name(source_name, used), "storage_kind": kind,
33+
"readstat_storage_type": readstat_types.get(source_name),
3234
"string_width": widths.get(source_name) if kind == "string" else None,
3335
"label": labels.get(source_name, "") or "", "format": formats.get(source_name),
3436
"measure": measures.get(source_name), "alignment": alignments.get(source_name),
@@ -79,6 +81,7 @@ def import_sav_dataset(*, source: str | Path, database_url: str, dataset_id: str
7981
source_format=source_path.suffix[1:].upper(), rows=_rows(frame, variables),
8082
variables=variables, file_label=getattr(meta, "file_label", "") or "",
8183
source_encoding=getattr(meta, "file_encoding", None),
84+
source_table_name=getattr(meta, "table_name", None),
8285
source_sha256=_sha256(source_path),
8386
source_created_at=_iso_datetime(getattr(meta, "creation_time", None)),
8487
source_modified_at=_iso_datetime(getattr(meta, "modification_time", None)),

‎src/openstatspec/sql/wide.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def catalog(metadata: MetaData) -> tuple[Table, Table]:
1818
Column("data_table", String(255), nullable=False, unique=True),
1919
Column("source_format", String(16), nullable=False),
2020
Column("source_name", Text, nullable=False),
21+
Column("source_table_name", Text),
2122
Column("source_sha256", String(64), nullable=False),
2223
Column("source_created_at", String(40)),
2324
Column("source_modified_at", String(40)),
@@ -35,6 +36,7 @@ def catalog(metadata: MetaData) -> tuple[Table, Table]:
3536
Column("source_name", String(255), nullable=False),
3637
Column("physical_name", String(255), nullable=False),
3738
Column("storage_kind", String(16), nullable=False),
39+
Column("readstat_storage_type", String(32)),
3840
Column("string_width", Integer),
3941
Column("label", Text, nullable=False, default=""),
4042
Column("format", String(64)),
@@ -96,6 +98,7 @@ def create_wide_dataset(
9698
*, database_url: str, dataset_id: str, source_name: str, source_format: str,
9799
rows: Iterable[Mapping[str, Any]], variables: list[dict[str, Any]], file_label: str = "",
98100
source_encoding: str | None = None, documents: str = "[]",
101+
source_table_name: str | None = None,
99102
source_sha256: str = "",
100103
source_created_at: str | None = None, source_modified_at: str | None = None,
101104
imported_at: str = "",
@@ -124,6 +127,7 @@ def create_wide_dataset(
124127
connection.execute(insert(datasets).values(
125128
dataset_id=dataset_id, data_table=data_table.name, source_format=source_format,
126129
source_name=source_name, source_encoding=source_encoding, case_count=len(materialized),
130+
source_table_name=source_table_name,
127131
source_sha256=source_sha256,
128132
source_created_at=source_created_at, source_modified_at=source_modified_at,
129133
imported_at=imported_at,

0 commit comments

Comments
 (0)