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

Fix some implicit Field casts #8209

Merged
merged 2 commits into from
Dec 17, 2019
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/Columns/ColumnUnique.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ size_t ColumnUnique<ColumnType>::uniqueInsert(const Field & x)
return getNullValueIndex();

if (size_of_value_if_fixed)
return uniqueInsertData(&x.get<char>(), size_of_value_if_fixed);
return uniqueInsertData(&x.reinterpret<char>(), size_of_value_if_fixed);

auto & val = x.get<String>();
return uniqueInsertData(val.data(), val.size());
Expand Down
14 changes: 12 additions & 2 deletions dbms/src/Functions/IFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ ColumnPtr wrapInNullable(const ColumnPtr & src, const Block & block, const Colum

/// Const Nullable that are NULL.
if (elem.column->onlyNull())
return block.getByPosition(result).type->createColumnConst(input_rows_count, Null());
{
auto result_type = block.getByPosition(result).type;
assert(result_type->isNullable());
return result_type->createColumnConstWithDefaultValue(input_rows_count);
}

if (isColumnConst(*elem.column))
continue;
Expand Down Expand Up @@ -281,7 +285,13 @@ bool ExecutableFunctionAdaptor::defaultImplementationForNulls(

if (null_presence.has_null_constant)
{
block.getByPosition(result).column = block.getByPosition(result).type->createColumnConst(input_rows_count, Null());
auto & result_column = block.getByPosition(result).column;
auto result_type = block.getByPosition(result).type;
// Default implementation for nulls returns null result for null arguments,
// so the result type must be nullable.
assert(result_type->isNullable());

result_column = result_type->createColumnConstWithDefaultValue(input_rows_count);
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions dbms/src/Functions/now64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ErrorCodes
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}

DateTime64::NativeType nowSubsecond(UInt32 scale)
static Field nowSubsecond(UInt32 scale)
{
const Int32 fractional_scale = 9;
timespec spec;
Expand All @@ -36,7 +36,8 @@ DateTime64::NativeType nowSubsecond(UInt32 scale)
else if (adjust_scale > 0)
components.fractional /= intExp10(adjust_scale);

return DecimalUtils::decimalFromComponents<DateTime64>(components, scale).value;
return DecimalField(DecimalUtils::decimalFromComponents<DateTime64>(components, scale),
scale);
}

class FunctionNow64 : public IFunction
Expand Down
10 changes: 7 additions & 3 deletions dbms/src/Functions/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,11 @@ class FunctionTransform : public IFunction
table_num_to_num = std::make_unique<NumToNum>();
auto & table = *table_num_to_num;
for (size_t i = 0; i < size; ++i)
table[from[i].get<UInt64>()] = (*used_to)[i].get<UInt64>();
{
// Field may be of Float type, but for the purpose of bitwise
// equality we can treat them as UInt64, hence the reinterpret().
table[from[i].reinterpret<UInt64>()] = (*used_to)[i].reinterpret<UInt64>();
}
}
else if (from[0].getType() != Field::Types::String && to[0].getType() == Field::Types::String)
{
Expand All @@ -806,7 +810,7 @@ class FunctionTransform : public IFunction
{
const String & str_to = to[i].get<const String &>();
StringRef ref{string_pool.insert(str_to.data(), str_to.size() + 1), str_to.size() + 1};
table[from[i].get<UInt64>()] = ref;
table[from[i].reinterpret<UInt64>()] = ref;
}
}
else if (from[0].getType() == Field::Types::String && to[0].getType() != Field::Types::String)
Expand All @@ -817,7 +821,7 @@ class FunctionTransform : public IFunction
{
const String & str_from = from[i].get<const String &>();
StringRef ref{string_pool.insert(str_from.data(), str_from.size() + 1), str_from.size() + 1};
table[ref] = (*used_to)[i].get<UInt64>();
table[ref] = (*used_to)[i].reinterpret<UInt64>();
}
}
else if (from[0].getType() == Field::Types::String && to[0].getType() == Field::Types::String)
Expand Down