Skip to content

Commit ddeff53

Browse files
authored
Merge d913100 into e233933
2 parents e233933 + d913100 commit ddeff53

File tree

5 files changed

+166
-12
lines changed

5 files changed

+166
-12
lines changed

ydb/library/yql/sql/v1/sql_query.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,22 +2016,29 @@ bool TSqlQuery::AlterTableAlterFamily(const TRule_alter_table_alter_column_famil
20162016
<< "' in one alter";
20172017
return false;
20182018
}
2019-
const TString stringValue(Ctx.Token(value.GetAlt_family_setting_value1().GetToken1()));
2020-
entry->Data = BuildLiteralSmartString(Ctx, stringValue);
2019+
if (!StoreString(value, entry->Data, Ctx)) {
2020+
Ctx.Error() << to_upper(settingName.Name) << " value should be a string literal";
2021+
return false;
2022+
}
20212023
} else if (to_lower(settingName.Name) == "compression") {
20222024
if (entry->Compression) {
20232025
Ctx.Error() << "Redefinition of 'compression' setting for column family '" << name.Name
20242026
<< "' in one alter";
20252027
return false;
20262028
}
2027-
const TString stringValue(Ctx.Token(value.GetAlt_family_setting_value1().GetToken1()));
2028-
entry->Compression = BuildLiteralSmartString(Ctx, stringValue);
2029+
if (!StoreString(value, entry->Compression, Ctx)) {
2030+
Ctx.Error() << to_upper(settingName.Name) << " value should be a string literal";
2031+
return false;
2032+
}
20292033
} else if (to_lower(settingName.Name) == "compression_level") {
20302034
if (entry->CompressionLevel) {
20312035
Ctx.Error() << "Redefinition of 'compression_level' setting for column family '" << name.Name << "' in one alter";
20322036
return false;
20332037
}
2034-
entry->CompressionLevel = LiteralNumber(Ctx, value.GetAlt_family_setting_value2().GetRule_integer1());
2038+
if (!StoreInt(value, entry->CompressionLevel, Ctx)) {
2039+
Ctx.Error() << to_upper(settingName.Name) << " value should be an integer";
2040+
return false;
2041+
}
20352042
} else {
20362043
Ctx.Error() << "Unknown table setting: " << settingName.Name;
20372044
return false;

ydb/library/yql/sql/v1/sql_translation.cpp

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,17 +1567,59 @@ TNodePtr TSqlTranslation::SerialTypeNode(const TRule_type_name_or_bind& node) {
15671567
return nullptr;
15681568
}
15691569

1570+
bool StoreString(const TRule_family_setting_value& from, TNodePtr& to, TContext& ctx) {
1571+
switch (from.Alt_case()) {
1572+
case TRule_family_setting_value::kAltFamilySettingValue1: {
1573+
// STRING_VALUE
1574+
const TString stringValue(ctx.Token(from.GetAlt_family_setting_value1().GetToken1()));
1575+
TNodePtr literal = BuildLiteralSmartString(ctx, stringValue);
1576+
if (literal->IsNull()) {
1577+
return false;
1578+
}
1579+
to = literal;
1580+
break;
1581+
}
1582+
default:
1583+
return false;
1584+
}
1585+
return true;
1586+
}
1587+
1588+
bool StoreInt(const TRule_family_setting_value& from, TNodePtr& to, TContext& ctx) {
1589+
switch (from.Alt_case()) {
1590+
case TRule_family_setting_value::kAltFamilySettingValue2: {
1591+
// integer
1592+
TNodePtr literal = LiteralNumber(ctx, from.GetAlt_family_setting_value2().GetRule_integer1());
1593+
if (literal->IsNull()) {
1594+
return false;
1595+
}
1596+
to = literal;
1597+
break;
1598+
}
1599+
default:
1600+
return false;
1601+
}
1602+
return true;
1603+
}
1604+
15701605
bool TSqlTranslation::FillFamilySettingsEntry(const TRule_family_settings_entry& settingNode, TFamilyEntry& family) {
15711606
TIdentifier id = IdEx(settingNode.GetRule_an_id1(), *this);
15721607
const TRule_family_setting_value& value = settingNode.GetRule_family_setting_value3();
15731608
if (to_lower(id.Name) == "data") {
1574-
const TString stringValue(Ctx.Token(value.GetAlt_family_setting_value1().GetToken1()));
1575-
family.Data = BuildLiteralSmartString(Ctx, stringValue);
1609+
if (!StoreString(value, family.Data, Ctx)) {
1610+
Ctx.Error() << to_upper(id.Name) << " value should be a string literal";
1611+
return false;
1612+
}
15761613
} else if (to_lower(id.Name) == "compression") {
1577-
const TString stringValue(Ctx.Token(value.GetAlt_family_setting_value1().GetToken1()));
1578-
family.Compression = BuildLiteralSmartString(Ctx, stringValue);
1614+
if (!StoreString(value, family.Compression, Ctx)) {
1615+
Ctx.Error() << to_upper(id.Name) << " value should be a string literal";
1616+
return false;
1617+
}
15791618
} else if (to_lower(id.Name) == "compression_level") {
1580-
family.CompressionLevel = LiteralNumber(Ctx, value.GetAlt_family_setting_value2().GetRule_integer1());
1619+
if (!StoreInt(value, family.CompressionLevel, Ctx)) {
1620+
Ctx.Error() << to_upper(id.Name) << " value should be an integer";
1621+
return false;
1622+
}
15811623
} else {
15821624
Ctx.Error() << "Unknown table setting: " << id.Name;
15831625
return false;

ydb/library/yql/sql/v1/sql_translation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ class TSqlTranslation: public TTranslation {
287287

288288
TNodePtr LiteralNumber(TContext& ctx, const TRule_integer& node);
289289

290+
bool StoreString(const TRule_family_setting_value& from, TNodePtr& to, TContext& ctx);
291+
bool StoreInt(const TRule_family_setting_value& from, TNodePtr& to, TContext& ctx);
292+
290293
template<typename TChar>
291294
struct TPatternComponent {
292295
TBasicString<TChar> Prefix;

ydb/library/yql/sql/v1/sql_ut.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7426,7 +7426,7 @@ Y_UNIT_TEST_SUITE(Restore) {
74267426
}
74277427

74287428
Y_UNIT_TEST_SUITE(ColumnFamily) {
7429-
Y_UNIT_TEST(CompressionLevel) {
7429+
Y_UNIT_TEST(CompressionLevelCorrectUsage) {
74307430
NYql::TAstParseResult res = SqlToYql(R"( use plato;
74317431
CREATE TABLE tableName (
74327432
Key Uint32 FAMILY default,
@@ -7459,4 +7459,55 @@ Y_UNIT_TEST_SUITE(ColumnFamily) {
74597459
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
74607460
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["compression_level"]);
74617461
}
7462+
7463+
Y_UNIT_TEST(FieldDataIsNotString) {
7464+
NYql::TAstParseResult res = SqlToYql(R"( use plato;
7465+
CREATE TABLE tableName (
7466+
Key Uint32 FAMILY default,
7467+
PRIMARY KEY (Key),
7468+
FAMILY default (
7469+
DATA = 1,
7470+
COMPRESSION = "lz4",
7471+
COMPRESSION_LEVEL = 5
7472+
)
7473+
);
7474+
)");
7475+
UNIT_ASSERT(!res.IsOk());
7476+
UNIT_ASSERT(res.Issues.Size() == 1);
7477+
UNIT_ASSERT_STRING_CONTAINS(res.Issues.ToString(), "DATA value should be a string literal");
7478+
}
7479+
7480+
Y_UNIT_TEST(FieldCompressionIsNotString) {
7481+
NYql::TAstParseResult res = SqlToYql(R"( use plato;
7482+
CREATE TABLE tableName (
7483+
Key Uint32 FAMILY default,
7484+
PRIMARY KEY (Key),
7485+
FAMILY default (
7486+
DATA = "test",
7487+
COMPRESSION = 2,
7488+
COMPRESSION_LEVEL = 5
7489+
),
7490+
);
7491+
)");
7492+
UNIT_ASSERT(!res.IsOk());
7493+
UNIT_ASSERT(res.Issues.Size() == 1);
7494+
UNIT_ASSERT_STRING_CONTAINS(res.Issues.ToString(), "COMPRESSION value should be a string literal");
7495+
}
7496+
7497+
Y_UNIT_TEST(FieldCompressionLevelIsNotInteger) {
7498+
NYql::TAstParseResult res = SqlToYql(R"( use plato;
7499+
CREATE TABLE tableName (
7500+
Key Uint32 FAMILY default,
7501+
PRIMARY KEY (Key),
7502+
FAMILY default (
7503+
DATA = "test",
7504+
COMPRESSION = "lz4",
7505+
COMPRESSION_LEVEL = "5"
7506+
)
7507+
);
7508+
)");
7509+
UNIT_ASSERT(!res.IsOk());
7510+
UNIT_ASSERT(res.Issues.Size() == 1);
7511+
UNIT_ASSERT_STRING_CONTAINS(res.Issues.ToString(), "COMPRESSION_LEVEL value should be an integer");
7512+
}
74627513
}

ydb/library/yql/sql/v1/sql_ut_antlr4.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7398,7 +7398,7 @@ Y_UNIT_TEST_SUITE(Restore) {
73987398
}
73997399

74007400
Y_UNIT_TEST_SUITE(ColumnFamily) {
7401-
Y_UNIT_TEST(CompressionLevel) {
7401+
Y_UNIT_TEST(CompressionLevelCorrectUsage) {
74027402
NYql::TAstParseResult res = SqlToYql(R"( use plato;
74037403
CREATE TABLE tableName (
74047404
Key Uint32 FAMILY default,
@@ -7431,4 +7431,55 @@ Y_UNIT_TEST_SUITE(ColumnFamily) {
74317431
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
74327432
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["compression_level"]);
74337433
}
7434+
7435+
Y_UNIT_TEST(FieldDataIsNotString) {
7436+
NYql::TAstParseResult res = SqlToYql(R"( use plato;
7437+
CREATE TABLE tableName (
7438+
Key Uint32 FAMILY default,
7439+
PRIMARY KEY (Key),
7440+
FAMILY default (
7441+
DATA = 1,
7442+
COMPRESSION = "lz4",
7443+
COMPRESSION_LEVEL = 5
7444+
)
7445+
);
7446+
)");
7447+
UNIT_ASSERT(!res.IsOk());
7448+
UNIT_ASSERT(res.Issues.Size() == 1);
7449+
UNIT_ASSERT_STRING_CONTAINS(res.Issues.ToString(), "DATA value should be a string literal");
7450+
}
7451+
7452+
Y_UNIT_TEST(FieldCompressionIsNotString) {
7453+
NYql::TAstParseResult res = SqlToYql(R"( use plato;
7454+
CREATE TABLE tableName (
7455+
Key Uint32 FAMILY default,
7456+
PRIMARY KEY (Key),
7457+
FAMILY default (
7458+
DATA = "test",
7459+
COMPRESSION = 2,
7460+
COMPRESSION_LEVEL = 5
7461+
),
7462+
);
7463+
)");
7464+
UNIT_ASSERT(!res.IsOk());
7465+
UNIT_ASSERT(res.Issues.Size() == 1);
7466+
UNIT_ASSERT_STRING_CONTAINS(res.Issues.ToString(), "COMPRESSION value should be a string literal");
7467+
}
7468+
7469+
Y_UNIT_TEST(FieldCompressionLevelIsNotInteger) {
7470+
NYql::TAstParseResult res = SqlToYql(R"( use plato;
7471+
CREATE TABLE tableName (
7472+
Key Uint32 FAMILY default,
7473+
PRIMARY KEY (Key),
7474+
FAMILY default (
7475+
DATA = "test",
7476+
COMPRESSION = "lz4",
7477+
COMPRESSION_LEVEL = "5"
7478+
)
7479+
);
7480+
)");
7481+
UNIT_ASSERT(!res.IsOk());
7482+
UNIT_ASSERT(res.Issues.Size() == 1);
7483+
UNIT_ASSERT_STRING_CONTAINS(res.Issues.ToString(), "COMPRESSION_LEVEL value should be an integer");
7484+
}
74347485
}

0 commit comments

Comments
 (0)