Skip to content

Commit e99e94e

Browse files
committed
Quoting timezone if present in DateTime/DateTime64
Added some test
1 parent d934380 commit e99e94e

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

clickhouse/types/types.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ DateTimeType::DateTimeType(std::string timezone)
245245

246246
std::string DateTimeType::GetName() const {
247247
std::string datetime_representation = "DateTime";
248-
const auto timezone = Timezone();
248+
const auto & timezone = Timezone();
249249
if (!timezone.empty())
250-
datetime_representation += "(" + timezone + ")";
250+
datetime_representation += "('" + timezone + "')";
251251

252252
return datetime_representation;
253253
}
254254

255255
/// class DateTime64Type
256256

257257
DateTime64Type::DateTime64Type(size_t precision, std::string timezone)
258-
: Type(DateTime64), TypeWithTimeZoneMixin(std::move(timezone)), precision_(precision) {
258+
: Type(DateTime64), details::TypeWithTimeZoneMixin(std::move(timezone)), precision_(precision) {
259259

260260
if (precision_ > 18) {
261261
throw std::runtime_error("DateTime64 precision is > 18");
@@ -268,9 +268,9 @@ std::string DateTime64Type::GetName() const {
268268
datetime64_representation += "DateTime64(";
269269
datetime64_representation += std::to_string(precision_);
270270

271-
const auto timezone = Timezone();
271+
const auto & timezone = Timezone();
272272
if (!timezone.empty()) {
273-
datetime64_representation += ", " + timezone;
273+
datetime64_representation += ", '" + timezone + "'";
274274
}
275275

276276
datetime64_representation += ")";

ut/columns_ut.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,3 +596,35 @@ TEST(ColumnsCase, UnmatchedBrackets) {
596596
ASSERT_EQ(nullptr, CreateColumnByType("Array(LowCardinality(Nullable(FixedString(10000))"));
597597
ASSERT_EQ(nullptr, CreateColumnByType("Array(LowCardinality(Nullable(FixedString(10000)))"));
598598
}
599+
600+
class ColumnsCaseWithName : public ::testing::TestWithParam<const char* /*Column Type String*/>
601+
{};
602+
603+
TEST_P(ColumnsCaseWithName, CreateColumnByType)
604+
{
605+
const auto col = CreateColumnByType(GetParam());
606+
ASSERT_NE(nullptr, col);
607+
EXPECT_EQ(col->GetType().GetName(), GetParam());
608+
}
609+
610+
INSTANTIATE_TEST_CASE_P(Basic, ColumnsCaseWithName, ::testing::Values(
611+
"Int8", "Int16", "Int32", "Int64",
612+
"UInt8", "UInt16", "UInt32", "UInt64",
613+
"String", "Date", "DateTime"
614+
));
615+
616+
INSTANTIATE_TEST_CASE_P(Parametrized, ColumnsCaseWithName, ::testing::Values(
617+
"FixedString(0)", "FixedString(10000)",
618+
"DateTime('UTC')", "DateTime64(3, 'UTC')",
619+
"Decimal(9,3)", "Decimal(18,3)",
620+
"Enum8('ONE' = 1, 'TWO' = 2)",
621+
"Enum16('ONE' = 1, 'TWO' = 2, 'THREE' = 3, 'FOUR' = 4)"
622+
));
623+
624+
625+
INSTANTIATE_TEST_CASE_P(Nested, ColumnsCaseWithName, ::testing::Values(
626+
"Nullable(FixedString(10000))",
627+
"Nullable(LowCardinality(FixedString(10000)))",
628+
"Array(Nullable(LowCardinality(FixedString(10000))))",
629+
"Array(Enum8('ONE' = 1, 'TWO' = 2))"
630+
));

0 commit comments

Comments
 (0)