[feature](nereids) Support select temp partition (#15579)
Support such grammer:
select * from t_p temporary partition(tp1);
select * from t_p temporary partitions(tp1);
select * from t_p temporary partition tp1;
This commit is contained in:
@ -312,8 +312,8 @@ qualifiedName
|
||||
;
|
||||
|
||||
specifiedPartition
|
||||
: PARTITION identifier
|
||||
| PARTITIONS identifierList
|
||||
: TEMPORARY? PARTITION (identifier | identifierList)
|
||||
| TEMPORARY? PARTITIONS identifierList
|
||||
;
|
||||
|
||||
constant
|
||||
|
||||
@ -45,20 +45,23 @@ import java.util.Optional;
|
||||
public class UnboundRelation extends LogicalRelation implements Unbound {
|
||||
private final List<String> nameParts;
|
||||
private final List<String> partNames;
|
||||
private final boolean isTempPart;
|
||||
|
||||
public UnboundRelation(RelationId id, List<String> nameParts) {
|
||||
this(id, nameParts, Optional.empty(), Optional.empty(), Collections.emptyList());
|
||||
this(id, nameParts, Optional.empty(), Optional.empty(),
|
||||
Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
public UnboundRelation(RelationId id, List<String> nameParts, List<String> partNames) {
|
||||
this(id, nameParts, Optional.empty(), Optional.empty(), partNames);
|
||||
public UnboundRelation(RelationId id, List<String> nameParts, List<String> partNames, boolean isTempPart) {
|
||||
this(id, nameParts, Optional.empty(), Optional.empty(), partNames, isTempPart);
|
||||
}
|
||||
|
||||
public UnboundRelation(RelationId id, List<String> nameParts, Optional<GroupExpression> groupExpression,
|
||||
Optional<LogicalProperties> logicalProperties, List<String> partNames) {
|
||||
Optional<LogicalProperties> logicalProperties, List<String> partNames, boolean isTempPart) {
|
||||
super(id, PlanType.LOGICAL_UNBOUND_RELATION, groupExpression, logicalProperties);
|
||||
this.nameParts = nameParts;
|
||||
this.partNames = ImmutableList.copyOf(Objects.requireNonNull(partNames, "partNames should not null"));
|
||||
this.isTempPart = isTempPart;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,12 +85,14 @@ public class UnboundRelation extends LogicalRelation implements Unbound {
|
||||
|
||||
@Override
|
||||
public Plan withGroupExpression(Optional<GroupExpression> groupExpression) {
|
||||
return new UnboundRelation(id, nameParts, groupExpression, Optional.of(getLogicalProperties()), partNames);
|
||||
return new UnboundRelation(id, nameParts, groupExpression, Optional.of(getLogicalProperties()),
|
||||
partNames, isTempPart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plan withLogicalProperties(Optional<LogicalProperties> logicalProperties) {
|
||||
return new UnboundRelation(id, nameParts, Optional.empty(), logicalProperties, partNames);
|
||||
return new UnboundRelation(id, nameParts, Optional.empty(), logicalProperties, partNames,
|
||||
isTempPart);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,4 +145,8 @@ public class UnboundRelation extends LogicalRelation implements Unbound {
|
||||
public List<String> getPartNames() {
|
||||
return partNames;
|
||||
}
|
||||
|
||||
public boolean isTempPart() {
|
||||
return isTempPart;
|
||||
}
|
||||
}
|
||||
|
||||
@ -434,7 +434,9 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
|
||||
public LogicalPlan visitTableName(TableNameContext ctx) {
|
||||
List<String> tableId = visitMultipartIdentifier(ctx.multipartIdentifier());
|
||||
List<String> partitionNames = new ArrayList<>();
|
||||
boolean isTempPart = false;
|
||||
if (ctx.specifiedPartition() != null) {
|
||||
isTempPart = ctx.specifiedPartition().TEMPORARY() != null;
|
||||
if (ctx.specifiedPartition().identifier() != null) {
|
||||
partitionNames.add(ctx.specifiedPartition().identifier().getText());
|
||||
} else {
|
||||
@ -442,7 +444,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
|
||||
}
|
||||
}
|
||||
LogicalPlan checkedRelation = withCheckPolicy(
|
||||
new UnboundRelation(RelationUtil.newRelationId(), tableId, partitionNames));
|
||||
new UnboundRelation(RelationUtil.newRelationId(), tableId, partitionNames, isTempPart));
|
||||
LogicalPlan plan = withTableAlias(checkedRelation, ctx.tableAlias());
|
||||
for (LateralViewContext lateralViewContext : ctx.lateralView()) {
|
||||
plan = withGenerate(plan, lateralViewContext);
|
||||
|
||||
@ -190,7 +190,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
|
||||
+ "Table: %s is not OLAP table", t.getName()));
|
||||
}
|
||||
return parts.stream().map(name -> {
|
||||
Partition part = ((OlapTable) t).getPartition(name);
|
||||
Partition part = ((OlapTable) t).getPartition(name, unboundRelation.isTempPart());
|
||||
if (part == null) {
|
||||
throw new IllegalStateException(String.format("Partition: %s is not exists", name));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user