Skip to content

Commit

Permalink
init nested value for nullable column for function TiDBCast, `TiDBT…
Browse files Browse the repository at this point in the history
…imestampDiff` and `TiDBDateDiff` (#2289) (#2291)
  • Loading branch information
ti-srebot authored Jul 1, 2021
1 parent 332467d commit 0194cb4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
9 changes: 9 additions & 0 deletions dbms/src/Columns/ColumnDecimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class DecimalPaddedPODArray : public PaddedPODArray<T>
scale(scale_)
{}

DecimalPaddedPODArray(size_t size, const T & x, UInt32 scale_)
: Base(size, x),
scale(scale_)
{}

DecimalPaddedPODArray(const DecimalPaddedPODArray & other)
: Base(other.begin(), other.end()),
scale(other.scale)
Expand Down Expand Up @@ -73,6 +78,10 @@ class ColumnDecimal final : public COWPtrHelper<ColumnVectorHelper, ColumnDecima
: data(n, scale_),
scale(scale_)
{}
ColumnDecimal(const size_t n, const T & x, UInt32 scale_)
: data(n, x, scale_),
scale(scale_)
{}

ColumnDecimal(const ColumnDecimal & src)
: data(src.data),
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Functions/FunctionsDateTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@ class FunctionTiDBTimestampDiff : public IFunction
const IColumn & y = *y_p;

size_t rows = block.rows();
auto res = ColumnInt64::create(rows);
auto result_null_map = ColumnUInt8::create(rows);
auto res = ColumnInt64::create(rows, 0);
auto result_null_map = ColumnUInt8::create(rows, 0);
if (unit == "year")
dispatchForColumns<MonthDiffCalculatorImpl, YearDiffResultCalculator>(x, y, res->getData(), result_null_map->getData());
else if (unit == "quarter")
Expand Down Expand Up @@ -1720,8 +1720,8 @@ class FunctionTiDBDateDiff : public IFunction
const IColumn & y = *y_p;

size_t rows = block.rows();
auto res = ColumnInt64::create(rows);
auto result_null_map = ColumnUInt8::create(rows);
auto res = ColumnInt64::create(rows, 0);
auto result_null_map = ColumnUInt8::create(rows, 0);

dispatch(x, y, res->getData(), result_null_map->getData());

Expand Down
12 changes: 4 additions & 8 deletions dbms/src/Functions/FunctionsTiDBConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,8 @@ struct TiDBConvertToInteger
{
size_t size = block.getByPosition(arguments[0]).column->size();

auto col_to = ColumnVector<ToFieldType>::create();
auto col_to = ColumnVector<ToFieldType>::create(size, 0);
typename ColumnVector<ToFieldType>::Container & vec_to = col_to->getData();
vec_to.resize(size);

ColumnUInt8::MutablePtr col_null_map_to;
ColumnUInt8::Container * vec_null_map_to [[maybe_unused]] = nullptr;
Expand Down Expand Up @@ -684,9 +683,8 @@ struct TiDBConvertToFloat
size_t size = block.getByPosition(arguments[0]).column->size();

/// NOTICE: Since ToFieldType only can be Float32 or Float64, convert from_value to Float64 and then implicitly cast to ToFieldType is fine.
auto col_to = ColumnVector<ToFieldType>::create();
auto col_to = ColumnVector<ToFieldType>::create(size, 0);
typename ColumnVector<ToFieldType>::Container & vec_to = col_to->getData();
vec_to.resize(size);

ColumnUInt8::MutablePtr col_null_map_to;
ColumnUInt8::Container * vec_null_map_to [[maybe_unused]] = nullptr;
Expand Down Expand Up @@ -1096,9 +1094,8 @@ struct TiDBConvertToDecimal
bool, const tipb::FieldType &, const Context & context)
{
size_t size = block.getByPosition(arguments[0]).column->size();
auto col_to = ColumnDecimal<ToFieldType>::create(0, scale);
auto col_to = ColumnDecimal<ToFieldType>::create(size, static_cast<ToFieldType>(0), scale);
typename ColumnDecimal<ToFieldType>::Container & vec_to = col_to->getData();
vec_to.resize(size);

ColumnUInt8::MutablePtr col_null_map_to;
ColumnUInt8::Container * vec_null_map_to [[maybe_unused]] = nullptr;
Expand Down Expand Up @@ -1193,9 +1190,8 @@ struct TiDBConvertToTime
Block & block, const ColumnNumbers & arguments, size_t result, bool, const tipb::FieldType &, const Context & context)
{
size_t size = block.getByPosition(arguments[0]).column->size();
auto col_to = ColumnUInt64::create();
auto col_to = ColumnUInt64::create(size, 0);
ColumnUInt64::Container & vec_to = col_to->getData();
vec_to.resize(size);

ColumnUInt8::MutablePtr col_null_map_to;
ColumnUInt8::Container * vec_null_map_to [[maybe_unused]] = nullptr;
Expand Down

0 comments on commit 0194cb4

Please sign in to comment.