[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));
|
||||
}
|
||||
|
||||
@ -12,3 +12,12 @@
|
||||
-- !sql --
|
||||
7 1 3
|
||||
|
||||
-- !sql --
|
||||
16 1234 t
|
||||
|
||||
-- !sql --
|
||||
16 1234 t
|
||||
|
||||
-- !sql --
|
||||
16 1234 t
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
suite("query_on_specific_partition") {
|
||||
sql "SET enable_vectorized_engine=true"
|
||||
sql "SET enable_nereids_planner=true"
|
||||
sql "SET enable_fallback_to_original_planner=false"
|
||||
|
||||
sql """
|
||||
DROP TABLE IF EXISTS t_p;
|
||||
@ -41,8 +40,13 @@ suite("query_on_specific_partition") {
|
||||
);
|
||||
"""
|
||||
|
||||
sql """ALTER TABLE t_p ADD TEMPORARY PARTITION tp1 VALUES [("15"), ("20"));"""
|
||||
|
||||
sql "INSERT INTO t_p VALUES(1, 1,'1')"
|
||||
sql "INSERT INTO t_p VALUES(7, 1,'3')"
|
||||
sql "INSERT INTO t_p TEMPORARY PARTITION(tp1) values(16,1234, 't');"
|
||||
|
||||
sql "SET enable_fallback_to_original_planner=false"
|
||||
|
||||
qt_sql "SELECT * FROM t_p PARTITION p1"
|
||||
|
||||
@ -51,4 +55,10 @@ suite("query_on_specific_partition") {
|
||||
order_qt_sql "SELECT * FROM t_p PARTITIONS (p2, p1)"
|
||||
|
||||
order_qt_sql "SELECT * FROM t_p PARTITIONS (p2, p1) WHERE id > 1"
|
||||
|
||||
qt_sql """select * from t_p temporary partition(tp1);"""
|
||||
|
||||
qt_sql """select * from t_p temporary partitions(tp1);"""
|
||||
|
||||
qt_sql """select * from t_p temporary partition tp1;"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user