Skip to content

Commit

Permalink
Avoid materialization for dictGetTOrDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
amosbird committed Nov 11, 2018
1 parent 92bc884 commit f76bfb0
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions dbms/src/Functions/FunctionsExternalDictionaries.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,17 @@ class FunctionDictGetStringOrDefault final : public IFunction
if (const auto default_col = checkAndGetColumn<ColumnString>(default_col_untyped))
{
/// const ids, vector defaults
/// @todo avoid materialization
const PaddedPODArray<UInt64> ids(id_col->size(), id_col->getValue<UInt64>());
auto out = ColumnString::create();
dictionary->getString(attr_name, ids, default_col, out.get());
block.getByPosition(result).column = std::move(out);
const PaddedPODArray<UInt64> ids(1, id_col->getValue<UInt64>());
PaddedPODArray<UInt8> flags(1);
dictionary->has(ids, flags);
if (flags.front())
{
auto out = ColumnString::create();
dictionary->getString(attr_name, ids, String(), out.get());
block.getByPosition(result).column = DataTypeString().createColumnConst(id_col->size(), out->getDataAt(0).toString());
}
else
block.getByPosition(result).column = block.getByPosition(arguments[3]).column; // reuse the default column
}
else if (const auto default_col = checkAndGetColumnConstStringOrFixedString(default_col_untyped))
{
Expand Down Expand Up @@ -1033,14 +1039,17 @@ class FunctionDictGetOrDefault final : public IFunction
if (const auto default_col = checkAndGetColumn<ColumnVector<Type>>(default_col_untyped))
{
/// const ids, vector defaults
/// @todo avoid materialization
const PaddedPODArray<UInt64> ids(id_col->size(), id_col->getValue<UInt64>());

auto out = ColumnVector<Type>::create(id_col->size());
auto & data = out->getData();
const auto & defs = default_col->getData();
DictGetTraits<DataType>::getOrDefault(dictionary, attr_name, ids, defs, data);
block.getByPosition(result).column = std::move(out);
const PaddedPODArray<UInt64> ids(1, id_col->getValue<UInt64>());
PaddedPODArray<UInt8> flags(1);
dictionary->has(ids, flags);
if (flags.front())
{
PaddedPODArray<Type> data(1);
DictGetTraits<DataType>::getOrDefault(dictionary, attr_name, ids, Type(), data);
block.getByPosition(result).column = DataTypeNumber<Type>().createColumnConst(id_col->size(), toField(data.front()));
}
else
block.getByPosition(result).column = block.getByPosition(arguments[3]).column; // reuse the default column
}
else if (const auto default_col = checkAndGetColumnConst<ColumnVector<Type>>(default_col_untyped))
{
Expand Down

0 comments on commit f76bfb0

Please sign in to comment.