Clarifications [#CLICKHOUSE-2].

This commit is contained in:
Alexey Milovidov 2017-12-11 00:05:21 +03:00
parent cc895f4698
commit de75e40528
7 changed files with 23 additions and 38 deletions

View File

@ -321,19 +321,13 @@ bool ColumnArray::hasEqualOffsets(const ColumnArray & other) const
ColumnPtr ColumnArray::convertToFullColumnIfConst() const ColumnPtr ColumnArray::convertToFullColumnIfConst() const
{ {
ColumnPtr new_data; ColumnPtr new_data;
ColumnPtr new_offsets;
if (auto full_column = getData().convertToFullColumnIfConst()) if (auto full_column = getData().convertToFullColumnIfConst())
new_data = full_column; new_data = full_column;
else else
new_data = data; new_data = data;
if (auto full_column = offsets->convertToFullColumnIfConst()) return std::make_shared<ColumnArray>(new_data, offsets);
new_offsets = full_column;
else
new_offsets = offsets;
return std::make_shared<ColumnArray>(new_data, new_offsets);
} }

View File

@ -35,17 +35,6 @@ ColumnNullable::ColumnNullable(ColumnPtr nested_column_, ColumnPtr null_map_)
} }
ColumnPtr ColumnNullable::convertToFullColumnIfConst() const
{
ColumnPtr new_col_holder;
if (auto full_col = nested_column->convertToFullColumnIfConst())
new_col_holder = std::make_shared<ColumnNullable>(full_col, null_map);
return new_col_holder;
}
void ColumnNullable::updateHashWithValue(size_t n, SipHash & hash) const void ColumnNullable::updateHashWithValue(size_t n, SipHash & hash) const
{ {
const auto & arr = getNullMap(); const auto & arr = getNullMap();

View File

@ -53,7 +53,6 @@ public:
size_t byteSize() const override; size_t byteSize() const override;
size_t allocatedBytes() const override; size_t allocatedBytes() const override;
ColumnPtr replicate(const Offsets_t & replicate_offsets) const override; ColumnPtr replicate(const Offsets_t & replicate_offsets) const override;
ColumnPtr convertToFullColumnIfConst() const override;
void updateHashWithValue(size_t n, SipHash & hash) const override; void updateHashWithValue(size_t n, SipHash & hash) const override;
void getExtremes(Field & min, Field & max) const override; void getExtremes(Field & min, Field & max) const override;

View File

@ -284,18 +284,6 @@ size_t ColumnTuple::allocatedBytes() const
return res; return res;
} }
ColumnPtr ColumnTuple::convertToFullColumnIfConst() const
{
const size_t tuple_size = columns.size();
Columns new_columns(columns);
for (size_t i = 0; i < tuple_size; ++i)
if (auto converted = columns[i]->convertToFullColumnIfConst())
new_columns[i] = converted;
return std::make_shared<ColumnTuple>(new_columns);
}
void ColumnTuple::getExtremes(Field & min, Field & max) const void ColumnTuple::getExtremes(Field & min, Field & max) const
{ {
const size_t tuple_size = columns.size(); const size_t tuple_size = columns.size();

View File

@ -57,7 +57,6 @@ public:
void reserve(size_t n) override; void reserve(size_t n) override;
size_t byteSize() const override; size_t byteSize() const override;
size_t allocatedBytes() const override; size_t allocatedBytes() const override;
ColumnPtr convertToFullColumnIfConst() const override;
void forEachSubcolumn(ColumnCallback callback) override; void forEachSubcolumn(ColumnCallback callback) override;
const Columns & getColumns() const { return columns; } const Columns & getColumns() const { return columns; }

View File

@ -44,9 +44,6 @@ public:
/** If column isn't constant, returns nullptr (or itself). /** If column isn't constant, returns nullptr (or itself).
* If column is constant, transforms constant to full column (if column type allows such tranform) and return it. * If column is constant, transforms constant to full column (if column type allows such tranform) and return it.
* Special case:
* If column is composed from several other columns (tuple for example), and contains both constant and full columns,
* then each constant column is transformed, and final result is returned.
*/ */
virtual ColumnPtr convertToFullColumnIfConst() const { return {}; } virtual ColumnPtr convertToFullColumnIfConst() const { return {}; }
@ -245,8 +242,8 @@ public:
/// Zero, if could be determined. /// Zero, if could be determined.
virtual size_t allocatedBytes() const = 0; virtual size_t allocatedBytes() const = 0;
/// If the column contains subcolumns (such as Array, Nullable, etc), enumerate them. /// If the column contains subcolumns (such as Array, Nullable, etc), do callback on them.
/// Shallow: doesn't do recursive calls. /// Shallow: doesn't do recursive calls; don't do call for itself.
using ColumnCallback = std::function<void(ColumnPtr&)>; using ColumnCallback = std::function<void(ColumnPtr&)>;
virtual void forEachSubcolumn(ColumnCallback) {} virtual void forEachSubcolumn(ColumnCallback) {}
@ -270,6 +267,23 @@ public:
/// It's a special kind of column, that contain single value, but is not a ColumnConst. /// It's a special kind of column, that contain single value, but is not a ColumnConst.
virtual bool isDummy() const { return false; } virtual bool isDummy() const { return false; }
/** Memory layout properties.
*
* Each value of a column can be placed in memory contiguously or not.
*
* Example: simple columns like UInt64 or FixedString store their values contiguously in single memory buffer.
*
* Example: Tuple store values of each component in separate subcolumn, so the values of Tuples with at least two components are not contiguous.
* Another example is Nullable. Each value have null flag, that is stored separately, so the value is not contiguous in memory.
*
* There are some important cases, when values are not stored contiguously, but for each value, you can get contiguous memory segment,
* that will unambiguously identify the value. In this case, methods getDataAt and insertData are implemented.
* Example: String column: bytes of strings are stored concatenated in one memory buffer
* and offsets to that buffer are stored in another buffer. The same is for Array of fixed-size contiguous elements.
*
* To avoid confusion between these cases, we don't have isContiguous method.
*/
/// Values in column have fixed size (including the case when values span many memory segments). /// Values in column have fixed size (including the case when values span many memory segments).
virtual bool valuesHaveFixedSize() const { return isFixedAndContiguous(); } virtual bool valuesHaveFixedSize() const { return isFixedAndContiguous(); }
@ -293,6 +307,8 @@ public:
virtual ~IColumn() {} virtual ~IColumn() {}
/** Print column name, size, and recursively print all subcolumns.
*/
String dumpStructure() const; String dumpStructure() const;
protected: protected:

View File

@ -204,7 +204,7 @@ public:
/** Create constant column for corresponding type, with specified size and value. /** Create constant column for corresponding type, with specified size and value.
*/ */
virtual ColumnPtr createConstColumn(size_t size, const Field & field) const; ColumnPtr createConstColumn(size_t size, const Field & field) const;
/** Get default value of data type. /** Get default value of data type.
* It is the "default" default, regardless the fact that a table could contain different user-specified default. * It is the "default" default, regardless the fact that a table could contain different user-specified default.