mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
Follow-up to #105171, which added `ruff` with a deliberately narrow, bug-class-only rule set and left the unused-name and star-import rules off pending a dedicated cleanup pass. This enables that second batch in `pyproject.toml` and fixes every violation across the tree (the bulk in integration tests): - `F401` unused-import and `F841` unused-variable: removed, preserving any side-effecting right-hand side (e.g. `result = node.query(...)` becomes `node.query(...)`). Two `try: import ...` feature probes are kept with `# noqa: F401`. - `F541` f-string-missing-placeholders: dropped the redundant `f` prefix. - `F403`/`F405` star imports: every `from module import *` is expanded into explicit imports of the names actually used, taken from each name's real origin, so stdlib/third-party names import from their real source rather than through a test "convenience bundle". The now-empty `tests/integration/helpers/kafka/common_direct.py` bundle is removed and its three remaining consumers import `_VarintBytes`/`KafkaAdminClient` directly. Eliminating the star imports surfaced a real bug the wildcard had masked from `F821`: `generate_presets.py` in `test_prometheus_protocols` called an undefined `execute_instant_query_with_http_api`; fixed to the existing `execute_query_via_http_api`. No `black`/`isort` reformatting was applied (neither is enforced in the style check), so the diff is limited to the lint fixes themselves. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
120 lines
3.6 KiB
Python
120 lines
3.6 KiB
Python
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node1 = cluster.add_instance("node1", with_zookeeper=True)
|
|
node2 = cluster.add_instance("node2", with_zookeeper=True)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def start_cluster():
|
|
try:
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
finally:
|
|
cluster.shutdown()
|
|
|
|
|
|
def get_compression_codec_byte(node, table_name, part_name, filename):
|
|
data_path = node.query(
|
|
f"SELECT arrayElement(data_paths, 1) FROM system.tables WHERE database='default' AND name='{table_name}'"
|
|
).strip()
|
|
cmd = f"tail -c +17 {data_path}/{part_name}/{filename}.bin | od -x -N 1 | head -n 1 | awk '{{print $2}}'"
|
|
return node.exec_in_container(["bash", "-c", cmd]).strip()
|
|
|
|
|
|
CODECS_MAPPING = {
|
|
"NONE": "0002",
|
|
"LZ4": "0082",
|
|
"LZ4HC": "0082", # not an error, same byte
|
|
"ZSTD": "0090",
|
|
"Multiple": "0091",
|
|
"Delta": "0092",
|
|
"T64": "0093",
|
|
}
|
|
|
|
|
|
def test_nested_compression_codec(start_cluster):
|
|
for i, node in enumerate([node1, node2]):
|
|
node.query("DROP TABLE IF EXISTS compression_table SYNC")
|
|
node.query(
|
|
"""
|
|
CREATE TABLE compression_table (
|
|
key UInt64,
|
|
column_ok Nullable(UInt64) CODEC(Delta, LZ4),
|
|
column_array Array(Array(UInt64)) CODEC(T64, LZ4),
|
|
column_bad LowCardinality(Int64) CODEC(Delta)
|
|
) ENGINE = ReplicatedMergeTree('/t', '{}') ORDER BY tuple() PARTITION BY key
|
|
SETTINGS min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0, replace_long_file_name_to_hash = 0;
|
|
""".format(
|
|
i
|
|
),
|
|
settings={
|
|
"allow_suspicious_codecs": "1",
|
|
"allow_suspicious_low_cardinality_types": "1",
|
|
},
|
|
)
|
|
|
|
node1.query("INSERT INTO compression_table VALUES (1, 1, [[77]], 32)")
|
|
|
|
node2.query("SYSTEM SYNC REPLICA compression_table", timeout=5)
|
|
|
|
node1.query("DETACH TABLE compression_table")
|
|
node2.query("DETACH TABLE compression_table")
|
|
|
|
node1.query("ATTACH TABLE compression_table")
|
|
node2.query("ATTACH TABLE compression_table")
|
|
|
|
for node in [node1, node2]:
|
|
assert (
|
|
get_compression_codec_byte(
|
|
node, "compression_table", "1_0_0_0", "column_ok"
|
|
)
|
|
== CODECS_MAPPING["Multiple"]
|
|
)
|
|
assert (
|
|
get_compression_codec_byte(
|
|
node, "compression_table", "1_0_0_0", "column_ok.null"
|
|
)
|
|
== CODECS_MAPPING["LZ4"]
|
|
)
|
|
|
|
assert (
|
|
get_compression_codec_byte(
|
|
node1, "compression_table", "1_0_0_0", "column_array"
|
|
)
|
|
== CODECS_MAPPING["Multiple"]
|
|
)
|
|
assert (
|
|
get_compression_codec_byte(
|
|
node2, "compression_table", "1_0_0_0", "column_array.size0"
|
|
)
|
|
== CODECS_MAPPING["LZ4"]
|
|
)
|
|
assert (
|
|
get_compression_codec_byte(
|
|
node2, "compression_table", "1_0_0_0", "column_array.size1"
|
|
)
|
|
== CODECS_MAPPING["LZ4"]
|
|
)
|
|
|
|
assert (
|
|
get_compression_codec_byte(
|
|
node2, "compression_table", "1_0_0_0", "column_bad.dict"
|
|
)
|
|
== CODECS_MAPPING["Delta"]
|
|
)
|
|
assert (
|
|
get_compression_codec_byte(
|
|
node1, "compression_table", "1_0_0_0", "column_bad"
|
|
)
|
|
== CODECS_MAPPING["NONE"]
|
|
)
|
|
|
|
for node in [node1, node2]:
|
|
node.query("DROP TABLE IF EXISTS compression_table SYNC")
|