Skip to content
Open
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 @@ -99,7 +99,7 @@ public Slot toSlot() throws UnboundException {
slotReference != null ? ((SlotReference) child()).getOriginalTable().orElse(null) : null,
slotReference != null ? slotReference.getOriginalColumn().orElse(null) : null,
slotReference != null ? ((SlotReference) child()).getOneLevelTable().orElse(null) : null,
slotReference != null ? slotReference.getOriginalColumn().orElse(null) : null,
slotReference != null ? slotReference.getOneLevelColumn().orElse(null) : null,
slotReference != null ? slotReference.getSubPath() : ImmutableList.of(), Optional.empty()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public SlotReference withColumn(Column column) {
@Override
public Slot withOneLevelTableAndColumnAndQualifier(TableIf oneLevelTable, Column column, List<String> qualifier) {
return new SlotReference(exprId, name, dataType, nullable, qualifier,
originalTable, column, oneLevelTable, column,
originalTable, originalColumn, oneLevelTable, column,
subPath, indexInSqlString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.doris.nereids.trees.expressions;

import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentDate;
import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.UnixTimestamp;
Expand All @@ -26,6 +28,7 @@
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
import org.apache.doris.nereids.types.IntegerType;

import com.google.common.collect.ImmutableList;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -66,4 +69,18 @@ public void testContainsNondeterministic() {
new UnixTimestamp(), new IntegerLiteral(2)).containsNondeterministic());

}

@Test
public void testAliasToSlotKeepsOneLevelColumn() {
SlotReference slotReference = new SlotReference(new ExprId(1), "k1", IntegerType.INSTANCE, true,
ImmutableList.of("test", "view_metadata"), null, new Column("k1", PrimitiveType.INT),
null, new Column("vk1", PrimitiveType.INT));

SlotReference aliasSlot = (SlotReference) new Alias(slotReference, "c2").toSlot();

Assertions.assertTrue(aliasSlot.getOriginalColumn().isPresent());
Assertions.assertTrue(aliasSlot.getOneLevelColumn().isPresent());
Assertions.assertEquals("k1", aliasSlot.getOriginalColumn().get().getName());
Assertions.assertEquals("vk1", aliasSlot.getOneLevelColumn().get().getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !view_lazy --
aaa
bbb

-- !chain_view_lazy --
aaa
bbb

-- !view_lazy_filter --
bbb 200
ccc 300

Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ suite ("metadata") {
println viewMeta

assertEquals("c1", viewMeta.getColumnName(1))
assertEquals("vk1", viewMeta.getColumnName(2))
assertEquals("vk1", viewMeta.getColumnName(3))
assertEquals("vk1", viewMeta.getColumnName(2),"viewMeta.getColumnName(2)")
assertEquals("vk1", viewMeta.getColumnName(3), "viewMeta.getColumnName(3)")
assertEquals("k2", viewMeta.getColumnName(4))
assertEquals("k2", viewMeta.getColumnName(5))
assertEquals("c4", viewMeta.getColumnName(6))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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("lazy_materialize_view") {
sql """
set enable_two_phase_read_opt = true;
set topn_opt_limit_threshold = 1000;
set topn_lazy_materialization_threshold = -1;
"""

sql "drop table if exists lazy_mat_view_t"
sql """
CREATE TABLE lazy_mat_view_t (
k1 INT NOT NULL,
k2 INT NOT NULL,
v1 VARCHAR(100) NULL,
v2 INT NULL
)
DUPLICATE KEY(k1)
DISTRIBUTED BY HASH(k1) BUCKETS 1
PROPERTIES (
"replication_num" = "1"
);
"""

sql """
insert into lazy_mat_view_t values
(1, 10, 'aaa', 100),
(2, 20, 'bbb', 200),
(3, 30, 'ccc', 300);
"""

sql "sync"

sql "drop view if exists lazy_mat_view_v1"
sql "CREATE VIEW lazy_mat_view_v1 AS SELECT * FROM lazy_mat_view_t"

sql "drop view if exists lazy_mat_view_v2"
sql "CREATE VIEW lazy_mat_view_v2 AS SELECT * FROM lazy_mat_view_v1"

// lazy materialization through a single-level view
explain {
sql "select v1 from lazy_mat_view_v1 order by k1 limit 2"
contains "OPT TWO PHASE"
}

order_qt_view_lazy """
select v1 from lazy_mat_view_v1 order by k1 limit 2
"""

// lazy materialization through a chained view (v2 -> v1 -> t)
explain {
sql "select v1 from lazy_mat_view_v2 order by k1 limit 2"
contains "OPT TWO PHASE"
}

order_qt_chain_view_lazy """
select v1 from lazy_mat_view_v2 order by k1 limit 2
"""

// lazy materialization through view with filter
explain {
sql "select v1, v2 from lazy_mat_view_v1 where k2 > 10 order by k1 limit 2"
contains "OPT TWO PHASE"
}

order_qt_view_lazy_filter """
select v1, v2 from lazy_mat_view_v1 where k2 > 10 order by k1 limit 2
"""
}
Loading