aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruzhas <uzhas@ydb.tech>2022-09-07 13:56:10 +0300
committeruzhas <uzhas@ydb.tech>2022-09-07 13:56:10 +0300
commit797ad94f1f5268c9424a5157abed26c6a0c5bf3a (patch)
treece1d49ab630b6a2a324638fe9b75dc02d57bc67e
parent8defe59106983bbb7d3fe3cd71b752a743d0bbba (diff)
downloadydb-797ad94f1f5268c9424a5157abed26c6a0c5bf3a.tar.gz
strip enum values
-rw-r--r--ydb/library/yql/providers/s3/path_generator/ut/yql_parse_partitioning_rules_ut.cpp21
-rw-r--r--ydb/library/yql/providers/s3/path_generator/yql_s3_path_generator.cpp9
2 files changed, 28 insertions, 2 deletions
diff --git a/ydb/library/yql/providers/s3/path_generator/ut/yql_parse_partitioning_rules_ut.cpp b/ydb/library/yql/providers/s3/path_generator/ut/yql_parse_partitioning_rules_ut.cpp
index bea34672ffa..3951752a5ba 100644
--- a/ydb/library/yql/providers/s3/path_generator/ut/yql_parse_partitioning_rules_ut.cpp
+++ b/ydb/library/yql/providers/s3/path_generator/ut/yql_parse_partitioning_rules_ut.cpp
@@ -26,6 +26,27 @@ Y_UNIT_TEST_SUITE(TParseTests) {
UNIT_ASSERT_VALUES_EQUAL(rule.Values.back(), "SPB");
}
+ Y_UNIT_TEST(SuccessParseEnumWithStrip) {
+ auto generator = CreatePathGenerator(R"(
+ {
+ "projection.enabled" : true,
+ "projection.city.type" : "enum",
+ "projection.city.values" : " MSK , SPB ",
+ "storage.location.template" : "/${city}/"
+ }
+ )", {"city"});
+ const auto& result = generator->GetConfig();
+ UNIT_ASSERT_VALUES_EQUAL(result.Enabled, true);
+ UNIT_ASSERT_VALUES_EQUAL(result.LocationTemplate, "/${city}/");
+ UNIT_ASSERT_VALUES_EQUAL(result.Rules.size(), 1);
+ const auto& rule = result.Rules.front();
+ UNIT_ASSERT_VALUES_EQUAL(rule.Type, IPathGenerator::EType::ENUM);
+ UNIT_ASSERT_VALUES_EQUAL(rule.Name, "city");
+ UNIT_ASSERT_VALUES_EQUAL(rule.Values.size(), 2);
+ UNIT_ASSERT_VALUES_EQUAL(rule.Values.front(), "MSK");
+ UNIT_ASSERT_VALUES_EQUAL(rule.Values.back(), "SPB");
+ }
+
Y_UNIT_TEST(ParseTwoEnabled) {
UNIT_ASSERT_NO_EXCEPTION(CreatePathGenerator(R"(
{
diff --git a/ydb/library/yql/providers/s3/path_generator/yql_s3_path_generator.cpp b/ydb/library/yql/providers/s3/path_generator/yql_s3_path_generator.cpp
index a0a6a876da7..ed0b00a6b0d 100644
--- a/ydb/library/yql/providers/s3/path_generator/yql_s3_path_generator.cpp
+++ b/ydb/library/yql/providers/s3/path_generator/yql_s3_path_generator.cpp
@@ -6,6 +6,7 @@
#include <util/generic/serialized_enum.h>
#include <util/string/cast.h>
#include <util/string/split.h>
+#include <util/string/strip.h>
namespace NYql::NPathGenerator {
@@ -368,8 +369,12 @@ private:
if (p.first == "type") {
// already processed
} else if (p.first == "values") {
- TString values = GetStringOrThrow(p.second, "The values must be a string");
- Config.Rules.push_back(IPathGenerator::TColumnPartitioningConfig{.Type=ToType(type), .Name=columnName, .Values=StringSplitter(values).Split(',').ToList<TString>()});
+ TString valuesStr = GetStringOrThrow(p.second, "The values must be a string");
+ auto values = StringSplitter(valuesStr).Split(',').SkipEmpty().ToList<TString>();
+ for (auto& v : values) {
+ v = StripString(v);
+ }
+ Config.Rules.push_back(IPathGenerator::TColumnPartitioningConfig{.Type=ToType(type), .Name=columnName, .Values=std::move(values)});
} else {
ythrow yexception() << "Invalid projection scheme: enum element must include only type or values (as string) but got " << p.first;
}