clickhouse: fixed bas_cast in ColumnConstArray (added nested type information) [#CONV-6788].

This commit is contained in:
Michael Kolupaev 2013-03-06 13:44:40 +00:00
parent a0de019a61
commit efed69fcc6
7 changed files with 27 additions and 18 deletions

View File

@ -7,6 +7,7 @@
#include <DB/Core/ErrorCodes.h>
#include <DB/Columns/ColumnVector.h>
#include <DB/Columns/IColumn.h>
#include <DB/DataTypes/IDataType.h>
namespace DB
@ -31,7 +32,9 @@ class ColumnConst : public IColumnConst
public:
typedef T Type;
ColumnConst(size_t s_, const T & data_) : s(s_), data(data_) {}
ColumnConst(size_t s_, const T & data_);
ColumnConst(size_t s_, const T & data_, DataTypePtr nested_type_);
std::string getName() const { return "ColumnConst<" + TypeName<T>::get() + ">"; }
bool isNumeric() const { return IsNumber<T>::value; }
@ -113,6 +116,7 @@ public:
private:
size_t s;
T data;
DataTypePtr nested_type; /// Только для массивов.
};
@ -120,6 +124,13 @@ typedef ColumnConst<String> ColumnConstString;
typedef ColumnConst<Array> ColumnConstArray;
template <typename T> ColumnConst<T>::ColumnConst(size_t s_, const T & data_) : s(s_), data(data_) {}
template <typename T> ColumnConst<T>::ColumnConst(size_t s_, const T & data_, DataTypePtr nested_type_) { throw Exception("Can't create non-array ColumnConst with nested type", ErrorCodes::LOGICAL_ERROR); }
template <> ColumnConst<Array>::ColumnConst(size_t s_, const Array & data_) { throw Exception("Can't create ColumnConst<Array> without nested type", ErrorCodes::LOGICAL_ERROR); }
template <> ColumnConst<Array>::ColumnConst(size_t s_, const Array & data_, DataTypePtr nested_type_) : s(s_), data(data_), nested_type(nested_type_) {}
template <typename T> ColumnPtr ColumnConst<T>::convertToFullColumn() const
{
ColumnVector<T> * res = new ColumnVector<T>;
@ -149,16 +160,16 @@ template <typename T> StringRef getDataAtImpl(size_t n, const T & data)
return StringRef(reinterpret_cast<const char *>(&data), sizeof(data));
}
template <> inline StringRef ColumnConst<UInt8 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<UInt8 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<UInt16 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<UInt32 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<UInt64 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int8 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int16 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int32 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int64 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Float32>::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Float64>::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int8 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int16 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int32 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Int64 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Float32 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
template <> inline StringRef ColumnConst<Float64 >::getDataAt(size_t n) const { return getDataAtImpl(n, data); }
}

View File

@ -54,7 +54,7 @@ public:
for (size_t i = 0, size = arguments.size(); i < size; ++i)
arr.push_back((*block.getByPosition(arguments[i]).column)[0]);
block.getByPosition(result).column = new ColumnConstArray(block.getByPosition(arguments[0]).column->size(), arr);
block.getByPosition(result).column = new ColumnConstArray(block.getByPosition(arguments[0]).column->size(), arr, block.getByPosition(arguments[0]).type);
}
};

View File

@ -436,7 +436,7 @@ public:
{
Array const_res;
TimeSlotsImpl<UInt32>::constant_constant(const_starts->getData(), const_durations->getData(), const_res);
block.getByPosition(result).column = new ColumnConstArray(block.getByPosition(0).column->size(), const_res);
block.getByPosition(result).column = new ColumnConstArray(block.getByPosition(0).column->size(), const_res, new DataTypeDateTime);
}
else
throw Exception("Illegal columns " + block.getByPosition(arguments[0]).column->getName()

View File

@ -334,7 +334,7 @@ public:
cur = Transform::toParent(cur, dict);
}
block.getByPosition(result).column = new ColumnConstArray(col_from->size(), res);
block.getByPosition(result).column = new ColumnConstArray(col_from->size(), res, new DataTypeFromFieldType<T>::Type);
}
else
throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName()

View File

@ -306,7 +306,7 @@ public:
while (generator.get(token_begin, token_end))
dst.push_back(String(token_begin, token_end - token_begin));
block.getByPosition(result).column = new ColumnConstArray(col_const_str->size(), dst);
block.getByPosition(result).column = new ColumnConstArray(col_const_str->size(), dst, new DataTypeString);
}
else
throw Exception("Illegal columns " + block.getByPosition(arguments.back()).column->getName()
@ -317,8 +317,8 @@ public:
};
typedef FunctionTokens<AlphaTokensImpl> FunctionAlphaTokens;
typedef FunctionTokens<SplitByCharImpl> FunctionSplitByChar;
typedef FunctionTokens<AlphaTokensImpl> FunctionAlphaTokens;
typedef FunctionTokens<SplitByCharImpl> FunctionSplitByChar;
typedef FunctionTokens<SplitByStringImpl> FunctionSplitByString;
}

View File

@ -32,9 +32,7 @@ template <> ColumnPtr ColumnConst<String>::convertToFullColumn() const
template <> ColumnPtr ColumnConst<Array>::convertToFullColumn() const
{
size_t array_size = data.size();
ColumnPtr nested_column = data.empty()
? new ColumnUInt8 /// Для пустого массива непонятно, какого типа будет материализованный столбец. Пусть будет UInt8.
: apply_visitor(FieldToDataType(), data.at(0))->createColumn();
ColumnPtr nested_column = nested_type->createColumn();
ColumnArray * res = new ColumnArray(nested_column);
ColumnArray::Offsets_t & offsets = res->getOffsets();

View File

@ -179,7 +179,7 @@ ColumnPtr DataTypeArray::createColumn() const
ColumnPtr DataTypeArray::createConstColumn(size_t size, const Field & field) const
{
return new ColumnConst<Array>(size, get<const Array &>(field));
return new ColumnConst<Array>(size, get<const Array &>(field), nested);
}
}