anysite-cli 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl
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.
- anysite/dataset/db_loader.py +58 -7
- {anysite_cli-0.1.5.dist-info → anysite_cli-0.1.7.dist-info}/METADATA +1 -1
- {anysite_cli-0.1.5.dist-info → anysite_cli-0.1.7.dist-info}/RECORD +6 -6
- {anysite_cli-0.1.5.dist-info → anysite_cli-0.1.7.dist-info}/WHEEL +0 -0
- {anysite_cli-0.1.5.dist-info → anysite_cli-0.1.7.dist-info}/entry_points.txt +0 -0
- {anysite_cli-0.1.5.dist-info → anysite_cli-0.1.7.dist-info}/licenses/LICENSE +0 -0
anysite/dataset/db_loader.py
CHANGED
|
@@ -315,8 +315,14 @@ class DatasetDbLoader:
|
|
|
315
315
|
return _extract_dot_value(record, diff_key)
|
|
316
316
|
return record.get(diff_key)
|
|
317
317
|
|
|
318
|
+
# Build field mapping for db_load.fields filtering
|
|
319
|
+
field_mapping = self._get_db_field_mapping(source)
|
|
320
|
+
|
|
318
321
|
# Determine the DB column name for the key
|
|
319
|
-
|
|
322
|
+
if field_mapping and diff_key in field_mapping:
|
|
323
|
+
db_key_col = field_mapping[diff_key]
|
|
324
|
+
else:
|
|
325
|
+
db_key_col = diff_key.replace(".", "_")
|
|
320
326
|
|
|
321
327
|
# INSERT added records
|
|
322
328
|
if result.added:
|
|
@@ -326,13 +332,14 @@ class DatasetDbLoader:
|
|
|
326
332
|
total += 1
|
|
327
333
|
|
|
328
334
|
# DELETE removed records (skipped in append mode)
|
|
335
|
+
ph = self._placeholder()
|
|
329
336
|
if result.removed and sync_mode == "full":
|
|
330
337
|
safe_col = sanitize_identifier(db_key_col)
|
|
331
338
|
for record in result.removed:
|
|
332
339
|
key_val = _get_key_val(record)
|
|
333
340
|
if key_val is not None:
|
|
334
341
|
self.adapter.execute(
|
|
335
|
-
f"DELETE FROM {table_name} WHERE {safe_col} =
|
|
342
|
+
f"DELETE FROM {table_name} WHERE {safe_col} = {ph}",
|
|
336
343
|
(str(key_val),),
|
|
337
344
|
)
|
|
338
345
|
total += 1
|
|
@@ -348,20 +355,34 @@ class DatasetDbLoader:
|
|
|
348
355
|
if not changed_fields:
|
|
349
356
|
continue
|
|
350
357
|
|
|
351
|
-
# Build SET clause
|
|
358
|
+
# Build SET clause — only include fields that exist in the DB
|
|
352
359
|
set_parts = []
|
|
353
360
|
params: list[Any] = []
|
|
354
361
|
for field_name in changed_fields:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
362
|
+
if field_mapping is not None:
|
|
363
|
+
if field_name not in field_mapping:
|
|
364
|
+
continue
|
|
365
|
+
db_col = field_mapping[field_name]
|
|
366
|
+
else:
|
|
367
|
+
db_col = field_name
|
|
368
|
+
|
|
369
|
+
if "." in field_name:
|
|
370
|
+
new_val = _extract_dot_value(record, field_name)
|
|
371
|
+
else:
|
|
372
|
+
new_val = record.get(field_name)
|
|
373
|
+
|
|
374
|
+
safe_field = sanitize_identifier(db_col)
|
|
375
|
+
set_parts.append(f"{safe_field} = {ph}")
|
|
358
376
|
params.append(new_val)
|
|
359
377
|
|
|
378
|
+
if not set_parts:
|
|
379
|
+
continue
|
|
380
|
+
|
|
360
381
|
params.append(str(key_val))
|
|
361
382
|
sql = (
|
|
362
383
|
f"UPDATE {table_name} "
|
|
363
384
|
f"SET {', '.join(set_parts)} "
|
|
364
|
-
f"WHERE {safe_col} =
|
|
385
|
+
f"WHERE {safe_col} = {ph}"
|
|
365
386
|
)
|
|
366
387
|
self.adapter.execute(sql, tuple(params))
|
|
367
388
|
total += 1
|
|
@@ -375,6 +396,36 @@ class DatasetDbLoader:
|
|
|
375
396
|
return other.dependency.field
|
|
376
397
|
return None
|
|
377
398
|
|
|
399
|
+
def _get_db_field_mapping(self, source: DatasetSource) -> dict[str, str] | None:
|
|
400
|
+
"""Build mapping of parquet_field -> db_column from db_load.fields.
|
|
401
|
+
|
|
402
|
+
Returns None if no explicit fields configured (all fields allowed).
|
|
403
|
+
"""
|
|
404
|
+
db_load = source.db_load
|
|
405
|
+
if not db_load or not db_load.fields:
|
|
406
|
+
return None
|
|
407
|
+
|
|
408
|
+
mapping: dict[str, str] = {}
|
|
409
|
+
for field_spec in db_load.fields:
|
|
410
|
+
alias = None
|
|
411
|
+
upper = field_spec.upper()
|
|
412
|
+
as_idx = upper.find(" AS ")
|
|
413
|
+
if as_idx != -1:
|
|
414
|
+
alias = field_spec[as_idx + 4:].strip()
|
|
415
|
+
source_field = field_spec[:as_idx].strip()
|
|
416
|
+
else:
|
|
417
|
+
source_field = field_spec
|
|
418
|
+
|
|
419
|
+
col_name = alias or source_field.replace(".", "_")
|
|
420
|
+
mapping[source_field] = col_name
|
|
421
|
+
return mapping
|
|
422
|
+
|
|
423
|
+
def _placeholder(self) -> str:
|
|
424
|
+
"""Get the parameter placeholder for the dialect."""
|
|
425
|
+
if self._dialect == "postgres":
|
|
426
|
+
return "%s"
|
|
427
|
+
return "?"
|
|
428
|
+
|
|
378
429
|
def _auto_id_type(self) -> str:
|
|
379
430
|
"""Get the auto-increment ID column type for the dialect."""
|
|
380
431
|
if self._dialect == "postgres":
|
|
@@ -21,7 +21,7 @@ anysite/dataset/__init__.py,sha256=J0sKQkGwVOPtvp6pka7LcdeUEADvjWRs71yRuROzJxI,8
|
|
|
21
21
|
anysite/dataset/analyzer.py,sha256=8dsPW32SbSaUTy1F0NIed1U45wjiMgQeJ2iWX7hBxRQ,9245
|
|
22
22
|
anysite/dataset/cli.py,sha256=rEWK1ka-YQ_Vbbj2nMaMYTD9g3wa3ethUWSoaWRSGTY,23066
|
|
23
23
|
anysite/dataset/collector.py,sha256=ZdR3CmQQew_iuJpNtJ4knSrjt0hvkEL4WIaS0IKEkwQ,23927
|
|
24
|
-
anysite/dataset/db_loader.py,sha256=
|
|
24
|
+
anysite/dataset/db_loader.py,sha256=ebx-SJa-w4EjUsuoNqU2wtAWlbXC93kCc9shs3ZHm70,15597
|
|
25
25
|
anysite/dataset/differ.py,sha256=jB_VWTb7UuEBWG9nv1ry5xeo9hmWdhA_cTm6Ed43_Uw,17746
|
|
26
26
|
anysite/dataset/errors.py,sha256=r8cZXoIzSeTGCWpeYjntnN0AduCu74YZyWs3sFu17J4,914
|
|
27
27
|
anysite/dataset/exporters.py,sha256=mA2FYbYJbHfrwkXbHDu4g5qPG_JJKnkVciXFKPkF1Vw,3708
|
|
@@ -58,8 +58,8 @@ anysite/streaming/writer.py,sha256=HfMsC4umUdJuNIAPK57YAxEGyTwUmy-zNrqFkwY6aew,4
|
|
|
58
58
|
anysite/utils/__init__.py,sha256=7SnbxpxKENK-2ecUL5NfnZ9okGI7COKYw4WF46172HM,23
|
|
59
59
|
anysite/utils/fields.py,sha256=bSrHadzNmabL4qubqhXXZoWb_P8KA-3S7_FLVT8nGBc,7410
|
|
60
60
|
anysite/utils/retry.py,sha256=89TbXvavi5t22P2mTYCLAS6SSZoW65gQ0nnYNbYAF0M,2684
|
|
61
|
-
anysite_cli-0.1.
|
|
62
|
-
anysite_cli-0.1.
|
|
63
|
-
anysite_cli-0.1.
|
|
64
|
-
anysite_cli-0.1.
|
|
65
|
-
anysite_cli-0.1.
|
|
61
|
+
anysite_cli-0.1.7.dist-info/METADATA,sha256=RLzLHvkzQ52E6Ovse5FrXEYjJ2P_6X_sGrs_F5ho2Uk,12437
|
|
62
|
+
anysite_cli-0.1.7.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
63
|
+
anysite_cli-0.1.7.dist-info/entry_points.txt,sha256=FDPxNasy0fRRcOgJdZRVP7Qw01C3TwRa1OwPJiskNyg,45
|
|
64
|
+
anysite_cli-0.1.7.dist-info/licenses/LICENSE,sha256=gVAxkI23CFm4x4HV_fkQYw_bGq93mQmVZEwxNs-YTa4,1069
|
|
65
|
+
anysite_cli-0.1.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|