- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorization.py
More file actions
Latest commit
24 lines (20 loc) · 916 Bytes
/
Copy pathVectorization.py
File metadata and controls
24 lines (20 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
importtorch
# 递归构建查询计划树的特征向量
defconstruct_feature_vector(query_plan_tree):
defencode_sub_plan(sub_plan):
encoded= []
node_type_id=int(sub_plan.get("Node Type ID", 0))
encoded.append(node_type_id)
encoded.append((sub_plan.get("Total Cost", 0) /1000000))
encoded.append((sub_plan.get("Plan Rows", 0)))
forsub_sub_planinsub_plan.get("Plans", []):
encoded.extend(encode_sub_plan(sub_sub_plan))
returnencoded
encoded_sequence= []
encoded_sequence.extend(encode_sub_plan(query_plan_tree))
MAX_LENGTH=30# 例如
iflen(encoded_sequence) <MAX_LENGTH:
encoded_sequence+= [0] * (MAX_LENGTH-len(encoded_sequence))
eliflen(encoded_sequence) >MAX_LENGTH:
encoded_sequence=encoded_sequence[:MAX_LENGTH]
returntorch.tensor(encoded_sequence, dtype=torch.float32)