Skip to content

Commit 78c6255

Browse files
committed
YQL-19747 read hint freq
commit_hash:9fbf12725871e41f15c0be6bc2c7b4dc1b3ce7de
1 parent 62045f2 commit 78c6255

File tree

5 files changed

+123
-19
lines changed

5 files changed

+123
-19
lines changed

yql/essentials/data/language/rules_corr_basic.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

yql/essentials/udfs/language/yql/test/canondata/result.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"uri": "file://test.test_ExtractPragmas_/results.txt"
2525
}
2626
],
27+
"test.test[ExtractReadHints]": [
28+
{
29+
"uri": "file://test.test_ExtractReadHints_/results.txt"
30+
}
31+
],
2732
"test.test[ExtractTypes]": [
2833
{
2934
"uri": "file://test.test_ExtractTypes_/results.txt"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[
2+
{
3+
"Write" = [
4+
{
5+
"Type" = [
6+
"ListType";
7+
[
8+
"StructType";
9+
[
10+
[
11+
"q";
12+
[
13+
"DataType";
14+
"String"
15+
]
16+
];
17+
[
18+
"column1";
19+
[
20+
"OptionalType";
21+
[
22+
"ListType";
23+
[
24+
"TupleType";
25+
[
26+
[
27+
"DataType";
28+
"String"
29+
];
30+
[
31+
"DataType";
32+
"String"
33+
];
34+
[
35+
"DataType";
36+
"Uint64"
37+
]
38+
]
39+
]
40+
]
41+
]
42+
]
43+
]
44+
]
45+
];
46+
"Data" = [
47+
[
48+
"select * from foo.bar with (inline, infer_scheme)";
49+
[
50+
[
51+
[
52+
"READ_HINT";
53+
"infer_scheme";
54+
"1"
55+
];
56+
[
57+
"READ_HINT";
58+
"inline";
59+
"1"
60+
]
61+
]
62+
]
63+
];
64+
[
65+
"select * from foo.bar with xlock";
66+
[
67+
[
68+
[
69+
"READ_HINT";
70+
"xlock";
71+
"1"
72+
]
73+
]
74+
]
75+
]
76+
]
77+
}
78+
]
79+
}
80+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT
2+
q,ListSort(ListFilter(YqlLang::RuleFreq(q),($x)->($x.0 in ("READ_HINT"))))
3+
FROM (VALUES
4+
("select * from foo.bar with xlock"),
5+
("select * from foo.bar with (inline, infer_scheme)")
6+
) AS a(q)
7+
order by q

yql/essentials/udfs/language/yql/yql_language_udf.cpp

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class TRuleFreqVisitor {
4949
VisitPragmaStmt(dynamic_cast<const TRule_pragma_stmt&>(msg));
5050
} else if (descr == TRule_into_simple_table_ref::GetDescriptor()) {
5151
VisitInsertTableRef(dynamic_cast<const TRule_into_simple_table_ref&>(msg));
52+
} else if (descr == TRule_table_ref::GetDescriptor()) {
53+
VisitReadTableRef(dynamic_cast<const TRule_table_ref&>(msg));
5254
}
5355

5456
TStringBuf fullName = descr->full_name();
@@ -118,28 +120,38 @@ class TRuleFreqVisitor {
118120
}
119121
}
120122

123+
void VisitHints(const TRule_table_hints& msg, const TString& parent) {
124+
auto& block = msg.GetBlock2();
125+
switch (block.Alt_case()) {
126+
case TRule_table_hints::TBlock2::kAlt1: {
127+
VisitHint(block.GetAlt1().GetRule_table_hint1(), parent);
128+
break;
129+
}
130+
case TRule_table_hints::TBlock2::kAlt2: {
131+
VisitHint(block.GetAlt2().GetRule_table_hint2(), parent);
132+
for (const auto& x : block.GetAlt2().GetBlock3()) {
133+
VisitHint(x.GetRule_table_hint2(), parent);
134+
}
135+
136+
break;
137+
}
138+
case TRule_table_hints::TBlock2::ALT_NOT_SET:
139+
return;
140+
}
141+
}
142+
143+
void VisitReadTableRef(const TRule_table_ref& msg) {
144+
if (msg.HasBlock4()) {
145+
const auto& hints = msg.GetBlock4().GetRule_table_hints1();
146+
VisitHints(hints, "READ_HINT");
147+
}
148+
}
149+
121150
void VisitInsertTableRef(const TRule_into_simple_table_ref& msg) {
122-
const TString parent = "INSERT_HINT";
123151
const auto& tableRef = msg.GetRule_simple_table_ref1();
124152
if (tableRef.HasBlock2()) {
125153
const auto& hints = tableRef.GetBlock2().GetRule_table_hints1();
126-
auto& block = hints.GetBlock2();
127-
switch (block.Alt_case()) {
128-
case TRule_table_hints::TBlock2::kAlt1: {
129-
VisitHint(block.GetAlt1().GetRule_table_hint1(), parent);
130-
break;
131-
}
132-
case TRule_table_hints::TBlock2::kAlt2: {
133-
VisitHint(block.GetAlt2().GetRule_table_hint2(), parent);
134-
for (const auto& x : block.GetAlt2().GetBlock3()) {
135-
VisitHint(x.GetRule_table_hint2(), parent);
136-
}
137-
138-
break;
139-
}
140-
case TRule_table_hints::TBlock2::ALT_NOT_SET:
141-
return;
142-
}
154+
VisitHints(hints, "INSERT_HINT");
143155
}
144156
}
145157

0 commit comments

Comments
 (0)