2017-07-21 06:35:58 +00:00
|
|
|
#include <Functions/FunctionHelpers.h>
|
|
|
|
#include <Columns/ColumnTuple.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <Columns/ColumnFixedString.h>
|
2017-07-24 01:00:31 +00:00
|
|
|
#include <Columns/ColumnNullable.h>
|
|
|
|
#include <DataTypes/DataTypeNullable.h>
|
2017-09-26 15:25:24 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include "FunctionsArithmetic.h"
|
2017-07-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
const ColumnConst * checkAndGetColumnConstStringOrFixedString(const IColumn * column)
|
|
|
|
{
|
2017-12-09 10:14:45 +00:00
|
|
|
if (!column->isColumnConst())
|
2017-07-21 06:35:58 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
const ColumnConst * res = static_cast<const ColumnConst *>(column);
|
|
|
|
|
|
|
|
if (checkColumn<ColumnString>(&res->getDataColumn())
|
|
|
|
|| checkColumn<ColumnFixedString>(&res->getDataColumn()))
|
|
|
|
return res;
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-07-24 01:00:31 +00:00
|
|
|
|
2017-12-09 12:23:09 +00:00
|
|
|
Columns convertConstTupleToConstantElements(const ColumnConst & column)
|
2017-07-21 06:35:58 +00:00
|
|
|
{
|
|
|
|
const ColumnTuple & src_tuple = static_cast<const ColumnTuple &>(column.getDataColumn());
|
2017-12-08 00:50:25 +00:00
|
|
|
const Columns & src_tuple_columns = src_tuple.getColumns();
|
|
|
|
size_t tuple_size = src_tuple_columns.size();
|
|
|
|
size_t rows = column.size();
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2017-12-09 12:23:09 +00:00
|
|
|
Columns res(tuple_size);
|
2017-12-08 00:50:25 +00:00
|
|
|
for (size_t i = 0; i < tuple_size; ++i)
|
2017-12-14 01:43:19 +00:00
|
|
|
res[i] = ColumnConst::create(src_tuple_columns[i], rows);
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2017-12-09 12:23:09 +00:00
|
|
|
return res;
|
2017-07-21 06:35:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-24 01:00:31 +00:00
|
|
|
|
|
|
|
Block createBlockWithNestedColumns(const Block & block, ColumnNumbers args)
|
|
|
|
{
|
|
|
|
std::sort(args.begin(), args.end());
|
|
|
|
|
|
|
|
Block res;
|
2017-12-09 13:12:54 +00:00
|
|
|
size_t rows = block.rows();
|
|
|
|
size_t columns = block.columns();
|
2017-07-24 01:00:31 +00:00
|
|
|
|
|
|
|
size_t j = 0;
|
2017-12-09 12:23:09 +00:00
|
|
|
for (size_t i = 0; i < columns; ++i)
|
2017-07-24 01:00:31 +00:00
|
|
|
{
|
|
|
|
const auto & col = block.getByPosition(i);
|
|
|
|
bool is_inserted = false;
|
|
|
|
|
|
|
|
if ((j < args.size()) && (i == args[j]))
|
|
|
|
{
|
|
|
|
++j;
|
|
|
|
|
2017-12-09 12:23:09 +00:00
|
|
|
if (col.type->isNullable())
|
2017-07-24 01:00:31 +00:00
|
|
|
{
|
2017-12-09 13:12:54 +00:00
|
|
|
const DataTypePtr & nested_type = static_cast<const DataTypeNullable &>(*col.type).getNestedType();
|
2017-12-09 12:23:09 +00:00
|
|
|
|
|
|
|
if (!col.column)
|
|
|
|
{
|
|
|
|
res.insert(i, {nullptr, nested_type, col.name});
|
|
|
|
is_inserted = true;
|
|
|
|
}
|
|
|
|
else if (col.column->isColumnNullable())
|
|
|
|
{
|
|
|
|
const auto & nested_col = static_cast<const ColumnNullable &>(*col.column).getNestedColumn();
|
|
|
|
|
|
|
|
res.insert(i, {nested_col, nested_type, col.name});
|
|
|
|
is_inserted = true;
|
|
|
|
}
|
|
|
|
else if (col.column->isColumnConst())
|
|
|
|
{
|
|
|
|
const auto & nested_col = static_cast<const ColumnNullable &>(
|
|
|
|
static_cast<const ColumnConst &>(*col.column).getDataColumn()).getNestedColumn();
|
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
res.insert(i, { ColumnConst::create(nested_col, rows), nested_type, col.name});
|
2017-12-09 12:23:09 +00:00
|
|
|
is_inserted = true;
|
|
|
|
}
|
2017-07-24 01:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_inserted)
|
|
|
|
res.insert(i, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Block createBlockWithNestedColumns(const Block & block, ColumnNumbers args, size_t result)
|
|
|
|
{
|
2017-12-09 12:23:09 +00:00
|
|
|
args.push_back(result);
|
|
|
|
return createBlockWithNestedColumns(block, args);
|
2017-07-24 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
}
|