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
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ public Plan visitLogicalProject(LogicalProject<? extends Plan> project, Context
.withChildren(context.elementAtToSlotMap.get(child));
} else {
addOthers = false;
newProjection = projection;
newProjection = (NamedExpression) projection
.withChildren(ExpressionUtils.replace(child, context.elementAtToSlotMap));

// try push element_at on this slot
if (extractSlotToSubPathPair((ElementAt) child) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ public void testVariantNumericIndexSubPath() throws Exception {
);
}

@Test
public void testVariantArraySubscriptUsesPrunedSubPath() throws Exception {
String sql = "select cast(v['items']['type'] as array<string>)[1] from variant_tbl";
String explain = getSQLPlanOrErrorMsg(sql, true);
Assertions.assertTrue(explain.contains("final projections: element_at(CAST(v AS array<text>), 1)"),
explain);
Assertions.assertTrue(explain.contains("subColPath=[items, type]"),
explain);
Assertions.assertFalse(explain.contains("element_at(CAST(element_at(element_at("),
explain);
Comment on lines +79 to +84
assertVariantSubColumnSlots(
sql,
ImmutableList.of(
ImmutableList.of("items", "type")
)
);
}

@Test
public void testVariantOrPredicatePaths() throws Exception {
assertPredicateAccessPathsEqual(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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_variant_array_subscript", "p0") {
sql "set enable_nereids_planner = true"
sql "set enable_fallback_to_original_planner = false"
sql "set default_variant_enable_nested_group = false"
sql "set default_variant_max_subcolumns_count = 100"

sql "DROP TABLE IF EXISTS test_variant_array_subscript"
sql """
CREATE TABLE test_variant_array_subscript (
id BIGINT,
v VARIANT
) ENGINE=OLAP
DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"disable_auto_compaction" = "true"
)
"""

sql """
INSERT INTO test_variant_array_subscript VALUES
(1, '{"items":{"type":["e2e_QC","platform_QC"]}}')
"""
sql "sync"

explain {
verbose true
sql """
SELECT CAST(v['items']['type'] AS ARRAY<STRING>)[1]
FROM test_variant_array_subscript
"""
contains "subColPath=[items, type]"
contains "element_at(CAST(v"
notContains "element_at(CAST(element_at(element_at("
}
}
Loading