Skip to content

Commit 726c7bf

Browse files
authored
Merge 9548866 into 3079189
2 parents 3079189 + 9548866 commit 726c7bf

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

ydb/library/yql/sql/pg/pg_sql.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class TConverter : public IPGParseEvents {
222222
bool AllowOver = false;
223223
bool AllowReturnSet = false;
224224
bool AllowSubLinks = false;
225+
bool AutoParametrizeEnabled = true;
225226
TVector<TAstNode*>* WindowItems = nullptr;
226227
TString Scope;
227228
};
@@ -1710,6 +1711,7 @@ class TConverter : public IPGParseEvents {
17101711
TExprSettings settings;
17111712
settings.AllowColumns = false;
17121713
settings.Scope = "DEFAULT";
1714+
settings.AutoParametrizeEnabled = false;
17131715
cinfo.Default = ParseExpr(constraintNode->raw_expr, settings);
17141716
if (!cinfo.Default) {
17151717
return false;
@@ -3111,7 +3113,7 @@ class TConverter : public IPGParseEvents {
31113113
? L(A("PgType"), QA(TPgConst::ToString(valueNType->type)))
31123114
: L(A("PgType"), QA("unknown"));
31133115

3114-
if (Settings.AutoParametrizeEnabled && !Settings.AutoParametrizeExprDisabledScopes.contains(settings.Scope)) {
3116+
if (Settings.AutoParametrizeEnabled && settings.AutoParametrizeEnabled) {
31153117
return AutoParametrizeConst(std::move(valueNType.GetRef()), pgTypeNode);
31163118
}
31173119

ydb/library/yql/sql/pg/pg_sql_autoparam_ut.cpp

+19-21
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
1313
UNIT_ASSERT_C(res.Issues.Empty(), "Failed to parse statement, issues: " + res.Issues.ToString());
1414
UNIT_ASSERT_C(res.PgAutoParamValues.Empty(), "Expected no auto parametrization");
1515
}
16-
17-
Y_UNIT_TEST(AutoParamValues_DifferentTypes) {
16+
17+
Y_UNIT_TEST(AutoParamValues_NoParametersWithDefaults) {
1818
TTranslationSettings settings;
1919
settings.AutoParametrizeEnabled = true;
2020
settings.AutoParametrizeValuesStmt = true;
21-
settings.AutoParametrizeExprDisabledScopes = {"VALUES"};
2221
auto res = SqlToYqlWithMode(
23-
R"(insert into plato.Output values (1,2,3), (1,2.0,3))",
22+
R"(CREATE TABLE t (a int PRIMARY KEY, b int DEFAULT 0))",
2423
NSQLTranslation::ESqlMode::QUERY,
2524
10,
2625
{},
@@ -33,10 +32,10 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
3332
}
3433

3534
using TUsedParamsGetter = std::function<void(TSet<TString>&, const NYql::TAstNode& node)>;
36-
35+
3736
void GetUsedParamsInValues(TSet<TString>& usedParams, const NYql::TAstNode& node) {
38-
const bool isPgSetItem =
39-
node.IsListOfSize(2) && node.GetChild(0)->IsAtom()
37+
const bool isPgSetItem =
38+
node.IsListOfSize(2) && node.GetChild(0)->IsAtom()
4039
&& node.GetChild(0)->GetContent() == "PgSetItem";
4140
if (!isPgSetItem) {
4241
return;
@@ -45,7 +44,7 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
4544

4645
for (const auto* pgOption : pgSetItemOptions->GetChildren()) {
4746
const bool isQuotedList =
48-
pgOption->IsListOfSize(2) && pgOption->GetChild(0)->IsAtom()
47+
pgOption->IsListOfSize(2) && pgOption->GetChild(0)->IsAtom()
4948
&& pgOption->GetChild(0)->GetContent() == "quote";
5049
if (!isQuotedList) {
5150
continue;
@@ -54,7 +53,7 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
5453
const auto* option = pgOption->GetChild(1);
5554
const auto* optionName = option->GetChild(0);
5655

57-
const bool isValuesNode =
56+
const bool isValuesNode =
5857
optionName->IsListOfSize(2) && optionName->GetChild(0)->IsAtom()
5958
&& optionName->GetChild(0)->GetContent() == "quote"
6059
&& optionName->GetChild(1)->GetContent() == "values";
@@ -68,11 +67,10 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
6867
}
6968
}
7069

71-
void TestAutoParam(const TString& query, const THashMap<TString, TString>& expectedParamNameToJsonYdbVal, const TMap<TString, TString>& expectedParamTypes, TUsedParamsGetter usedParamsGetter, THashSet<TString> disabledParametrizeScopes = {}) {
70+
void TestAutoParam(const TString& query, const THashMap<TString, TString>& expectedParamNameToJsonYdbVal, const TMap<TString, TString>& expectedParamTypes, TUsedParamsGetter usedParamsGetter) {
7271
TTranslationSettings settings;
7372
settings.AutoParametrizeEnabled = true;
7473
settings.AutoParametrizeValuesStmt = true;
75-
settings.AutoParametrizeExprDisabledScopes = disabledParametrizeScopes;
7674
auto res = SqlToYqlWithMode(
7775
query,
7876
NSQLTranslation::ESqlMode::QUERY,
@@ -87,9 +85,9 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
8785
TSet<TString> declaredParams;
8886
TMap<TString, TString> actualParamTypes;
8987
VisitAstNodes(*res.Root, [&declaredParams, &actualParamTypes] (const NYql::TAstNode& node) {
90-
const bool isDeclareNode =
91-
node.IsList() && node.GetChildrenCount() > 0
92-
&& node.GetChild(0)->IsAtom()
88+
const bool isDeclareNode =
89+
node.IsList() && node.GetChildrenCount() > 0
90+
&& node.GetChild(0)->IsAtom()
9391
&& node.GetChild(0)->GetContent() == "declare";
9492
if (isDeclareNode) {
9593
UNIT_ASSERT_VALUES_EQUAL(node.GetChildrenCount(), 3);
@@ -114,7 +112,7 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
114112

115113
auto actualParam = res.PgAutoParamValues.GetRef()[expectedParamName];
116114
UNIT_ASSERT_STRINGS_EQUAL(expectedParam.ShortUtf8DebugString(), actualParam.ShortUtf8DebugString());
117-
UNIT_ASSERT_C(declaredParams.contains(expectedParamName),
115+
UNIT_ASSERT_C(declaredParams.contains(expectedParamName),
118116
"Declared params don't contain expected param name: " << expectedParamName);
119117
}
120118

@@ -184,7 +182,7 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
184182
TString type = "(ListType (TupleType (PgType 'unknown) (PgType 'int4)))";
185183
TestAutoParam(query, {{"a0", expectedParamJson}}, {{"a0", type}}, GetUsedParamsInValues);
186184
}
187-
185+
188186
Y_UNIT_TEST(AutoParamConsts_Where) {
189187
TString query = R"(
190188
select * from plato.Output where key > 1
@@ -201,8 +199,8 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
201199
return;
202200
}
203201
const auto quotedVal = maybeQuote.GetRef();
204-
const bool isWhere =
205-
quotedVal->IsListOfSize(2) && quotedVal->GetChild(1)->IsListOfSize(3)
202+
const bool isWhere =
203+
quotedVal->IsListOfSize(2) && quotedVal->GetChild(1)->IsListOfSize(3)
206204
&& quotedVal->GetChild(1)->IsListOfSize(3)
207205
&& quotedVal->GetChild(1)->GetChild(0)->IsAtom()
208206
&& quotedVal->GetChild(1)->GetChild(0)->GetContent() == "PgWhere";
@@ -224,7 +222,7 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
224222
TString type = "(PgType 'int4)";
225223
TestAutoParam(query, {{"a0", expectedParamJson}}, {{"a0", type}}, usedInWhereComp);
226224
}
227-
225+
228226
Y_UNIT_TEST(AutoParamConsts_Select) {
229227
TString query = R"(
230228
select 1, 'test', B'10001'
@@ -250,7 +248,7 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
250248
{"a2", "(PgType 'bit)"},
251249
};
252250
TestAutoParam(query, {
253-
{"a0", expectedParamJsonInt4},
251+
{"a0", expectedParamJsonInt4},
254252
{"a1", expectedParamJsonText},
255253
{"a2", expectedParamJsonBit},
256254
}, expectedParamTypes, dummyGetter);
@@ -270,7 +268,7 @@ Y_UNIT_TEST_SUITE(PgSqlParsingAutoparam) {
270268
const TUsedParamsGetter dummyGetter = [] (TSet<TString>& usedParams, const NYql::TAstNode&) {
271269
usedParams = {"a0", "a1"};
272270
};
273-
TestAutoParam(query, {{"a0", expectedParamJsonInt4}, {"a1", expectedParamJsonText}}, paramToType, dummyGetter, {});
271+
TestAutoParam(query, {{"a0", expectedParamJsonInt4}, {"a1", expectedParamJsonText}}, paramToType, dummyGetter);
274272
}
275273

276274
}

ydb/library/yql/sql/settings/translation_settings.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace NSQLTranslation {
2727
};
2828

2929
enum class EBindingsMode {
30-
// raise error
30+
// raise error
3131
DISABLED,
3232
// classic support for bindings
3333
ENABLED,
@@ -111,7 +111,6 @@ namespace NSQLTranslation {
111111
TVector<ui32> PgParameterTypeOids;
112112
bool AutoParametrizeEnabled = false;
113113
bool AutoParametrizeValuesStmt = false;
114-
THashSet<TString> AutoParametrizeExprDisabledScopes = {};
115114

116115
TGUCSettings::TPtr GUCSettings = std::make_shared<TGUCSettings>();
117116
bool UnicodeLiterals = false;

0 commit comments

Comments
 (0)