Dictionaries added Date32 type support

This commit is contained in:
Maksim Kita 2022-01-20 13:48:33 +00:00
parent 2eb9b3118e
commit 115ecb09a8
3 changed files with 42 additions and 12 deletions

View File

@ -1,17 +1,20 @@
#include "DictionaryStructure.h"
#include <Dictionaries/DictionaryStructure.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <IO/WriteHelpers.h>
#include <IO/Operators.h>
#include <Common/StringUtils/StringUtils.h>
#include <Formats/FormatSettings.h>
#include <Columns/IColumn.h>
#include <DataTypes/DataTypeFactory.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeArray.h>
#include <Functions/FunctionHelpers.h>
#include <Formats/FormatSettings.h>
#include <IO/WriteHelpers.h>
#include <IO/Operators.h>
#include <Common/StringUtils/StringUtils.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
namespace DB
@ -38,13 +41,14 @@ DictionaryTypedSpecialAttribute makeDictionaryTypedSpecialAttribute(
return DictionaryTypedSpecialAttribute{std::move(name), std::move(expression), DataTypeFactory::instance().get(type_name)};
}
std::optional<AttributeUnderlyingType> maybeGetAttributeUnderlyingType(TypeIndex index)
std::optional<AttributeUnderlyingType> tryGetAttributeUnderlyingType(TypeIndex index)
{
switch (index) /// Special cases which do not map TypeIndex::T -> AttributeUnderlyingType::T
{
case TypeIndex::Date: return AttributeUnderlyingType::UInt16;
case TypeIndex::Date32: return AttributeUnderlyingType::Int32;
case TypeIndex::DateTime: return AttributeUnderlyingType::UInt32;
case TypeIndex::DateTime64: return AttributeUnderlyingType::UInt64;
case TypeIndex::DateTime64: return AttributeUnderlyingType::Int64;
default: break;
}
@ -296,7 +300,7 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
auto non_nullable_type = removeNullable(initial_type);
const auto underlying_type_opt = maybeGetAttributeUnderlyingType(non_nullable_type->getTypeId());
const auto underlying_type_opt = tryGetAttributeUnderlyingType(non_nullable_type->getTypeId());
if (!underlying_type_opt)
throw Exception(ErrorCodes::UNKNOWN_TYPE,

View File

@ -0,0 +1,2 @@
0 2019-05-05
2019-05-05

View File

@ -0,0 +1,24 @@
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table
(
id UInt64,
value Date32
) ENGINE=TinyLog;
INSERT INTO test_table VALUES (0, toDate32('2019-05-05'));
DROP DICTIONARY IF EXISTS test_dictionary;
CREATE DICTIONARY test_dictionary
(
id UInt64,
value Date32
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(TABLE 'test_table'))
LAYOUT(DIRECT());
SELECT * FROM test_dictionary;
SELECT dictGet('test_dictionary', 'value', toUInt64(0));
DROP DICTIONARY test_dictionary;
DROP TABLE test_table;