Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions be/src/olap/rowset/segment_v2/column_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,6 @@ Status StructColumnWriter::append_data(const uint8_t** ptr, size_t num_rows) {
reinterpret_cast<const void*>(data),
num_rows));
}
if (is_nullable()) {
std::vector<vectorized::UInt8> null_signs(num_rows, 0);
const uint8_t* null_sign_ptr = null_signs.data();
RETURN_IF_ERROR(_null_writer->append_data(&null_sign_ptr, num_rows));
}
return Status::OK();
}

Expand Down
30 changes: 24 additions & 6 deletions be/src/olap/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,8 @@ vectorized::IColumn::MutablePtr Schema::get_column_by_field(const Field& field)
return get_data_type_ptr(field)->create_column();
}

vectorized::IColumn::MutablePtr Schema::get_predicate_column_ptr(const Field& field) {
if (UNLIKELY(field.type() == OLAP_FIELD_TYPE_ARRAY)) {
return get_data_type_ptr(field)->create_column();
}

vectorized::IColumn::MutablePtr Schema::get_predicate_column_ptr(const Field& field,
bool is_nullable) {
vectorized::IColumn::MutablePtr ptr = nullptr;
switch (field.type()) {
case OLAP_FIELD_TYPE_BOOL:
Expand Down Expand Up @@ -182,11 +179,32 @@ vectorized::IColumn::MutablePtr Schema::get_predicate_column_ptr(const Field& fi
case OLAP_FIELD_TYPE_DECIMAL128I:
ptr = doris::vectorized::PredicateColumnType<TYPE_DECIMAL128I>::create();
break;
case OLAP_FIELD_TYPE_ARRAY:
ptr = doris::vectorized::ColumnArray::create(
get_predicate_column_ptr(*field.get_sub_field(0)),
doris::vectorized::ColumnArray::ColumnOffsets::create());
break;
case OLAP_FIELD_TYPE_STRUCT: {
size_t field_size = field.get_sub_field_count();
doris::vectorized::MutableColumns columns(field_size);
for (size_t i = 0; i < field_size; i++) {
columns[i] = get_predicate_column_ptr(*field.get_sub_field(i));
}
ptr = doris::vectorized::ColumnStruct::create(std::move(columns));
break;
}
case OLAP_FIELD_TYPE_MAP:
ptr = doris::vectorized::ColumnMap::create(
doris::vectorized::ColumnArray::create(
get_predicate_column_ptr(*field.get_sub_field(0), true)),
doris::vectorized::ColumnArray::create(
get_predicate_column_ptr(*field.get_sub_field(1), true)));
break;
default:
LOG(FATAL) << "Unexpected type when choosing predicate column, type=" << field.type();
}

if (field.is_nullable()) {
if (field.is_nullable() || is_nullable) {
return doris::vectorized::ColumnNullable::create(std::move(ptr),
doris::vectorized::ColumnUInt8::create());
}
Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class Schema {

static vectorized::IColumn::MutablePtr get_column_by_field(const Field& field);

static vectorized::IColumn::MutablePtr get_predicate_column_ptr(const Field& field);
static vectorized::IColumn::MutablePtr get_predicate_column_ptr(const Field& field,
bool is_nullable = false);

const std::vector<Field*>& columns() const { return _cols; }

Expand Down
12 changes: 12 additions & 0 deletions be/src/vec/columns/column_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ size_t ColumnMap::filter(const Filter& filter) {
return value_result_size;
}

Status ColumnMap::filter_by_selector(const uint16_t* sel, size_t sel_size, IColumn* col_ptr) {
auto to = reinterpret_cast<vectorized::ColumnMap*>(col_ptr);

auto& array_keys = assert_cast<vectorized::ColumnArray&>(*keys);
array_keys.filter_by_selector(sel, sel_size, &to->get_keys());

auto& array_values = assert_cast<vectorized::ColumnArray&>(*values);
array_values.filter_by_selector(sel, sel_size, &to->get_values());

return Status::OK();
}

ColumnPtr ColumnMap::permute(const Permutation& perm, size_t limit) const {
return ColumnMap::create(keys->permute(perm, limit), values->permute(perm, limit));
}
Expand Down
5 changes: 2 additions & 3 deletions be/src/vec/columns/column_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ class ColumnMap final : public COWHelper<IColumn, ColumnMap> {
void update_hash_with_value(size_t n, SipHash& hash) const override;

ColumnPtr filter(const Filter& filt, ssize_t result_size_hint) const override;

size_t filter(const Filter& filter) override;

Status filter_by_selector(const uint16_t* sel, size_t sel_size, IColumn* col_ptr) override;
ColumnPtr permute(const Permutation& perm, size_t limit) const override;
ColumnPtr replicate(const Offsets& offsets) const override;
MutableColumns scatter(ColumnIndex num_columns, const Selector& selector) const override {
Expand Down Expand Up @@ -148,7 +147,7 @@ class ColumnMap final : public COWHelper<IColumn, ColumnMap> {
return get_offsets()[i] - get_offsets()[i - 1];
}

explicit ColumnMap(MutableColumnPtr&& keys, MutableColumnPtr&& values);
ColumnMap(MutableColumnPtr&& keys, MutableColumnPtr&& values);

ColumnMap(const ColumnMap&) = default;
};
Expand Down
10 changes: 10 additions & 0 deletions be/src/vec/columns/column_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ size_t ColumnStruct::filter(const Filter& filter) {
return result_size;
}

Status ColumnStruct::filter_by_selector(const uint16_t* sel, size_t sel_size, IColumn* col_ptr) {
auto to = reinterpret_cast<vectorized::ColumnStruct*>(col_ptr);
const size_t tuple_size = columns.size();
DCHECK_EQ(to->tuple_size(), tuple_size);
for (size_t i = 0; i < tuple_size; ++i) {
columns[i]->filter_by_selector(sel, sel_size, &to->get_column(i));
}
return Status::OK();
}

ColumnPtr ColumnStruct::permute(const Permutation& perm, size_t limit) const {
const size_t tuple_size = columns.size();
Columns new_columns(tuple_size);
Expand Down
5 changes: 2 additions & 3 deletions be/src/vec/columns/column_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ class ColumnStruct final : public COWHelper<IColumn, ColumnStruct> {

void insert_range_from(const IColumn& src, size_t start, size_t length) override;
ColumnPtr filter(const Filter& filt, ssize_t result_size_hint) const override;

size_t filter(const Filter& filter) override;

Status filter_by_selector(const uint16_t* sel, size_t sel_size, IColumn* col_ptr) override;
ColumnPtr permute(const Permutation& perm, size_t limit) const override;
ColumnPtr replicate(const Offsets& offsets) const override;
MutableColumns scatter(ColumnIndex num_columns, const Selector& selector) const override;
Expand Down Expand Up @@ -240,4 +239,4 @@ class ColumnStruct final : public COWHelper<IColumn, ColumnStruct> {
// const Collator* collator = nullptr) const;
};

} // namespace doris::vectorized
} // namespace doris::vectorized
8 changes: 0 additions & 8 deletions be/src/vec/data_types/data_type_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@

#include "data_type_map.h"

#include "gen_cpp/data.pb.h"
#include "vec/columns/column_array.h"
#include "vec/columns/column_map.h"
#include "vec/columns/column_nullable.h"
#include "vec/common/assert_cast.h"
#include "vec/data_types/data_type_array.h"
#include "vec/data_types/data_type_nullable.h"

namespace doris::vectorized {

DataTypeMap::DataTypeMap(const DataTypePtr& keys_, const DataTypePtr& values_) {
Expand Down
7 changes: 7 additions & 0 deletions be/src/vec/data_types/data_type_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@

#pragma once

#include "gen_cpp/data.pb.h"
#include "util/stack_util.h"
#include "vec/columns/column_array.h"
#include "vec/columns/column_map.h"
#include "vec/columns/column_nullable.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_array.h"
#include "vec/data_types/data_type_nullable.h"

namespace doris::vectorized {
/** Map data type.
Expand Down
4 changes: 4 additions & 0 deletions regression-test/data/delete_p0/test_map_column_delete.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
1 {1:'a', 2:'doris'}
2 {}
3 changes: 3 additions & 0 deletions regression-test/data/delete_p0/test_struct_column_delete.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
1 {1, 'a'}
27 changes: 27 additions & 0 deletions regression-test/suites/delete_p0/test_map_column_delete.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_map_column_delete") {
def tableName = "test_map_column_delete"

sql """ DROP TABLE IF EXISTS ${tableName}; """
sql "ADMIN SET FRONTEND CONFIG ('enable_struct_type' = 'true')"
sql """ CREATE TABLE IF NOT EXISTS ${tableName} (id INT NULL, m_map MAP<INT, VARCHAR(30)> NULL) ENGINE=OLAP DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 4 PROPERTIES ( "replication_allocation" = "tag.location.default: 1","in_memory" = "false","storage_format" = "V2") """
sql """ insert into ${tableName} values(1, {1:'a', 2:"doris"}),(2,{}),(3,NULL),(4,NULL),(5,NULL) """
sql """ DELETE FROM ${tableName} WHERE m_map is NULL """
qt_sql """ SELECT * FROM ${tableName} order by id """
}
27 changes: 27 additions & 0 deletions regression-test/suites/delete_p0/test_struct_column_delete.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_struct_column_delete") {
def tableName = "test_struct_column_delete"

sql """ DROP TABLE IF EXISTS ${tableName}; """
sql "ADMIN SET FRONTEND CONFIG ('enable_struct_type' = 'true')"
sql """ CREATE TABLE IF NOT EXISTS ${tableName} (id INT NULL, s_struct STRUCT<f1:INT, f2:VARCHAR(30)> NULL) ENGINE=OLAP DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 4 PROPERTIES ( "replication_allocation" = "tag.location.default: 1","in_memory" = "false","storage_format" = "V2") """
sql """ insert into ${tableName} values(1, {1, 'a'}),(2,NULL),(3,NULL),(4,NULL),(5,NULL) """
sql """ DELETE FROM ${tableName} WHERE s_struct is NULL """
qt_sql """ SELECT * FROM ${tableName} order by id """
}