Skip to content

Commit

Permalink
opt join
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinyhZou authored and liuneng1994 committed Mar 6, 2024
1 parent eccb1fb commit c3000d5
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 90 deletions.
5 changes: 5 additions & 0 deletions src/Columns/ColumnConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ class ColumnConst final : public COWHelper<IColumn, ColumnConst>
return data->isNullAt(0);
}

void insertIndicesFrom(const IColumn &, const Selector & selector) override
{
s += selector.size();
}

void insertRangeFrom(const IColumn &, size_t /*start*/, size_t length) override
{
s += length;
Expand Down
13 changes: 13 additions & 0 deletions src/Columns/ColumnDecimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@ void ColumnDecimal<T>::insertData(const char * src, size_t /*length*/)
data.emplace_back(tmp);
}

template <is_decimal T>
void ColumnDecimal<T>::insertIndicesFrom(const IColumn & src, const IColumn::Selector & selector)
{
size_t old_size = data.size();
data.resize(old_size + selector.size());
const ColumnDecimal & src_dec = assert_cast<const ColumnDecimal &>(src);
const Container & src_data = src_dec.getData();
for (size_t i = 0; i < selector.size(); i++)
{
data[old_size + i] = src_data[selector[i]];
}
}

template <is_decimal T>
void ColumnDecimal<T>::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
Expand Down
1 change: 1 addition & 0 deletions src/Columns/ColumnDecimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ColumnDecimal final : public COWHelper<ColumnVectorHelper, ColumnDecimal<T
void insertDefault() override { data.push_back(T()); }
void insertManyDefaults(size_t length) override { data.resize_fill(data.size() + length); }
void insert(const Field & x) override { data.push_back(x.get<T>()); }
void insertIndicesFrom(const IColumn & src, const IColumn::Selector & selector) override;
void insertRangeFrom(const IColumn & src, size_t start, size_t length) override;
void insertRangeSelective(const IColumn & src, const IColumn::Selector & selector, size_t selector_start, size_t length) override;

Expand Down
15 changes: 15 additions & 0 deletions src/Columns/ColumnNullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ const char * ColumnNullable::skipSerializedInArena(const char * pos) const
return pos;
}

void ColumnNullable::insertIndicesFrom(const IColumn & src, const Selector & selector)
{
const ColumnNullable & nullable_col = assert_cast<const ColumnNullable &>(src);
const IColumn & src_null_map = *nullable_col.null_map;
const IColumn & src_nested_column = *nullable_col.nested_column;
getNullMapColumn().insertIndicesFrom(src_null_map, selector);
getNestedColumn().insertIndicesFrom(src_nested_column, selector);
}

void ColumnNullable::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
const ColumnNullable & nullable_col = assert_cast<const ColumnNullable &>(src);
Expand Down Expand Up @@ -280,6 +289,12 @@ void ColumnNullable::insertFromNotNullable(const IColumn & src, size_t n)
getNullMapData().push_back(0);
}

void ColumnNullable::insertIndicesFromNotNullable(const IColumn & src, const IColumn::Selector & selector)
{
getNestedColumn().insertIndicesFrom(src, selector);
getNullMapColumn().insertMany(0, selector.size());
}

void ColumnNullable::insertRangeFromNotNullable(const IColumn & src, size_t start, size_t length)
{
getNestedColumn().insertRangeFrom(src, start, length);
Expand Down
2 changes: 2 additions & 0 deletions src/Columns/ColumnNullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable>
StringRef serializeValueIntoArena(size_t n, Arena & arena, char const *& begin, const UInt8 * null_bit) const override;
const char * deserializeAndInsertFromArena(const char * pos) override;
const char * skipSerializedInArena(const char * pos) const override;
void insertIndicesFrom(const IColumn & src, const Selector & selector) override;
void insertRangeFrom(const IColumn & src, size_t start, size_t length) override;
void insertRangeSelective(const IColumn & src, const IColumn::Selector & selector, size_t selector_start, size_t length) override;
void insert(const Field & x) override;
void insertFrom(const IColumn & src, size_t n) override;

void insertFromNotNullable(const IColumn & src, size_t n);
void insertIndicesFromNotNullable(const IColumn & src, const IColumn::Selector & selector);
void insertRangeFromNotNullable(const IColumn & src, size_t start, size_t length);
void insertManyFromNotNullable(const IColumn & src, size_t position, size_t length);

Expand Down
5 changes: 5 additions & 0 deletions src/Columns/ColumnString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ void ColumnString::updateWeakHash32(WeakHash32 & hash) const
}
}

void ColumnString::insertIndicesFrom(const IColumn & src, const Selector & selector)
{
for (auto sel : selector)
ColumnString::insertFrom(src, sel);
}

void ColumnString::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
Expand Down
1 change: 1 addition & 0 deletions src/Columns/ColumnString.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class ColumnString final : public COWHelper<IColumn, ColumnString>
hash.update(reinterpret_cast<const char *>(offsets.data()), offsets.size() * sizeof(offsets[0]));
hash.update(reinterpret_cast<const char *>(chars.data()), chars.size() * sizeof(chars[0]));
}
void insertIndicesFrom(const IColumn & src, const Selector & selector) override;

void insertRangeFrom(const IColumn & src, size_t start, size_t length) override;

Expand Down
13 changes: 13 additions & 0 deletions src/Columns/ColumnVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,19 @@ Float32 ColumnVector<T>::getFloat32(size_t n [[maybe_unused]]) const
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Cannot get the value of {} as Float32", TypeName<T>);
}

template <typename T>
void ColumnVector<T>::insertIndicesFrom(const IColumn & src, const IColumn::Selector & selector)
{
size_t old_size = data.size();
data.resize(old_size + selector.size());
const ColumnVector & src_vec = assert_cast<const ColumnVector &>(src);
const Container & src_data = src_vec.getData();
for (size_t i = 0; i < selector.size(); i++)
{
data[old_size + i] = src_data[selector[i]];
}
}

template <typename T>
void ColumnVector<T>::insertRangeFrom(const IColumn & src, size_t start, size_t length)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Columns/ColumnVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class ColumnVector final : public COWHelper<ColumnVectorHelper, ColumnVector<T>>
data.push_back(static_cast<T>(x.get<T>()));
}

void insertIndicesFrom(const IColumn & src, const IColumn::Selector & selector) override;

void insertRangeFrom(const IColumn & src, size_t start, size_t length) override;

ColumnPtr filter(const IColumn::Filter & filt, ssize_t result_size_hint) const override;
Expand Down
6 changes: 6 additions & 0 deletions src/Columns/IColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ void IColumn::insertFrom(const IColumn & src, size_t n)
insert(src[n]);
}

void IColumn::insertIndicesFrom(const IColumn & src, const Selector & selector)
{
for (auto sel : selector)
insertFrom(src, sel);
}

ColumnPtr IColumn::createWithOffsets(const Offsets & offsets, const ColumnConst & column_with_default_value, size_t total_rows, size_t shift) const
{
if (offsets.size() + shift != size())
Expand Down
1 change: 1 addition & 0 deletions src/Columns/IColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ class IColumn : public COW<IColumn>
using ColumnIndex = UInt64;
using Selector = PaddedPODArray<ColumnIndex>;
[[nodiscard]] virtual std::vector<MutablePtr> scatter(ColumnIndex num_columns, const Selector & selector) const = 0;
virtual void insertIndicesFrom(const IColumn & src, const Selector & selector);

/// This function will get row index from selector and append the data to this column.
/// This function will handle indexes start from input 'selector_start' and will append 'size' times
Expand Down
1 change: 1 addition & 0 deletions src/Disks/ObjectStorages/HDFS/HDFSObjectStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class HDFSObjectStorage : public IObjectStorage
const Poco::Util::AbstractConfiguration & config;

HDFSBuilderWrapper hdfs_builder;
protected:
HDFSFSPtr hdfs_fs;
SettingsPtr settings;
const std::string hdfs_root_path;
Expand Down
Loading

0 comments on commit c3000d5

Please sign in to comment.