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
10 changes: 9 additions & 1 deletion be/src/vec/functions/function_variant_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "common/status.h"
#include "exprs/json_functions.h"
#include "simdjson.h"
#include "util/defer_op.h"
#include "vec/columns/column.h"
#include "vec/columns/column_nullable.h"
#include "vec/columns/column_object.h"
Expand Down Expand Up @@ -102,8 +103,11 @@ class FunctionVariantElement : public IFunction {
static Status get_element_column(const ColumnObject& src, const ColumnPtr& index_column,
ColumnPtr* result) {
std::string field_name = index_column->get_data_at(0).to_string();
Defer finalize([&]() { (*result)->assume_mutable()->finalize(); });
if (src.empty()) {
*result = ColumnObject::create(true);
// src subcolumns empty but src row count may not be 0
(*result)->assume_mutable()->insert_many_defaults(src.size());
return Status::OK();
}
if (src.is_scalar_variant() &&
Expand Down Expand Up @@ -135,8 +139,10 @@ class FunctionVariantElement : public IFunction {
PathInData path(field_name);
ColumnObject::Subcolumns subcolumns = mutable_ptr->get_subcolumns();
const auto* node = subcolumns.find_exact(path);
auto result_col = ColumnObject::create(true, false /*should not create root*/);
MutableColumnPtr result_col;
if (node != nullptr) {
// Create without root, since root will be added
result_col = ColumnObject::create(true, false /*should not create root*/);
std::vector<decltype(node)> nodes;
PathsInData paths;
ColumnObject::Subcolumns::get_leaves_of_node(node, nodes, paths);
Expand All @@ -162,6 +168,8 @@ class FunctionVariantElement : public IFunction {
auto container = ColumnObject::create(std::move(new_subcolumns), true);
result_col->insert_range_from(*container, 0, container->size());
} else {
// Create with root, otherwise the root type maybe type Nothing
result_col = ColumnObject::create(true);
result_col->insert_many_defaults(src.size());
}
*result = result_col->get_ptr();
Expand Down
130 changes: 130 additions & 0 deletions regression-test/data/variant_p0/rqg/rqg3.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !rqg3 --
0

-- !rqg3_2 --
0

-- !rqg3_3 --
0

-- !rqg3_4 --
0

-- !rqg3_5 --
0

-- !rqg3_6 --
0

-- !rqg3_7 --
0

-- !rqg3_8 --
0

-- !rqg3_9 --
0

-- !rqg3_10 --
0

-- !rqg3_11 --
10

-- !rqg3_12 --
10

-- !rqg3_13 --
10

-- !rqg3_14 --
10

-- !rqg3_15 --
10

-- !rqg3_16 --
10

-- !rqg3_17 --
10

-- !rqg3_18 --
10

-- !rqg3_19 --
21

-- !rqg3_20 --
21

-- !rqg3_21 --
21

-- !rqg3_22 --
21

-- !rqg3_23 --
21

-- !rqg3_24 --
21

-- !rqg3_25 --
25

-- !rqg3_26 --
25

-- !rqg3_27 --
25

-- !rqg3_28 --
25

-- !rqg3_29 --
25

-- !rqg3_30 --
25

-- !rqg3_31 --
6

-- !rqg3_32 --
6

-- !rqg3_33 --
6

-- !rqg3_34 --
6

-- !rqg3_35 --
6

-- !rqg3_36 --
6

-- !rqg3_37 --
7

-- !rqg3_38 --
7

-- !rqg3_39 --
7

-- !rqg3_40 --
7

-- !rqg3_41 --
7

-- !rqg3_42 --
7

-- !rqg3_43 --
0 \N c \N \N \N

Loading