Skip to content

Commit

Permalink
[feature](mtmv)add more test case1 (apache#28910)
Browse files Browse the repository at this point in the history
  • Loading branch information
zddr authored and stephen committed Dec 28, 2023
1 parent b0cc8d2 commit c8bac6c
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.apache.doris.nereids.trees.plans.visitor.TableCollector.TableCollectorContext;
import org.apache.doris.qe.ConnectContext;

import com.google.common.collect.Sets;

import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -77,12 +79,7 @@ private static Set<BaseTableInfo> getBaseTables(Plan plan) {
}

private static Set<BaseTableInfo> getBaseViews(Plan plan) {
TableCollectorContext collectorContext =
new TableCollector.TableCollectorContext(
com.google.common.collect.Sets.newHashSet(TableType.VIEW));
plan.accept(TableCollector.INSTANCE, collectorContext);
List<TableIf> collectedTables = collectorContext.getCollectedTables();
return transferTableIfToInfo(collectedTables);
return Sets.newHashSet();
}

private static Set<BaseTableInfo> transferTableIfToInfo(List<TableIf> tables) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.doris.catalog.PartitionType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.View;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.FeNameFormat;
Expand All @@ -56,6 +57,7 @@
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalSink;
import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
import org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionCollector;
import org.apache.doris.nereids.trees.plans.visitor.TableCollector;
import org.apache.doris.nereids.trees.plans.visitor.TableCollector.TableCollectorContext;
Expand All @@ -66,6 +68,8 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -80,6 +84,8 @@
* MTMV info in creating MTMV.
*/
public class CreateMTMVInfo {
public static final Logger LOG = LogManager.getLogger(CreateMTMVInfo.class);

private final boolean ifNotExists;
private final TableNameInfo mvName;
private List<String> keys;
Expand Down Expand Up @@ -208,7 +214,7 @@ public void analyzeQuery(ConnectContext ctx) {
throw new AnalysisException("at least contain one table");
}
// can not contain VIEW or MTMV
analyzeBaseTables(plan);
analyzeBaseTables(planner.getAnalyzedPlan());
// can not contain Random function
analyzeExpressions(planner.getAnalyzedPlan());
// can not contain partition or tablets
Expand Down Expand Up @@ -282,11 +288,28 @@ private PartitionDesc generatePartitionDesc(OlapTable relatedTable) {

private void analyzeBaseTables(Plan plan) {
TableCollectorContext collectorContext =
new TableCollector.TableCollectorContext(Sets.newHashSet(TableType.MATERIALIZED_VIEW, TableType.VIEW));
new TableCollector.TableCollectorContext(Sets.newHashSet(TableType.MATERIALIZED_VIEW));
plan.accept(TableCollector.INSTANCE, collectorContext);
List<TableIf> collectedTables = collectorContext.getCollectedTables();
if (!CollectionUtils.isEmpty(collectedTables)) {
throw new AnalysisException("can not contain MATERIALIZED_VIEW or VIEW");
throw new AnalysisException("can not contain MATERIALIZED_VIEW");
}

List<Object> subQuerys = plan.collectToList(node -> node instanceof LogicalSubQueryAlias);
for (Object subquery : subQuerys) {
List<String> qualifier = ((LogicalSubQueryAlias) subquery).getQualifier();
if (!CollectionUtils.isEmpty(qualifier) && qualifier.size() == 3) {
try {
TableIf table = Env.getCurrentEnv().getCatalogMgr()
.getCatalogOrAnalysisException(qualifier.get(0))
.getDbOrAnalysisException(qualifier.get(1)).getTableOrAnalysisException(qualifier.get(2));
if (table instanceof View) {
throw new AnalysisException("can not contain VIEW");
}
} catch (org.apache.doris.common.AnalysisException e) {
LOG.warn("can not get table, ", e);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public RelationId getRelationId() {
return relationId;
}

public List<String> getQualifier() {
return qualifier;
}

@Override
public Set<RelationId> getInputRelations() {
Set<RelationId> relationIdSet = Sets.newHashSet();
Expand Down
7 changes: 4 additions & 3 deletions regression-test/data/mtmv_p0/test_build_mtmv.out
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ lisi 300
zhangsang 200

-- !select --
clz 200
lisi 300
zhangsang 200
{grace_period=3333}

-- !select --
clz 200
Expand All @@ -59,3 +57,6 @@ clz 200
lisi 300
zhangsang 200

-- !select_union --
11 111

Loading

0 comments on commit c8bac6c

Please sign in to comment.