Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Keep alias type name to metadata" #9594

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbms/src/DataTypes/DataTypeAggregateFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ bool DataTypeAggregateFunction::equals(const IDataType & rhs) const
}


static DataTypePtr create(const String & /*type_name*/, const ASTPtr & arguments)
static DataTypePtr create(const ASTPtr & arguments)
{
String function_name;
AggregateFunctionPtr function;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/DataTypes/DataTypeArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ size_t DataTypeArray::getNumberOfDimensions() const
}


static DataTypePtr create(const String & /*type_name*/, const ASTPtr & arguments)
static DataTypePtr create(const ASTPtr & arguments)
{
if (!arguments || arguments->children.size() != 1)
throw Exception("Array data type family must have exactly one argument - type of elements", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/DataTypes/DataTypeCustomIPv4AndIPv6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ class DataTypeCustomIPv6Serialization : public DataTypeCustomSimpleTextSerializa

void registerDataTypeDomainIPv4AndIPv6(DataTypeFactory & factory)
{
factory.registerSimpleDataTypeCustom("IPv4", [&](const String & /*type_name*/)
factory.registerSimpleDataTypeCustom("IPv4", []
{
return std::make_pair(DataTypeFactory::instance().get("UInt32"),
std::make_unique<DataTypeCustomDesc>(std::make_unique<DataTypeCustomFixedName>("IPv4"), std::make_unique<DataTypeCustomIPv4Serialization>()));
});

factory.registerSimpleDataTypeCustom("IPv6", [&](const String & /*type_name*/)
factory.registerSimpleDataTypeCustom("IPv6", []
{
return std::make_pair(DataTypeFactory::instance().get("FixedString(16)"),
std::make_unique<DataTypeCustomDesc>(std::make_unique<DataTypeCustomFixedName>("IPv6"), std::make_unique<DataTypeCustomIPv6Serialization>()));
std::make_unique<DataTypeCustomDesc>(std::make_unique<DataTypeCustomFixedName>("IPv6"), std::make_unique<DataTypeCustomIPv6Serialization>()));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ String DataTypeCustomSimpleAggregateFunction::getName() const
}


static std::pair<DataTypePtr, DataTypeCustomDescPtr> create(const String & /*type_name*/, const ASTPtr & arguments)
static std::pair<DataTypePtr, DataTypeCustomDescPtr> create(const ASTPtr & arguments)
{
String function_name;
AggregateFunctionPtr function;
Expand Down
7 changes: 1 addition & 6 deletions dbms/src/DataTypes/DataTypeDate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ bool DataTypeDate::equals(const IDataType & rhs) const

void registerDataTypeDate(DataTypeFactory & factory)
{
const auto & creator = [&](const String & /*type_name*/)
{
return DataTypePtr(std::make_shared<DataTypeDate>());
};

factory.registerSimpleDataType("Date", creator, DataTypeFactory::CaseInsensitive);
factory.registerSimpleDataType("Date", [] { return DataTypePtr(std::make_shared<DataTypeDate>()); }, DataTypeFactory::CaseInsensitive);
}

}
14 changes: 7 additions & 7 deletions dbms/src/DataTypes/DataTypeDateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ TimezoneMixin::TimezoneMixin(const String & time_zone_name)
utc_time_zone(DateLUT::instance("UTC"))
{}

DataTypeDateTime::DataTypeDateTime(const String & time_zone_name, const String & type_name_)
: TimezoneMixin(time_zone_name), type_name(type_name_)
DataTypeDateTime::DataTypeDateTime(const String & time_zone_name)
: TimezoneMixin(time_zone_name)
{
}

Expand All @@ -55,10 +55,10 @@ DataTypeDateTime::DataTypeDateTime(const TimezoneMixin & time_zone_)
String DataTypeDateTime::doGetName() const
{
if (!has_explicit_time_zone)
return type_name;
return "DateTime";

WriteBufferFromOwnString out;
out << type_name << "(" << quote << time_zone.getTimeZone() << ")";
out << "DateTime(" << quote << time_zone.getTimeZone() << ")";
return out.str();
}

Expand Down Expand Up @@ -194,10 +194,10 @@ namespace ErrorCodes
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}

static DataTypePtr create(const String & type_name, const ASTPtr & arguments)
static DataTypePtr create(const ASTPtr & arguments)
{
if (!arguments)
return std::make_shared<DataTypeDateTime>("", type_name);
return std::make_shared<DataTypeDateTime>();

if (arguments->children.size() != 1)
throw Exception("DateTime data type can optionally have only one argument - time zone name", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
Expand All @@ -206,7 +206,7 @@ static DataTypePtr create(const String & type_name, const ASTPtr & arguments)
if (!arg || arg->value.getType() != Field::Types::String)
throw Exception("Parameter for DateTime data type must be string literal", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

return std::make_shared<DataTypeDateTime>(arg->value.get<String>(), type_name);
return std::make_shared<DataTypeDateTime>(arg->value.get<String>());
}

void registerDataTypeDateTime(DataTypeFactory & factory)
Expand Down
4 changes: 1 addition & 3 deletions dbms/src/DataTypes/DataTypeDateTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TimezoneMixin
class DataTypeDateTime final : public DataTypeNumberBase<UInt32>, public TimezoneMixin
{
public:
explicit DataTypeDateTime(const String & time_zone_name = "", const String & type_name_ = "DateTime");
explicit DataTypeDateTime(const String & time_zone_name = "");
explicit DataTypeDateTime(const TimezoneMixin & time_zone);

static constexpr auto family_name = "DateTime";
Expand All @@ -75,8 +75,6 @@ class DataTypeDateTime final : public DataTypeNumberBase<UInt32>, public Timezon
bool canBeInsideNullable() const override { return true; }

bool equals(const IDataType & rhs) const override;
private:
const String type_name;
};

}
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/DataTypes/DataTypeDateTime64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ getArgument(const ASTPtr & arguments, size_t argument_index, const char * argume
return argument->value.get<NearestResultType>();
}

static DataTypePtr create64(const String & /*type_name*/, const ASTPtr & arguments)
static DataTypePtr create64(const ASTPtr & arguments)
{
if (!arguments || arguments->size() == 0)
return std::make_shared<DataTypeDateTime64>(DataTypeDateTime64::default_scale);
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/DataTypes/DataTypeDecimalBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const DecimalType<U> decimalResultType(const DataTypeNumber<T> &, const DecimalT
}

template <template <typename> typename DecimalType>
DataTypePtr createDecimal(UInt64 precision_value, UInt64 scale_value, const String & type_name = "Decimal", bool only_scale = false)
DataTypePtr createDecimal(UInt64 precision_value, UInt64 scale_value)
{
if (precision_value < DecimalUtils::minPrecision() || precision_value > DecimalUtils::maxPrecision<Decimal128>())
throw Exception("Wrong precision", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
Expand All @@ -202,10 +202,10 @@ DataTypePtr createDecimal(UInt64 precision_value, UInt64 scale_value, const Stri
throw Exception("Negative scales and scales larger than precision are not supported", ErrorCodes::ARGUMENT_OUT_OF_BOUND);

if (precision_value <= DecimalUtils::maxPrecision<Decimal32>())
return std::make_shared<DecimalType<Decimal32>>(precision_value, scale_value, type_name, only_scale);
return std::make_shared<DecimalType<Decimal32>>(precision_value, scale_value);
else if (precision_value <= DecimalUtils::maxPrecision<Decimal64>())
return std::make_shared<DecimalType<Decimal64>>(precision_value, scale_value, type_name, only_scale);
return std::make_shared<DecimalType<Decimal128>>(precision_value, scale_value, type_name, only_scale);
return std::make_shared<DecimalType<Decimal64>>(precision_value, scale_value);
return std::make_shared<DecimalType<Decimal128>>(precision_value, scale_value);
}

}
8 changes: 4 additions & 4 deletions dbms/src/DataTypes/DataTypeEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ static void checkASTStructure(const ASTPtr & child)
}

template <typename DataTypeEnum>
static DataTypePtr createExact(const String & /*type_name*/, const ASTPtr & arguments)
static DataTypePtr createExact(const ASTPtr & arguments)
{
if (!arguments || arguments->children.empty())
throw Exception("Enum data type cannot be empty", ErrorCodes::EMPTY_DATA_PASSED);
Expand Down Expand Up @@ -404,7 +404,7 @@ static DataTypePtr createExact(const String & /*type_name*/, const ASTPtr & argu
return std::make_shared<DataTypeEnum>(values);
}

static DataTypePtr create(const String & type_name, const ASTPtr & arguments)
static DataTypePtr create(const ASTPtr & arguments)
{
if (!arguments || arguments->children.empty())
throw Exception("Enum data type cannot be empty", ErrorCodes::EMPTY_DATA_PASSED);
Expand All @@ -425,10 +425,10 @@ static DataTypePtr create(const String & type_name, const ASTPtr & arguments)
Int64 value = value_literal->value.get<Int64>();

if (value > std::numeric_limits<Int8>::max() || value < std::numeric_limits<Int8>::min())
return createExact<DataTypeEnum16>(type_name, arguments);
return createExact<DataTypeEnum16>(arguments);
}

return createExact<DataTypeEnum8>(type_name, arguments);
return createExact<DataTypeEnum8>(arguments);
}

void registerDataTypeEnum(DataTypeFactory & factory)
Expand Down
16 changes: 8 additions & 8 deletions dbms/src/DataTypes/DataTypeFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ DataTypePtr DataTypeFactory::get(const String & family_name_param, const ASTPtr
return get("LowCardinality", low_cardinality_params);
}

return findCreatorByName(family_name)(family_name_param, parameters);
return findCreatorByName(family_name)(parameters);
}


Expand Down Expand Up @@ -107,30 +107,30 @@ void DataTypeFactory::registerSimpleDataType(const String & name, SimpleCreator
throw Exception("DataTypeFactory: the data type " + name + " has been provided "
" a null constructor", ErrorCodes::LOGICAL_ERROR);

registerDataType(name, [name, creator](const String & type_name, const ASTPtr & ast)
registerDataType(name, [name, creator](const ASTPtr & ast)
{
if (ast)
throw Exception("Data type " + name + " cannot have arguments", ErrorCodes::DATA_TYPE_CANNOT_HAVE_ARGUMENTS);
return creator(type_name);
return creator();
}, case_sensitiveness);
}

void DataTypeFactory::registerDataTypeCustom(const String & family_name, CreatorWithCustom creator, CaseSensitiveness case_sensitiveness)
{
registerDataType(family_name, [creator](const String & type_name, const ASTPtr & ast)
registerDataType(family_name, [creator](const ASTPtr & ast)
{
auto res = creator(type_name, ast);
auto res = creator(ast);
res.first->setCustomization(std::move(res.second));

return res.first;
}, case_sensitiveness);
}

void DataTypeFactory::registerSimpleDataTypeCustom(const String & name, SimpleCreatorWithCustom creator, CaseSensitiveness case_sensitiveness)
void DataTypeFactory::registerSimpleDataTypeCustom(const String &name, SimpleCreatorWithCustom creator, CaseSensitiveness case_sensitiveness)
{
registerDataTypeCustom(name, [creator](const String & type_name, const ASTPtr & /*ast*/)
registerDataTypeCustom(name, [creator](const ASTPtr & /*ast*/)
{
return creator(type_name);
return creator();
}, case_sensitiveness);
}

Expand Down
9 changes: 5 additions & 4 deletions dbms/src/DataTypes/DataTypeFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ namespace DB
class IDataType;
using DataTypePtr = std::shared_ptr<const IDataType>;


/** Creates a data type by name of data type family and parameters.
*/
class DataTypeFactory final : private boost::noncopyable, public IFactoryWithAliases<std::function<DataTypePtr(const String & type_name, const ASTPtr & parameters)>>
class DataTypeFactory final : private boost::noncopyable, public IFactoryWithAliases<std::function<DataTypePtr(const ASTPtr & parameters)>>
{
private:
using SimpleCreator = std::function<DataTypePtr(const String & type_name)>;
using SimpleCreator = std::function<DataTypePtr()>;
using DataTypesDictionary = std::unordered_map<String, Creator>;
using CreatorWithCustom = std::function<std::pair<DataTypePtr, DataTypeCustomDescPtr>(const String & type_name, const ASTPtr & parameters)>;
using SimpleCreatorWithCustom = std::function<std::pair<DataTypePtr, DataTypeCustomDescPtr>(const String & type_name)>;
using CreatorWithCustom = std::function<std::pair<DataTypePtr,DataTypeCustomDescPtr>(const ASTPtr & parameters)>;
using SimpleCreatorWithCustom = std::function<std::pair<DataTypePtr,DataTypeCustomDescPtr>()>;

public:
static DataTypeFactory & instance();
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/DataTypes/DataTypeFixedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace ErrorCodes

std::string DataTypeFixedString::doGetName() const
{
return type_name + "(" + toString(n) + ")";
return "FixedString(" + toString(n) + ")";
}


Expand Down Expand Up @@ -279,7 +279,7 @@ bool DataTypeFixedString::equals(const IDataType & rhs) const
}


static DataTypePtr create(const String & type_name, const ASTPtr & arguments)
static DataTypePtr create(const ASTPtr & arguments)
{
if (!arguments || arguments->children.size() != 1)
throw Exception("FixedString data type family must have exactly one argument - size in bytes", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
Expand All @@ -288,7 +288,7 @@ static DataTypePtr create(const String & type_name, const ASTPtr & arguments)
if (!argument || argument->value.getType() != Field::Types::UInt64 || argument->value.get<UInt64>() == 0)
throw Exception("FixedString data type family must have a number (positive integer) as its argument", ErrorCodes::UNEXPECTED_AST_STRUCTURE);

return std::make_shared<DataTypeFixedString>(argument->value.get<UInt64>(), type_name);
return std::make_shared<DataTypeFixedString>(argument->value.get<UInt64>());
}


Expand Down
5 changes: 1 addition & 4 deletions dbms/src/DataTypes/DataTypeFixedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DataTypeFixedString final : public IDataType
public:
static constexpr bool is_parametric = true;

DataTypeFixedString(size_t n_, const String & type_name_ = "FixedString") : n(n_), type_name(type_name_)
DataTypeFixedString(size_t n_) : n(n_)
{
if (n == 0)
throw Exception("FixedString size must be positive", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
Expand Down Expand Up @@ -85,9 +85,6 @@ class DataTypeFixedString final : public IDataType
bool isCategorial() const override { return true; }
bool canBeInsideNullable() const override { return true; }
bool canBeInsideLowCardinality() const override { return true; }

private:
const String type_name;
};

}
21 changes: 8 additions & 13 deletions dbms/src/DataTypes/DataTypeInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ bool DataTypeInterval::equals(const IDataType & rhs) const
return typeid(rhs) == typeid(*this) && kind == static_cast<const DataTypeInterval &>(rhs).kind;
}

template <IntervalKind::Kind kind>
static DataTypePtr create(const String & /*type_name*/)
{
return DataTypePtr(std::make_shared<DataTypeInterval>(kind));
}

void registerDataTypeInterval(DataTypeFactory & factory)
{
factory.registerSimpleDataType("IntervalSecond", create<IntervalKind::Second>);
factory.registerSimpleDataType("IntervalMinute", create<IntervalKind::Minute>);
factory.registerSimpleDataType("IntervalHour", create<IntervalKind::Hour>);
factory.registerSimpleDataType("IntervalDay", create<IntervalKind::Day>);
factory.registerSimpleDataType("IntervalWeek", create<IntervalKind::Week>);
factory.registerSimpleDataType("IntervalMonth", create<IntervalKind::Month>);
factory.registerSimpleDataType("IntervalQuarter", create<IntervalKind::Quarter>);
factory.registerSimpleDataType("IntervalYear", create<IntervalKind::Year>);
factory.registerSimpleDataType("IntervalSecond", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Second)); });
factory.registerSimpleDataType("IntervalMinute", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Minute)); });
factory.registerSimpleDataType("IntervalHour", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Hour)); });
factory.registerSimpleDataType("IntervalDay", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Day)); });
factory.registerSimpleDataType("IntervalWeek", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Week)); });
factory.registerSimpleDataType("IntervalMonth", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Month)); });
factory.registerSimpleDataType("IntervalQuarter", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Quarter)); });
factory.registerSimpleDataType("IntervalYear", [] { return DataTypePtr(std::make_shared<DataTypeInterval>(IntervalKind::Year)); });
}

}
2 changes: 1 addition & 1 deletion dbms/src/DataTypes/DataTypeLowCardinality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ bool DataTypeLowCardinality::equals(const IDataType & rhs) const
}


static DataTypePtr create(const String & /*type_name*/, const ASTPtr & arguments)
static DataTypePtr create(const ASTPtr & arguments)
{
if (!arguments || arguments->children.size() != 1)
throw Exception("LowCardinality data type family must have single argument - type of elements",
Expand Down
4 changes: 1 addition & 3 deletions dbms/src/DataTypes/DataTypeNothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ bool DataTypeNothing::equals(const IDataType & rhs) const

void registerDataTypeNothing(DataTypeFactory & factory)
{
const auto & creator = [&](const String & /*type_name*/) { return DataTypePtr(std::make_shared<DataTypeNothing>()); };

factory.registerSimpleDataType("Nothing", creator);
factory.registerSimpleDataType("Nothing", [] { return DataTypePtr(std::make_shared<DataTypeNothing>()); });
}

}
2 changes: 1 addition & 1 deletion dbms/src/DataTypes/DataTypeNullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ bool DataTypeNullable::equals(const IDataType & rhs) const
}


static DataTypePtr create(const String & /*type_name*/, const ASTPtr & arguments)
static DataTypePtr create(const ASTPtr & arguments)
{
if (!arguments || arguments->children.size() != 1)
throw Exception("Nullable data type family must have exactly one argument - nested type", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/DataTypes/DataTypeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ bool DataTypeString::equals(const IDataType & rhs) const

void registerDataTypeString(DataTypeFactory & factory)
{
const auto & creator = [&] (const String & type_name) { return std::make_shared<DataTypeString>(type_name); };
auto creator = static_cast<DataTypePtr(*)()>([] { return DataTypePtr(std::make_shared<DataTypeString>()); });

factory.registerSimpleDataType("String", creator);

Expand Down
7 changes: 0 additions & 7 deletions dbms/src/DataTypes/DataTypeString.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class DataTypeString final : public IDataType
using FieldType = String;
static constexpr bool is_parametric = false;

DataTypeString(const String & type_name_ = "String") : type_name(type_name_) {}

String doGetName() const override { return type_name; }

const char * getFamilyName() const override
{
return "String";
Expand Down Expand Up @@ -67,9 +63,6 @@ class DataTypeString final : public IDataType
bool isCategorial() const override { return true; }
bool canBeInsideNullable() const override { return true; }
bool canBeInsideLowCardinality() const override { return true; }

private:
const String type_name;
};

}