Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Sep 12, 2024
1 parent 04b2dfd commit 88a08e7
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

package org.apache.doris.analysis;

public class MetaTableName {

public static final String PARTITIONS = "partitions";

private final String tableName;

public MetaTableName(String tableName) {
this.tableName = tableName;
}

public String getTableName() {
return tableName;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.doris.nereids.analyzer;

import org.apache.doris.analysis.SysTableName;
import org.apache.doris.analysis.MetaTableName;
import org.apache.doris.analysis.TableScanParams;
import org.apache.doris.analysis.TableSnapshot;
import org.apache.doris.common.Pair;
Expand Down Expand Up @@ -63,7 +63,7 @@ public class UnboundRelation extends LogicalRelation implements Unbound, BlockFu

private final Optional<TableSnapshot> tableSnapshot;
// eg: tableName$partitions
private final Optional<SysTableName> sysTableName;
private final Optional<MetaTableName> metaTableName;

public UnboundRelation(RelationId id, List<String> nameParts) {
this(id, nameParts, Optional.empty(), Optional.empty(), ImmutableList.of(), false, ImmutableList.of(),
Expand Down Expand Up @@ -109,14 +109,23 @@ public UnboundRelation(RelationId id, List<String> nameParts, List<String> partN
tableSnapshot, Optional.empty());
}

public UnboundRelation(RelationId id, List<String> nameParts, List<String> partNames, boolean isTempPart,
List<Long> tabletIds, List<String> hints, Optional<TableSample> tableSample, Optional<String> indexName,
TableScanParams scanParams, Optional<Pair<Integer, Integer>> indexInSqlString,
Optional<TableSnapshot> tableSnapshot, Optional<MetaTableName> metaTableName) {
this(id, nameParts, Optional.empty(), Optional.empty(),
partNames, isTempPart, tabletIds, hints, tableSample, indexName, scanParams, indexInSqlString,
tableSnapshot, metaTableName);
}

/**
* constructor of UnboundRelation
*/
public UnboundRelation(RelationId id, List<String> nameParts, Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties, List<String> partNames, boolean isTempPart,
List<Long> tabletIds, List<String> hints, Optional<TableSample> tableSample, Optional<String> indexName,
TableScanParams scanParams, Optional<Pair<Integer, Integer>> indexInSqlString,
Optional<TableSnapshot> tableSnapshot, Optional<SysTableName> sysTableName) {
Optional<TableSnapshot> tableSnapshot, Optional<MetaTableName> metaTableName) {
super(id, PlanType.LOGICAL_UNBOUND_RELATION, groupExpression, logicalProperties);
this.nameParts = ImmutableList.copyOf(Objects.requireNonNull(nameParts, "nameParts should not null"));
this.partNames = ImmutableList.copyOf(Objects.requireNonNull(partNames, "partNames should not null"));
Expand All @@ -128,7 +137,7 @@ public UnboundRelation(RelationId id, List<String> nameParts, Optional<GroupExpr
this.scanParams = scanParams;
this.indexInSqlString = indexInSqlString;
this.tableSnapshot = tableSnapshot;
this.sysTableName = sysTableName;
this.metaTableName = metaTableName;
}

public List<String> getNameParts() {
Expand All @@ -150,21 +159,21 @@ public Plan withGroupExpression(Optional<GroupExpression> groupExpression) {
return new UnboundRelation(relationId, nameParts,
groupExpression, Optional.of(getLogicalProperties()),
partNames, isTempPart, tabletIds, hints, tableSample, indexName, null, indexInSqlString, tableSnapshot,
sysTableName);
metaTableName);
}

@Override
public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties, List<Plan> children) {
return new UnboundRelation(relationId, nameParts, groupExpression, logicalProperties, partNames,
isTempPart, tabletIds, hints, tableSample, indexName, null, indexInSqlString, tableSnapshot,
sysTableName);
metaTableName);
}

public UnboundRelation withIndexInSql(Pair<Integer, Integer> index) {
return new UnboundRelation(relationId, nameParts, groupExpression, Optional.of(getLogicalProperties()),
partNames, isTempPart, tabletIds, hints, tableSample, indexName, null,
Optional.of(index), tableSnapshot, sysTableName);
Optional.of(index), tableSnapshot, metaTableName);
}

@Override
Expand Down Expand Up @@ -236,7 +245,7 @@ public Optional<TableSnapshot> getTableSnapshot() {
return tableSnapshot;
}

public Optional<SysTableName> getSysTableName() {
return sysTableName;
public Optional<MetaTableName> getMetaTableName() {
return metaTableName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.analysis.ArithmeticExpr.Operator;
import org.apache.doris.analysis.BrokerDesc;
import org.apache.doris.analysis.ColumnNullableType;
import org.apache.doris.analysis.MetaTableName;
import org.apache.doris.analysis.StorageBackend;
import org.apache.doris.analysis.TableName;
import org.apache.doris.analysis.TableScanParams;
Expand Down Expand Up @@ -1407,7 +1408,7 @@ protected LogicalPlan withTableAlias(LogicalPlan plan, TableAliasContext ctx) {

@Override
public LogicalPlan visitTableName(TableNameContext ctx) {
List<String> tableId = visitMultipartIdentifier(ctx.multipartIdentifier());
List<String> nameParts = visitMultipartIdentifier(ctx.multipartIdentifier());
List<String> partitionNames = new ArrayList<>();
boolean isTempPart = false;
if (ctx.specifiedPartition() != null) {
Expand Down Expand Up @@ -1453,10 +1454,20 @@ public LogicalPlan visitTableName(TableNameContext ctx) {
}
}

MetaTableName metaTableName = null;
if (ctx.metaTableParams() != null) {
metaTableName = new MetaTableName(ctx.metaTableParams().identifier().getText());
}

TableSample tableSample = ctx.sample() == null ? null : (TableSample) visit(ctx.sample());
UnboundRelation relation = new UnboundRelation(StatementScopeIdGenerator.newRelationId(),
tableId, partitionNames, isTempPart, tabletIdLists, relationHints,
Optional.ofNullable(tableSample), indexName, scanParams, Optional.ofNullable(tableSnapshot));
nameParts, Optional.empty(), Optional.empty(), partitionNames, isTempPart,
tabletIdLists, relationHints,
Optional.ofNullable(tableSample),
indexName, scanParams, Optional.empty(),
Optional.ofNullable(tableSnapshot),
Optional.ofNullable(metaTableName));

LogicalPlan checkedRelation = LogicalPlanBuilderAssistant.withCheckPolicy(relation);
LogicalPlan plan = withTableAlias(checkedRelation, ctx.tableAlias());
for (LateralViewContext lateralViewContext : ctx.lateralView()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.doris.nereids.rules.analysis;

import org.apache.doris.analysis.MetaTableName;
import org.apache.doris.catalog.AggStateType;
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.Column;
Expand Down Expand Up @@ -65,6 +66,8 @@
import org.apache.doris.nereids.trees.expressions.functions.agg.Min;
import org.apache.doris.nereids.trees.expressions.functions.agg.QuantileUnion;
import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
import org.apache.doris.nereids.trees.expressions.functions.table.PartitionValues;
import org.apache.doris.nereids.trees.expressions.functions.table.TableValuedFunction;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PreAggStatus;
Expand Down Expand Up @@ -377,8 +380,15 @@ private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelatio
});
List<String> qualifierWithoutTableName = Lists.newArrayList();
qualifierWithoutTableName.addAll(qualifiedTableName.subList(0, qualifiedTableName.size() - 1));
if (unboundRelation.getSysTableName().isPresent()) {
return new LogicalTVFRelation();
if (unboundRelation.getMetaTableName().isPresent()) {
String metaTableName = unboundRelation.getMetaTableName().get().getTableName();
TableValuedFunction tvf;
if (metaTableName.equalsIgnoreCase(MetaTableName.PARTITIONS)) {
tvf = PartitionValues.create(qualifiedTableName);
} else {
throw new AnalysisException("Unsupported meta table: " + metaTableName);
}
return new LogicalTVFRelation(unboundRelation.getRelationId(), tvf);
}
boolean isView = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import org.apache.doris.tablefunction.PartitionValuesTableValuedFunction;
import org.apache.doris.tablefunction.TableValuedFunctionIf;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

/**
Expand All @@ -35,6 +39,20 @@ public PartitionValues(Properties properties) {
super("partition_values", properties);
}

/**
* Create PartitionValues function.
* @param qualifiedTableName ctl.db.tbl
* @return PartitionValues function
*/
public static TableValuedFunction create(List<String> qualifiedTableName) {
Preconditions.checkArgument(qualifiedTableName != null && qualifiedTableName.size() == 3);
Map<String, String> parameters = Maps.newHashMap();
parameters.put(PartitionValuesTableValuedFunction.CATALOG, qualifiedTableName.get(0));
parameters.put(PartitionValuesTableValuedFunction.DB, qualifiedTableName.get(1));
parameters.put(PartitionValuesTableValuedFunction.TABLE, qualifiedTableName.get(2));
return new PartitionValues(new Properties(parameters));
}

@Override
public FunctionSignature customSignature() {
return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX, getArgumentsTypes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class PartitionValuesTableValuedFunction extends MetadataTableValuedFunct

public static final String NAME = "partition_values";

private static final String CATALOG = "catalog";
private static final String DB = "database";
private static final String TABLE = "table";
public static final String CATALOG = "catalog";
public static final String DB = "database";
public static final String TABLE = "table";

private static final ImmutableSet<String> PROPERTIES_SET = ImmutableSet.of(CATALOG, DB, TABLE);

Expand Down

0 comments on commit 88a08e7

Please sign in to comment.