Skip to content

Commit

Permalink
[feature-wip][array-type] Support more sub types. (#9466)
Browse files Browse the repository at this point in the history
Please refer to #9465
  • Loading branch information
adonis0147 authored May 26, 2022
1 parent 73e31a2 commit 2a11a4a
Show file tree
Hide file tree
Showing 25 changed files with 1,207 additions and 676 deletions.
5 changes: 3 additions & 2 deletions be/src/exprs/array_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ void ArrayFunctions::init() {}
DCHECK_EQ(context->get_return_type().children.size(), 1); \
CollectionValue v; \
CollectionValue::init_collection(context, num_children, PRIMARY_TYPE, &v); \
for (int i = 0; i < num_children; ++i) { \
v.set(i, PRIMARY_TYPE, values + i); \
auto iterator = v.iterator(PRIMARY_TYPE); \
for (int i = 0; i < num_children; ++i, iterator.next()) { \
iterator.set(values + i); \
} \
CollectionVal ret; \
v.to_collection_val(&ret); \
Expand Down
13 changes: 7 additions & 6 deletions be/src/exprs/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ Status Literal::prepare(RuntimeState* state, const RowDescriptor& row_desc, Expr
if (type().type == TYPE_ARRAY) {
DCHECK_EQ(type().children.size(), 1) << "array children type not 1";
// init array value
auto td = type().children.at(0).type;
RETURN_IF_ERROR(CollectionValue::init_collection(state->obj_pool(), get_num_children(), td,
&_value.array_val));
auto child_type = type().children.at(0).type;
RETURN_IF_ERROR(CollectionValue::init_collection(state->obj_pool(), get_num_children(),
child_type, &_value.array_val));
auto iterator = _value.array_val.iterator(child_type);
// init every item
for (int i = 0; i < get_num_children(); ++i) {
Expr* children = get_child(i);
RETURN_IF_ERROR(_value.array_val.set(i, td, children->get_const_val(context)));
for (int i = 0; i < get_num_children() && iterator.has_next(); ++i, iterator.next()) {
Expr* child = get_child(i);
iterator.set(child->get_const_val(context));
}
}

Expand Down
16 changes: 15 additions & 1 deletion be/src/olap/aggregate_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ AggregateFuncResolver::AggregateFuncResolver() {
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_STRING>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_BOOL>();
// array types has sub type like array<int> field type is array, subtype is int
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_BOOL>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_TINYINT>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
Expand All @@ -116,9 +118,21 @@ AggregateFuncResolver::AggregateFuncResolver() {
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_LARGEINT>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_VARCHAR>();
OLAP_FIELD_TYPE_FLOAT>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_DOUBLE>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_CHAR>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_VARCHAR>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_STRING>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_DATE>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_DATETIME>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_DECIMAL>();
add_aggregate_mapping<OLAP_FIELD_AGGREGATION_NONE, OLAP_FIELD_TYPE_ARRAY,
OLAP_FIELD_TYPE_ARRAY>();

Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/rowset/segment_v2/segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Status SegmentWriter::append_block(const vectorized::Block* block, size_t row_po
}

// convert column data from engine format to storage layer format
std::vector<vectorized::IOlapColumnDataAccessorSPtr> short_key_columns;
std::vector<vectorized::IOlapColumnDataAccessor*> short_key_columns;
size_t num_key_columns = _tablet_schema->num_short_key_columns();
for (size_t cid = 0; cid < _column_writers.size(); ++cid) {
auto converted_result = _olap_data_convertor.convert_column_data(cid);
Expand Down
15 changes: 10 additions & 5 deletions be/src/olap/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ class ArrayTypeInfo : public TypeInfo {
}

void direct_copy(void* dest, const void* src) const override {
auto dest_value = reinterpret_cast<CollectionValue*>(dest);
auto dest_value = static_cast<CollectionValue*>(dest);
// NOTICE: The address pointed by null_signs of the dest_value can NOT be modified here.
auto base = reinterpret_cast<uint8_t*>(dest_value->mutable_null_signs());
direct_copy(&base, dest, src);
}

void direct_copy(uint8_t** base, void* dest, const void* src) const {
auto dest_value = reinterpret_cast<CollectionValue*>(dest);
auto src_value = reinterpret_cast<const CollectionValue*>(src);
auto dest_value = static_cast<CollectionValue*>(dest);
auto src_value = static_cast<const CollectionValue*>(src);

auto nulls_size = src_value->has_null() ? src_value->length() : 0;
dest_value->set_data(src_value->length() ? (*base + nulls_size) : nullptr);
Expand All @@ -330,17 +330,22 @@ class ArrayTypeInfo : public TypeInfo {
src_value->length());
}
*base += nulls_size + src_value->length() * _item_type_info->size();

// Direct copy item.
if (_item_type_info->type() == OLAP_FIELD_TYPE_ARRAY) {
for (uint32_t i = 0; i < src_value->length(); ++i) {
if (dest_value->is_null_at(i)) continue;
if (dest_value->is_null_at(i)) {
continue;
}
dynamic_cast<const ArrayTypeInfo*>(_item_type_info.get())
->direct_copy(base, (uint8_t*)(dest_value->mutable_data()) + i * _item_size,
(uint8_t*)(src_value->data()) + i * _item_size);
}
} else {
for (uint32_t i = 0; i < src_value->length(); ++i) {
if (dest_value->is_null_at(i)) continue;
if (dest_value->is_null_at(i)) {
continue;
}
auto dest_address = (uint8_t*)(dest_value->mutable_data()) + i * _item_size;
auto src_address = (uint8_t*)(src_value->data()) + i * _item_size;
if (is_olap_string_type(_item_type_info->type())) {
Expand Down
Loading

0 comments on commit 2a11a4a

Please sign in to comment.