Skip to content

Commit acc29b6

Browse files
yihong0618evenyag
authored andcommitted
fix: better fmt check from 40s to 4s (GreptimeTeam#5279)
Signed-off-by: yihong0618 <[email protected]>
1 parent 25745a7 commit acc29b6

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

scripts/check-snafu.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import os
1616
import re
17+
from multiprocessing import Pool
1718

1819

1920
def find_rust_files(directory):
@@ -33,13 +34,11 @@ def extract_branch_names(file_content):
3334
return pattern.findall(file_content)
3435

3536

36-
def check_snafu_in_files(branch_name, rust_files):
37+
def check_snafu_in_files(branch_name, rust_files_content):
3738
branch_name_snafu = f"{branch_name}Snafu"
38-
for rust_file in rust_files:
39-
with open(rust_file, "r") as file:
40-
content = file.read()
41-
if branch_name_snafu in content:
42-
return True
39+
for content in rust_files_content.values():
40+
if branch_name_snafu in content:
41+
return True
4342
return False
4443

4544

@@ -49,21 +48,24 @@ def main():
4948

5049
for error_file in error_files:
5150
with open(error_file, "r") as file:
52-
content = file.read()
53-
branch_names.extend(extract_branch_names(content))
51+
branch_names.extend(extract_branch_names(file.read()))
52+
53+
# Read all rust files into memory once
54+
rust_files_content = {}
55+
for rust_file in other_rust_files:
56+
with open(rust_file, "r") as file:
57+
rust_files_content[rust_file] = file.read()
5458

55-
unused_snafu = [
56-
branch_name
57-
for branch_name in branch_names
58-
if not check_snafu_in_files(branch_name, other_rust_files)
59-
]
59+
with Pool() as pool:
60+
results = pool.starmap(
61+
check_snafu_in_files, [(bn, rust_files_content) for bn in branch_names]
62+
)
63+
unused_snafu = [bn for bn, found in zip(branch_names, results) if not found]
6064

6165
if unused_snafu:
6266
print("Unused error variants:")
6367
for name in unused_snafu:
6468
print(name)
65-
66-
if unused_snafu:
6769
raise SystemExit(1)
6870

6971

src/common/datasource/tests/orc/write.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@
3535
"bigint_other": [5, -5, 1, 5, 5],
3636
"utf8_increase": ["a", "bb", "ccc", "dddd", "eeeee"],
3737
"utf8_decrease": ["eeeee", "dddd", "ccc", "bb", "a"],
38-
"timestamp_simple": [datetime.datetime(2023, 4, 1, 20, 15, 30, 2000), datetime.datetime.fromtimestamp(int('1629617204525777000')/1000000000), datetime.datetime(2023, 1, 1), datetime.datetime(2023, 2, 1), datetime.datetime(2023, 3, 1)],
39-
"date_simple": [datetime.date(2023, 4, 1), datetime.date(2023, 3, 1), datetime.date(2023, 1, 1), datetime.date(2023, 2, 1), datetime.date(2023, 3, 1)]
38+
"timestamp_simple": [
39+
datetime.datetime(2023, 4, 1, 20, 15, 30, 2000),
40+
datetime.datetime.fromtimestamp(int("1629617204525777000") / 1000000000),
41+
datetime.datetime(2023, 1, 1),
42+
datetime.datetime(2023, 2, 1),
43+
datetime.datetime(2023, 3, 1),
44+
],
45+
"date_simple": [
46+
datetime.date(2023, 4, 1),
47+
datetime.date(2023, 3, 1),
48+
datetime.date(2023, 1, 1),
49+
datetime.date(2023, 2, 1),
50+
datetime.date(2023, 3, 1),
51+
],
4052
}
4153

54+
4255
def infer_schema(data):
4356
schema = "struct<"
4457
for key, value in data.items():
@@ -56,7 +69,7 @@ def infer_schema(data):
5669
elif key.startswith("date"):
5770
dt = "date"
5871
else:
59-
print(key,value,dt)
72+
print(key, value, dt)
6073
raise NotImplementedError
6174
if key.startswith("double"):
6275
dt = "double"
@@ -68,7 +81,6 @@ def infer_schema(data):
6881
return schema
6982

7083

71-
7284
def _write(
7385
schema: str,
7486
data,

0 commit comments

Comments
 (0)