MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / sub_process

Function sub_process

union/D3L/opendata_large_query.py:33–82  ·  view source on GitHub ↗
(query_tables, queue)

Source from the content-addressed store, hash-verified

31 return result
32
33def sub_process(query_tables, queue):
34 tables_to_skip = ["USA_CSV0000000000001722"]
35 for i, table_name_with_extension in enumerate(query_tables):
36
37 table_name = os.path.splitext(table_name_with_extension)[0]
38 if table_name in tables_to_skip:
39 print(f"跳过查询表 {i + 1},因为它在要跳过的列表中")
40 queue.put(1) # 在队列中放入一个占位符值
41 continue
42 output_folder = "/home/wangyanzhang/d3l-main/d3l-main/examples/notebooks/opendata_large_50"
43 if not os.path.exists(output_folder):
44 os.makedirs(output_folder)
45 results_file = os.path.join(output_folder, f"{table_name}.csv")
46
47 if os.path.exists(results_file):
48 print(f"跳过查询表 {i + 1},因为结果文件已经存在:{results_file}")
49 queue.put(1) # 在队列中放入一个占位符值
50 continue
51
52 try:
53 # 执行查询
54 results, extended_results = qe.table_query(table=dataloader.read_table(table_name=table_name),
55 aggregator=None, k=50, verbose=True)
56
57
58 # 创建一个新的 CSV 文件
59 with open(results_file, mode='w', newline='') as csvfile:
60 writer = csv.writer(csvfile)
61
62 # Write the header
63 writer.writerow(['query_table', 'candidate_table', 'query_col_name', 'candidate_col_name'])
64
65 # 写入查询结果到 CSV 文件
66 for result in extended_results:
67 query_table = table_name
68 candidate_table = os.path.basename(result[0])
69
70 for x, column_info in enumerate(result[1]):
71 column_info_name = f"column_info{x+1}"
72 globals()[column_info_name] = column_info[0]
73
74 row = [f"{query_table}.csv", f"{candidate_table}.csv", column_info[0][0], column_info[0][1]]
75 writer.writerow(row)
76
77 print(f"Results for query table {i + 1} have been written to {results_file}")
78 queue.put(1)
79 except Exception as e:
80 # 在这里处理异常。你可以打印错误消息以进行调试。
81 print(f"查询表 {i + 1} 发生了异常:{e}")
82 queue.put((-1, "test-pid"))
83
84if __name__ == "__main__":
85 # 记录程序开始时间

Callers

nothing calls this directly

Calls 2

table_queryMethod · 0.80
read_tableMethod · 0.45

Tested by

no test coverage detected