Skip to content

Commit 62045f2

Browse files
committed
YQL-19747 insert hint freq
commit_hash:01de471fe936ed3f2cd62c15676f8497b764edde
1 parent 34ff7e5 commit 62045f2

File tree

5 files changed

+169
-1
lines changed

5 files changed

+169
-1
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
@@ -14,6 +14,11 @@
1414
"uri": "file://test.test_ExtractInFuncs_/results.txt"
1515
}
1616
],
17+
"test.test[ExtractInsertHints]": [
18+
{
19+
"uri": "file://test.test_ExtractInsertHints_/results.txt"
20+
}
21+
],
1722
"test.test[ExtractPragmas]": [
1823
{
1924
"uri": "file://test.test_ExtractPragmas_/results.txt"
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
"insert into plato.foo with (truncate,user_attrs='{}') select 1";
49+
[
50+
[
51+
[
52+
"INSERT_HINT";
53+
"truncate";
54+
"1"
55+
];
56+
[
57+
"INSERT_HINT";
58+
"user_attrs";
59+
"1"
60+
]
61+
]
62+
]
63+
];
64+
[
65+
"insert into plato.foo with columns struct<a:int32> select 1";
66+
[
67+
[
68+
[
69+
"INSERT_HINT";
70+
"columns";
71+
"1"
72+
]
73+
]
74+
]
75+
];
76+
[
77+
"insert into plato.foo with schema(a int32) select 1";
78+
[
79+
[
80+
[
81+
"INSERT_HINT";
82+
"schema";
83+
"1"
84+
]
85+
]
86+
]
87+
];
88+
[
89+
"insert into plato.foo with truncate select 1";
90+
[
91+
[
92+
[
93+
"INSERT_HINT";
94+
"truncate";
95+
"1"
96+
]
97+
]
98+
]
99+
]
100+
]
101+
}
102+
]
103+
}
104+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SELECT
2+
q,ListSort(ListFilter(YqlLang::RuleFreq(q),($x)->($x.0 in ("INSERT_HINT"))))
3+
FROM (VALUES
4+
("insert into plato.foo with truncate select 1"),
5+
("insert into plato.foo with schema(a int32) select 1"),
6+
("insert into plato.foo with columns struct<a:int32> select 1"),
7+
("insert into plato.foo with (truncate,user_attrs='{}') select 1")
8+
) AS a(q)
9+
order by q

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class TRuleFreqVisitor {
4747
VisitSimpleType(dynamic_cast<const TRule_type_name_simple&>(msg));
4848
} else if (descr == TRule_pragma_stmt::GetDescriptor()) {
4949
VisitPragmaStmt(dynamic_cast<const TRule_pragma_stmt&>(msg));
50+
} else if (descr == TRule_into_simple_table_ref::GetDescriptor()) {
51+
VisitInsertTableRef(dynamic_cast<const TRule_into_simple_table_ref&>(msg));
5052
}
5153

5254
TStringBuf fullName = descr->full_name();
@@ -93,6 +95,54 @@ class TRuleFreqVisitor {
9395
Freqs[std::make_pair("PRAGMA", prefix.empty() ? pragma : (prefix + "." + pragma))] += 1;
9496
}
9597

98+
void VisitHint(const TRule_table_hint& msg, const TString& parent) {
99+
switch (msg.Alt_case()) {
100+
case TRule_table_hint::kAltTableHint1: {
101+
const auto& alt = msg.GetAlt_table_hint1();
102+
const TString id = Id(alt.GetRule_an_id_hint1(), Translation);
103+
Freqs[std::make_pair(parent, id)] += 1;
104+
break;
105+
}
106+
case TRule_table_hint::kAltTableHint2: {
107+
const auto& alt = msg.GetAlt_table_hint2();
108+
Freqs[std::make_pair(parent, alt.GetToken1().GetValue())] += 1;
109+
break;
110+
}
111+
case TRule_table_hint::kAltTableHint3: {
112+
const auto& alt = msg.GetAlt_table_hint3();
113+
Freqs[std::make_pair(parent, alt.GetToken1().GetValue())] += 1;
114+
break;
115+
}
116+
case TRule_table_hint::ALT_NOT_SET:
117+
return;
118+
}
119+
}
120+
121+
void VisitInsertTableRef(const TRule_into_simple_table_ref& msg) {
122+
const TString parent = "INSERT_HINT";
123+
const auto& tableRef = msg.GetRule_simple_table_ref1();
124+
if (tableRef.HasBlock2()) {
125+
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+
}
143+
}
144+
}
145+
96146
template<typename TUnaryCasualExprRule>
97147
void VisitUnaryCasualSubexpr(const TUnaryCasualExprRule& msg) {
98148
const auto& block = msg.GetBlock1();

0 commit comments

Comments
 (0)