Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/DataTypes/registerDataTypeDateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ static DataTypePtr create32(const ASTPtr & arguments, [[maybe_unused]] bool comp
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
"The datetime32 data type can optionally have only one argument - time zone name");

const auto * argument = arguments->children[0]->as<ASTLiteral>();
if (argument && argument->value.getType() == Field::Types::Which::UInt64)
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"The datetime32 data type does not support precision. Use datetime64 for fractional seconds");

const auto timezone = getArgument<String, ArgumentKind::Mandatory>(arguments, 0, "timezone", "datetime32");

return std::make_shared<DataTypeDateTime>(timezone);
Expand Down
16 changes: 16 additions & 0 deletions src/DataTypes/tests/gtest_data_types_binary_encoding.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include <Core/Field.h>
#include <Common/Exception.h>
#include <DataTypes/DataTypesBinaryEncoding.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypeFixedString.h>
Expand Down Expand Up @@ -27,6 +28,7 @@ using namespace DB;
namespace DB::ErrorCodes
{
extern const int UNSUPPORTED_METHOD;
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}


Expand Down Expand Up @@ -135,3 +137,17 @@ GTEST_TEST(DataTypesBinaryEncoding, EncodeAndDecode)
check(DataTypeFactory::instance().get("json(max_dynamic_paths=10)"));
check(DataTypeFactory::instance().get("json(max_dynamic_paths=10, max_dynamic_types=10, a.b.c uint32, SKIP a.c, b.g string, SKIP l.d.f)"));
}

GTEST_TEST(DataTypeFactory, DateTime32PrecisionError)
{
try
{
DataTypeFactory::instance().get("datetime32(3)");
FAIL() << "Expected datetime32 precision to throw";
}
catch (const Exception & e)
{
EXPECT_EQ(e.code(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
EXPECT_NE(std::string(e.what()).find("datetime32 data type does not support precision"), std::string::npos);
}
}