moose-lib 0.4.276__py3-none-any.whl → 0.4.278__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.
Potentially problematic release.
This version of moose-lib might be problematic. Click here for more details.
- moose_lib/dmv2/olap_table.py +24 -7
- {moose_lib-0.4.276.dist-info → moose_lib-0.4.278.dist-info}/METADATA +1 -1
- {moose_lib-0.4.276.dist-info → moose_lib-0.4.278.dist-info}/RECORD +5 -5
- {moose_lib-0.4.276.dist-info → moose_lib-0.4.278.dist-info}/WHEEL +0 -0
- {moose_lib-0.4.276.dist-info → moose_lib-0.4.278.dist-info}/top_level.txt +0 -0
moose_lib/dmv2/olap_table.py
CHANGED
|
@@ -426,6 +426,17 @@ class OlapTable(TypedMooseResource, Generic[T]):
|
|
|
426
426
|
def _to_json_each_row(self, records: list[dict]) -> bytes:
|
|
427
427
|
return "\n".join(json.dumps(r, default=str) for r in records).encode("utf-8")
|
|
428
428
|
|
|
429
|
+
def _with_wait_end_settings(self, settings: dict) -> dict:
|
|
430
|
+
"""Add wait_end_of_query setting to ensure at least once delivery for INSERT operations.
|
|
431
|
+
|
|
432
|
+
Args:
|
|
433
|
+
settings: Base settings dictionary
|
|
434
|
+
|
|
435
|
+
Returns:
|
|
436
|
+
Settings dictionary with wait_end_of_query added
|
|
437
|
+
"""
|
|
438
|
+
return {**settings, "wait_end_of_query": 1}
|
|
439
|
+
|
|
429
440
|
def _prepare_insert_options(
|
|
430
441
|
self,
|
|
431
442
|
table_name: str,
|
|
@@ -437,13 +448,14 @@ class OlapTable(TypedMooseResource, Generic[T]):
|
|
|
437
448
|
) -> tuple[str, bytes, dict]:
|
|
438
449
|
"""Prepare insert options for JSONEachRow raw SQL insert, returning settings dict."""
|
|
439
450
|
# Base settings for all inserts
|
|
440
|
-
|
|
451
|
+
base_settings = {
|
|
441
452
|
"date_time_input_format": "best_effort",
|
|
442
453
|
"max_insert_block_size": 100000 if is_stream else min(len(validated_data), 100000),
|
|
443
454
|
"max_block_size": 65536,
|
|
444
455
|
"async_insert": 1 if len(validated_data) > 1000 else 0,
|
|
445
456
|
"wait_for_async_insert": 1,
|
|
446
457
|
}
|
|
458
|
+
settings = self._with_wait_end_settings(base_settings)
|
|
447
459
|
if (strategy == "discard" and options and
|
|
448
460
|
(options.allow_errors is not None or options.allow_errors_ratio is not None)):
|
|
449
461
|
if options.allow_errors is not None:
|
|
@@ -541,12 +553,13 @@ class OlapTable(TypedMooseResource, Generic[T]):
|
|
|
541
553
|
batch = records_dict[i:i + RETRY_BATCH_SIZE]
|
|
542
554
|
try:
|
|
543
555
|
sql = f"INSERT INTO {table_name} FORMAT JSONEachRow"
|
|
544
|
-
|
|
556
|
+
base_settings = {
|
|
545
557
|
"date_time_input_format": "best_effort",
|
|
546
558
|
"max_insert_block_size": RETRY_BATCH_SIZE,
|
|
547
559
|
"max_block_size": RETRY_BATCH_SIZE,
|
|
548
560
|
"async_insert": 0
|
|
549
561
|
}
|
|
562
|
+
settings = self._with_wait_end_settings(base_settings)
|
|
550
563
|
json_lines = self._to_json_each_row(batch)
|
|
551
564
|
client.command(sql, data=json_lines, settings=settings)
|
|
552
565
|
successful.extend(records[i:i + RETRY_BATCH_SIZE])
|
|
@@ -554,12 +567,12 @@ class OlapTable(TypedMooseResource, Generic[T]):
|
|
|
554
567
|
for j, record_dict in enumerate(batch):
|
|
555
568
|
try:
|
|
556
569
|
sql = f"INSERT INTO {table_name} FORMAT JSONEachRow"
|
|
557
|
-
|
|
570
|
+
individual_settings = self._with_wait_end_settings({
|
|
558
571
|
"date_time_input_format": "best_effort",
|
|
559
572
|
"async_insert": 0
|
|
560
|
-
}
|
|
573
|
+
})
|
|
561
574
|
json_line = self._to_json_each_row([record_dict])
|
|
562
|
-
client.command(sql, data=json_line, settings=
|
|
575
|
+
client.command(sql, data=json_line, settings=individual_settings)
|
|
563
576
|
successful.append(records[i + j])
|
|
564
577
|
except ClickHouseError as error:
|
|
565
578
|
failed.append(FailedRecord(
|
|
@@ -675,14 +688,18 @@ class OlapTable(TypedMooseResource, Generic[T]):
|
|
|
675
688
|
if len(batch) >= 1000: # Batch size
|
|
676
689
|
json_lines = self._to_json_each_row(batch)
|
|
677
690
|
sql = f"INSERT INTO {table_name} FORMAT JSONEachRow"
|
|
678
|
-
|
|
691
|
+
# Add wait_end_of_query to batch settings using helper function
|
|
692
|
+
batch_settings = self._with_wait_end_settings(settings)
|
|
693
|
+
client.command(sql, data=json_lines, settings=batch_settings)
|
|
679
694
|
total_inserted += len(batch)
|
|
680
695
|
batch = []
|
|
681
696
|
|
|
682
697
|
if batch: # Insert any remaining records
|
|
683
698
|
json_lines = self._to_json_each_row(batch)
|
|
684
699
|
sql = f"INSERT INTO {table_name} FORMAT JSONEachRow"
|
|
685
|
-
|
|
700
|
+
# Add wait_end_of_query to final batch settings using helper function
|
|
701
|
+
final_settings = self._with_wait_end_settings(settings)
|
|
702
|
+
client.command(sql, data=json_lines, settings=final_settings)
|
|
686
703
|
total_inserted += len(batch)
|
|
687
704
|
|
|
688
705
|
return InsertResult(
|
|
@@ -18,7 +18,7 @@ moose_lib/dmv2/consumption.py,sha256=vt1APul1O21yPHaB0MRjF_9ohz5MJs5QIpDCnzFwyJA
|
|
|
18
18
|
moose_lib/dmv2/ingest_api.py,sha256=Snek9NGwaJl_BuImSWGtQq91m9D3AJ4qBoGiKZ-9yTQ,2323
|
|
19
19
|
moose_lib/dmv2/ingest_pipeline.py,sha256=Y1gsvHZjlW07gMapLnBRJEsoAPv7ThvLABoLmVV7BHE,6714
|
|
20
20
|
moose_lib/dmv2/materialized_view.py,sha256=kcx-sJFTM-cH3Uc1GoldgFGodjoz0AegAQEMmohdS38,3826
|
|
21
|
-
moose_lib/dmv2/olap_table.py,sha256=
|
|
21
|
+
moose_lib/dmv2/olap_table.py,sha256=mQYPThAhIfZ4aTadb_tdRvQyXcjcwlY26yF1iKzuih0,31479
|
|
22
22
|
moose_lib/dmv2/registry.py,sha256=AaGS6Xy0vKz-wHLPgRVxfKfSwW5KksMePjZ8N7-2OKU,2054
|
|
23
23
|
moose_lib/dmv2/sql_resource.py,sha256=kUZoGqxhZMHMthtBZGYJBxTFjXkspXiWLXhJRYXgGUM,1864
|
|
24
24
|
moose_lib/dmv2/stream.py,sha256=H5nzqVHIXulFNMNaGZUQnhGjNx7fIg0X95kxAO_qlls,10600
|
|
@@ -31,7 +31,7 @@ tests/__init__.py,sha256=0Gh4yzPkkC3TzBGKhenpMIxJcRhyrrCfxLSfpTZnPMQ,53
|
|
|
31
31
|
tests/conftest.py,sha256=ZVJNbnr4DwbcqkTmePW6U01zAzE6QD0kNAEZjPG1f4s,169
|
|
32
32
|
tests/test_moose.py,sha256=mBsx_OYWmL8ppDzL_7Bd7xR6qf_i3-pCIO3wm2iQNaA,2136
|
|
33
33
|
tests/test_redis_client.py,sha256=d9_MLYsJ4ecVil_jPB2gW3Q5aWnavxmmjZg2uYI3LVo,3256
|
|
34
|
-
moose_lib-0.4.
|
|
35
|
-
moose_lib-0.4.
|
|
36
|
-
moose_lib-0.4.
|
|
37
|
-
moose_lib-0.4.
|
|
34
|
+
moose_lib-0.4.278.dist-info/METADATA,sha256=99ouJnsUC33mfZl_aJfc2aimdrP2SsE2leoSaGW0b9I,729
|
|
35
|
+
moose_lib-0.4.278.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
36
|
+
moose_lib-0.4.278.dist-info/top_level.txt,sha256=XEns2-4aCmGp2XjJAeEH9TAUcGONLnSLy6ycT9FSJh8,16
|
|
37
|
+
moose_lib-0.4.278.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|