Skip to content

Commit

Permalink
remove obsolete parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtizJ committed Mar 28, 2022
1 parent bbfe8a2 commit 6cbdc6a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/DataTypes/DataTypeLowCardinalityHelpers.cpp
Expand Up @@ -36,7 +36,7 @@ DataTypePtr recursiveRemoveLowCardinality(const DataTypePtr & type)
element = recursiveRemoveLowCardinality(element);

if (tuple_type->haveExplicitNames())
return std::make_shared<DataTypeTuple>(elements, tuple_type->getElementNames(), tuple_type->serializeNames());
return std::make_shared<DataTypeTuple>(elements, tuple_type->getElementNames());
else
return std::make_shared<DataTypeTuple>(elements);
}
Expand Down
21 changes: 7 additions & 14 deletions src/DataTypes/DataTypeTuple.cpp
Expand Up @@ -64,8 +64,8 @@ static std::optional<Exception> checkTupleNames(const Strings & names)
return {};
}

DataTypeTuple::DataTypeTuple(const DataTypes & elems_, const Strings & names_, bool serialize_names_)
: elems(elems_), names(names_), have_explicit_names(true), serialize_names(serialize_names_)
DataTypeTuple::DataTypeTuple(const DataTypes & elems_, const Strings & names_)
: elems(elems_), names(names_), have_explicit_names(true)
{
size_t size = elems.size();
if (names.size() != size)
Expand All @@ -75,11 +75,6 @@ DataTypeTuple::DataTypeTuple(const DataTypes & elems_, const Strings & names_, b
throw std::move(*exception);
}

bool DataTypeTuple::canBeCreatedWithNames(const Strings & names)
{
return checkTupleNames(names) == std::nullopt;
}

std::string DataTypeTuple::doGetName() const
{
size_t size = elems.size();
Expand All @@ -91,7 +86,7 @@ std::string DataTypeTuple::doGetName() const
if (i != 0)
s << ", ";

if (have_explicit_names && serialize_names)
if (have_explicit_names)
s << backQuoteIfNeed(names[i]) << ' ';

s << elems[i]->getName();
Expand Down Expand Up @@ -265,31 +260,29 @@ size_t DataTypeTuple::getSizeOfValueInMemory() const
SerializationPtr DataTypeTuple::doGetDefaultSerialization() const
{
SerializationTuple::ElementSerializations serializations(elems.size());
bool use_explicit_names = have_explicit_names && serialize_names;
for (size_t i = 0; i < elems.size(); ++i)
{
String elem_name = use_explicit_names ? names[i] : toString(i + 1);
String elem_name = have_explicit_names ? names[i] : toString(i + 1);
auto serialization = elems[i]->getDefaultSerialization();
serializations[i] = std::make_shared<SerializationNamed>(serialization, elem_name);
}

return std::make_shared<SerializationTuple>(std::move(serializations), use_explicit_names);
return std::make_shared<SerializationTuple>(std::move(serializations), have_explicit_names);
}

SerializationPtr DataTypeTuple::getSerialization(const SerializationInfo & info) const
{
SerializationTuple::ElementSerializations serializations(elems.size());
const auto & info_tuple = assert_cast<const SerializationInfoTuple &>(info);
bool use_explicit_names = have_explicit_names && serialize_names;

for (size_t i = 0; i < elems.size(); ++i)
{
String elem_name = use_explicit_names ? names[i] : toString(i + 1);
String elem_name = have_explicit_names ? names[i] : toString(i + 1);
auto serialization = elems[i]->getSerialization(*info_tuple.getElementInfo(i));
serializations[i] = std::make_shared<SerializationNamed>(serialization, elem_name);
}

return std::make_shared<SerializationTuple>(std::move(serializations), use_explicit_names);
return std::make_shared<SerializationTuple>(std::move(serializations), have_explicit_names);
}

MutableSerializationInfoPtr DataTypeTuple::createSerializationInfo(const SerializationInfo::Settings & settings) const
Expand Down
6 changes: 1 addition & 5 deletions src/DataTypes/DataTypeTuple.h
Expand Up @@ -22,14 +22,11 @@ class DataTypeTuple final : public IDataType
DataTypes elems;
Strings names;
bool have_explicit_names;
bool serialize_names = true;
public:
static constexpr bool is_parametric = true;

explicit DataTypeTuple(const DataTypes & elems);
DataTypeTuple(const DataTypes & elems, const Strings & names, bool serialize_names_ = true);

static bool canBeCreatedWithNames(const Strings & names);
DataTypeTuple(const DataTypes & elems, const Strings & names);

TypeIndex getTypeId() const override { return TypeIndex::Tuple; }
std::string doGetName() const override;
Expand Down Expand Up @@ -66,7 +63,6 @@ class DataTypeTuple final : public IDataType
String getNameByPosition(size_t i) const;

bool haveExplicitNames() const { return have_explicit_names; }
bool serializeNames() const { return serialize_names; }
};

}
Expand Down
3 changes: 1 addition & 2 deletions src/Functions/FunctionsConversion.h
Expand Up @@ -2957,8 +2957,7 @@ class FunctionCast final : public FunctionCastBase
/// For named tuples allow conversions for tuples with
/// different sets of elements. If element exists in @to_type
/// and doesn't exist in @to_type it will be filled by default values.
if (from_type->haveExplicitNames() && from_type->serializeNames()
&& to_type->haveExplicitNames() && to_type->serializeNames())
if (from_type->haveExplicitNames() && to_type->haveExplicitNames())
{
const auto & from_names = from_type->getElementNames();
std::unordered_map<String, size_t> from_positions;
Expand Down
21 changes: 2 additions & 19 deletions src/Functions/tuple.cpp
Expand Up @@ -54,29 +54,12 @@ class FunctionTuple : public IFunction
bool useDefaultImplementationForNulls() const override { return false; }
bool useDefaultImplementationForConstants() const override { return true; }

DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.empty())
throw Exception("Function " + getName() + " requires at least one argument.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

DataTypes types;
Strings names;

for (const auto & argument : arguments)
{
types.emplace_back(argument.type);
names.emplace_back(argument.name);
}

/// Create named tuple if possible. We don't print tuple element names
/// because they are bad anyway -- aliases are not used, e.g. tuple(1 a)
/// will have element name '1' and not 'a'. If we ever change this, and
/// add the ability to access tuple elements by name, like tuple(1 a).a,
/// we should probably enable printing for better discoverability.
if (DataTypeTuple::canBeCreatedWithNames(names))
return std::make_shared<DataTypeTuple>(types, names, false /*print names*/);

return std::make_shared<DataTypeTuple>(types);
return std::make_shared<DataTypeTuple>(arguments);
}

ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override
Expand Down
Expand Up @@ -4,7 +4,7 @@ DROP TABLE IF EXISTS test02008;
CREATE TABLE test02008 (
col Tuple(
a Tuple(key1 int, key2 int),
b Tuple(key1 int, key3 int)
b Tuple(key1 int, key2 int)
)
) ENGINE=Memory();
INSERT INTO test02008 VALUES (tuple(tuple(1, 2), tuple(3, 4)));
Expand Down

0 comments on commit 6cbdc6a

Please sign in to comment.