Skip to content
Merged
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
17 changes: 15 additions & 2 deletions fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ statementBase
(ENGINE EQ engine=identifier)?
((AGGREGATE | UNIQUE | DUPLICATE) KEY keys=identifierList (CLUSTER BY clusterKeys=identifierList)?)?
(COMMENT STRING_LITERAL)?
((autoPartition=AUTO)? PARTITION BY (RANGE | LIST) (partitionKeys=identifierList | partitionExpr=functionCallExpression)
LEFT_PAREN (partitions=partitionsDef)? RIGHT_PAREN)?
(partition=partitionTable)?
(DISTRIBUTED BY (HASH hashKeys=identifierList | RANDOM) (BUCKETS (INTEGER_VALUE | autoBucket=AUTO))?)?
(ROLLUP LEFT_PAREN rollupDefs RIGHT_PAREN)?
properties=propertyClause?
Expand Down Expand Up @@ -128,6 +127,19 @@ partitionSpec
// | PARTITIONS WITH RECENT
;

partitionTable
: ((autoPartition=AUTO)? PARTITION BY (RANGE | LIST)? partitionList=identityOrFunctionList
(LEFT_PAREN (partitions=partitionsDef)? RIGHT_PAREN))
;

identityOrFunctionList
: LEFT_PAREN identityOrFunction (COMMA partitions+=identityOrFunction)* RIGHT_PAREN
;

identityOrFunction
: (identifier | functionCallExpression)
;

dataDesc
: ((WITH)? mergeType)? DATA INFILE LEFT_PAREN filePaths+=STRING_LITERAL (COMMA filePath+=STRING_LITERAL)* RIGHT_PAREN
INTO TABLE tableName=multipartIdentifier
Expand Down Expand Up @@ -731,6 +743,7 @@ primaryExpression
| primaryExpression COLLATE (identifier | STRING_LITERAL | DEFAULT) #collate
;


functionCallExpression
: functionIdentifier
LEFT_PAREN (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

// to describe the key list partition's information in create table stmt
public class ListPartitionDesc extends PartitionDesc {
Expand All @@ -37,6 +38,9 @@ public ListPartitionDesc(List<String> partitionColNames,
super(partitionColNames, allPartitionDescs);
type = PartitionType.LIST;
this.isAutoCreatePartitions = false;
this.partitionExprs = new ArrayList<>(partitionColNames.stream()
.map(col -> new SlotRef(null, col))
.collect(Collectors.toList()));
}

public ListPartitionDesc(ArrayList<Expr> exprs, List<String> partitionColNames,
Expand Down Expand Up @@ -68,12 +72,12 @@ public String toSql() {
StringBuilder sb = new StringBuilder();
sb.append("PARTITION BY LIST(");
int idx = 0;
for (String column : partitionColNames) {
if (idx != 0) {
for (Expr e : partitionExprs) {
if (idx > 0) {
sb.append(", ");
}
sb.append("`").append(column).append("`");
idx++;
sb.append(e.toSql());
}
sb.append(")\n(\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

// to describe the key range partition's information in create table stmt
public class RangePartitionDesc extends PartitionDesc {
Expand All @@ -35,6 +36,9 @@ public RangePartitionDesc(List<String> partitionColNames,
List<AllPartitionDesc> allPartitionDescs) throws AnalysisException {
super(partitionColNames, allPartitionDescs);
type = org.apache.doris.catalog.PartitionType.RANGE;
this.partitionExprs = new ArrayList<>(partitionColNames.stream()
.map(col -> new SlotRef(null, col))
.collect(Collectors.toList()));
this.isAutoCreatePartitions = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2431,33 +2431,13 @@ public LogicalPlan visitCreateTable(CreateTableContext ctx) {
// NOTICE: we should not generate immutable map here, because it will be modified when analyzing.
? Maps.newHashMap(visitPropertyClause(ctx.extProperties))
: Maps.newHashMap();
String partitionType = null;
if (ctx.PARTITION() != null) {
partitionType = ctx.RANGE() != null ? "RANGE" : "LIST";
}
boolean isAutoPartition = ctx.autoPartition != null;
ImmutableList.Builder<Expression> autoPartitionExpr = new ImmutableList.Builder<>();
if (isAutoPartition) {
if (ctx.RANGE() != null) {
// AUTO PARTITION BY RANGE FUNC_CALL_EXPR
if (ctx.partitionExpr != null) {
autoPartitionExpr.add(visitFunctionCallExpression(ctx.partitionExpr));
} else {
throw new AnalysisException(
"AUTO PARTITION BY RANGE must provide a function expr");
}
} else {
// AUTO PARTITION BY LIST(`partition_col`)
if (ctx.partitionKeys != null) {
// only support one column in auto partition
autoPartitionExpr.addAll(visitIdentifierList(ctx.partitionKeys).stream()
.distinct().map(name -> UnboundSlot.quoted(name))
.collect(Collectors.toList()));
} else {
throw new AnalysisException(
"AUTO PARTITION BY List must provide a partition column");
}
}

// solve partition by
PartitionTableInfo partitionInfo;
if (ctx.partition != null) {
partitionInfo = (PartitionTableInfo) ctx.partitionTable().accept(this);
} else {
partitionInfo = PartitionTableInfo.EMPTY;
}

if (ctx.columnDefs() != null) {
Expand All @@ -2476,11 +2456,7 @@ public LogicalPlan visitCreateTable(CreateTableContext ctx) {
keysType,
ctx.keys != null ? visitIdentifierList(ctx.keys) : ImmutableList.of(),
comment,
isAutoPartition,
autoPartitionExpr.build(),
partitionType,
ctx.partitionKeys != null ? visitIdentifierList(ctx.partitionKeys) : null,
ctx.partitions != null ? visitPartitionsDef(ctx.partitions) : null,
partitionInfo,
desc,
ctx.rollupDefs() != null ? visitRollupDefs(ctx.rollupDefs()) : ImmutableList.of(),
properties,
Expand All @@ -2498,11 +2474,7 @@ public LogicalPlan visitCreateTable(CreateTableContext ctx) {
keysType,
ctx.keys != null ? visitIdentifierList(ctx.keys) : ImmutableList.of(),
comment,
isAutoPartition,
autoPartitionExpr.build(),
partitionType,
ctx.partitionKeys != null ? visitIdentifierList(ctx.partitionKeys) : null,
ctx.partitions != null ? visitPartitionsDef(ctx.partitions) : null,
partitionInfo,
desc,
ctx.rollupDefs() != null ? visitRollupDefs(ctx.rollupDefs()) : ImmutableList.of(),
properties,
Expand All @@ -2513,6 +2485,26 @@ public LogicalPlan visitCreateTable(CreateTableContext ctx) {
}
}

@Override
public PartitionTableInfo visitPartitionTable(DorisParser.PartitionTableContext ctx) {
boolean isAutoPartition = ctx.autoPartition != null;
ImmutableList<Expression> partitionList = ctx.partitionList.identityOrFunction().stream()
.map(partition -> {
IdentifierContext identifier = partition.identifier();
if (identifier != null) {
return UnboundSlot.quoted(identifier.getText());
} else {
return visitFunctionCallExpression(partition.functionCallExpression());
}
})
.collect(ImmutableList.toImmutableList());
return new PartitionTableInfo(
isAutoPartition,
ctx.RANGE() != null ? "RANGE" : "LIST",
ctx.partitions != null ? visitPartitionsDef(ctx.partitions) : null,
partitionList);
}

@Override
public List<ColumnDefinition> visitColumnDefs(ColumnDefsContext ctx) {
return ctx.cols.stream().map(this::visitColumnDef).collect(Collectors.toList());
Expand Down
Loading