/root/doris/be/src/exprs/vmap_literal.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "exprs/vmap_literal.h" |
19 | | |
20 | | #include <glog/logging.h> |
21 | | |
22 | | #include <memory> |
23 | | #include <ostream> |
24 | | #include <vector> |
25 | | |
26 | | #include "core/column/column.h" |
27 | | #include "core/data_type/data_type.h" |
28 | | #include "core/field.h" |
29 | | #include "exprs/vexpr.h" |
30 | | |
31 | | namespace doris { |
32 | | class RowDescriptor; |
33 | | class RuntimeState; |
34 | | class VExprContext; |
35 | | } // namespace doris |
36 | | |
37 | | //insert into table_map values ({'name':'zhangsan', 'gender':'male'}), ({'name':'lisi', 'gender':'female'}); |
38 | | namespace doris { |
39 | | |
40 | | Status VMapLiteral::prepare(RuntimeState* state, const RowDescriptor& row_desc, |
41 | 0 | VExprContext* context) { |
42 | 0 | RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, row_desc, context)); |
43 | | // map-field should contain two vector field for keys and values |
44 | 0 | Field map = Field::create_field<TYPE_MAP>(Map()); |
45 | 0 | Field keys = Field::create_field<TYPE_ARRAY>(Array()); |
46 | 0 | Field values = Field::create_field<TYPE_ARRAY>(Array()); |
47 | | // each child is slot with key1, value1, key2, value2... |
48 | 0 | for (int idx = 0; idx < _children.size() && idx + 1 < _children.size(); idx += 2) { |
49 | 0 | Field kf, vf; |
50 | 0 | auto key_literal = std::dynamic_pointer_cast<const VLiteral>(_children[idx]); |
51 | 0 | key_literal->get_column_ptr()->get(0, kf); |
52 | 0 | auto val_literal = std::dynamic_pointer_cast<const VLiteral>( |
53 | 0 | VExpr::expr_without_cast(_children[idx + 1])); |
54 | 0 | val_literal->get_column_ptr()->get(0, vf); |
55 | |
|
56 | 0 | keys.get<TYPE_ARRAY>().push_back(kf); |
57 | 0 | values.get<TYPE_ARRAY>().push_back(vf); |
58 | 0 | } |
59 | 0 | map.get<TYPE_MAP>().push_back(keys); |
60 | 0 | map.get<TYPE_MAP>().push_back(values); |
61 | |
|
62 | 0 | _column_ptr = _data_type->create_column_const(1, map); |
63 | 0 | return Status::OK(); |
64 | 0 | } |
65 | | |
66 | | } // namespace doris |