diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 1c90d08296bcac4..7c60b61471c729b 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -967,7 +967,8 @@ sampleMethod ; tableSnapshot - : FOR tableSnapshotType=(TIME | VERSION) AS OF valueExpression + : FOR VERSION AS OF version=number + | FOR TIME AS OF time=STRING_LITERAL ; // this rule is used for explicitly capturing wrong identifiers such as test-table, which should actually be `test-table` diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/source/IcebergScanNode.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/source/IcebergScanNode.java index c2fd6eb20b246e5..a45b8981cdf1f96 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/source/IcebergScanNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/source/IcebergScanNode.java @@ -106,7 +106,7 @@ public IcebergScanNode(PlanNodeId id, TupleDescriptor desc, boolean needCheckCol ExternalTable table = (ExternalTable) desc.getTable(); if (table instanceof HMSExternalTable) { source = new IcebergHMSSource((HMSExternalTable) table, desc, columnNameToRange, - ((HMSExternalTable) table).getTableSnapshotVersion()); + ((HMSExternalTable) table).getTableSnapshotVersion()); } else if (table instanceof IcebergExternalTable) { String catalogType = ((IcebergExternalTable) table).getIcebergCatalogType(); switch (catalogType) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java index 53dfb899c857790..166516c22a53383 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java @@ -60,27 +60,28 @@ public class UnboundRelation extends LogicalRelation implements Unbound, BlockFu // the start and end position of the sql substring(e.g. "t1", "db1.t1", "ctl1.db1.t1") private final Optional> indexInSqlString; - private final TableSnapshot tableSnapshot; + private final Optional tableSnapshot; public UnboundRelation(RelationId id, List nameParts) { this(id, nameParts, Optional.empty(), Optional.empty(), ImmutableList.of(), false, ImmutableList.of(), - ImmutableList.of(), Optional.empty(), Optional.empty(), null, Optional.empty(), null); + ImmutableList.of(), Optional.empty(), Optional.empty(), null, Optional.empty(), Optional.empty()); } public UnboundRelation(RelationId id, List nameParts, List partNames, boolean isTempPart) { this(id, nameParts, Optional.empty(), Optional.empty(), partNames, isTempPart, ImmutableList.of(), - ImmutableList.of(), Optional.empty(), Optional.empty(), null, Optional.empty(), null); + ImmutableList.of(), Optional.empty(), Optional.empty(), null, Optional.empty(), Optional.empty()); } public UnboundRelation(RelationId id, List nameParts, List partNames, boolean isTempPart, List tabletIds, List hints, Optional tableSample, Optional indexName) { this(id, nameParts, Optional.empty(), Optional.empty(), - partNames, isTempPart, tabletIds, hints, tableSample, indexName, null, Optional.empty(), null); + partNames, isTempPart, tabletIds, hints, tableSample, indexName, null, Optional.empty(), + Optional.empty()); } public UnboundRelation(RelationId id, List nameParts, List partNames, boolean isTempPart, List tabletIds, List hints, Optional tableSample, Optional indexName, - TableScanParams scanParams, TableSnapshot tableSnapshot) { + TableScanParams scanParams, Optional tableSnapshot) { this(id, nameParts, Optional.empty(), Optional.empty(), partNames, isTempPart, tabletIds, hints, tableSample, indexName, scanParams, Optional.empty(), tableSnapshot); @@ -90,13 +91,13 @@ public UnboundRelation(RelationId id, List nameParts, Optional logicalProperties, List partNames, boolean isTempPart, List tabletIds, List hints, Optional tableSample, Optional indexName) { this(id, nameParts, groupExpression, logicalProperties, partNames, - isTempPart, tabletIds, hints, tableSample, indexName, null, Optional.empty(), null); + isTempPart, tabletIds, hints, tableSample, indexName, null, Optional.empty(), Optional.empty()); } public UnboundRelation(RelationId id, List nameParts, List partNames, boolean isTempPart, List tabletIds, List hints, Optional tableSample, Optional indexName, TableScanParams scanParams, Optional> indexInSqlString, - TableSnapshot tableSnapshot) { + Optional tableSnapshot) { this(id, nameParts, Optional.empty(), Optional.empty(), partNames, isTempPart, tabletIds, hints, tableSample, indexName, scanParams, indexInSqlString, tableSnapshot); @@ -109,7 +110,7 @@ public UnboundRelation(RelationId id, List nameParts, Optional logicalProperties, List partNames, boolean isTempPart, List tabletIds, List hints, Optional tableSample, Optional indexName, TableScanParams scanParams, Optional> indexInSqlString, - TableSnapshot tableSnapshot) { + Optional tableSnapshot) { 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")); @@ -211,7 +212,7 @@ public Optional> getIndexInSqlString() { return indexInSqlString; } - public TableSnapshot getTableSnapshot() { + public Optional getTableSnapshot() { return tableSnapshot; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 6eef595ead74bc8..c06d90f41a3b6a5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -1365,11 +1365,11 @@ public LogicalPlan visitTableName(TableNameContext ctx) { TableSnapshot tableSnapshot = null; if (ctx.tableSnapshot() != null) { - if (ctx.tableSnapshot().tableSnapshotType.getText().equalsIgnoreCase("time")) { - tableSnapshot = new TableSnapshot(stripQuotes(ctx.tableSnapshot().valueExpression().getText())); + if (ctx.tableSnapshot().TIME() != null) { + tableSnapshot = new TableSnapshot(stripQuotes(ctx.tableSnapshot().time.getText())); tableSnapshot.setType(TableSnapshot.VersionType.TIME); } else { - tableSnapshot = new TableSnapshot(Long.parseLong(ctx.tableSnapshot().valueExpression().getText())); + tableSnapshot = new TableSnapshot(Long.parseLong(ctx.tableSnapshot().number().getText())); tableSnapshot.setType(TableSnapshot.VersionType.VERSION); } } @@ -1379,10 +1379,11 @@ public LogicalPlan visitTableName(TableNameContext ctx) { UnboundRelation relation = forCreateView ? new UnboundRelation(StatementScopeIdGenerator.newRelationId(), tableId, partitionNames, isTempPart, tabletIdLists, relationHints, Optional.ofNullable(tableSample), indexName, scanParams, - Optional.of(Pair.of(identifier.start.getStartIndex(), identifier.stop.getStopIndex())), tableSnapshot) : + Optional.of(Pair.of(identifier.start.getStartIndex(), identifier.stop.getStopIndex())), + Optional.ofNullable(tableSnapshot)) : new UnboundRelation(StatementScopeIdGenerator.newRelationId(), tableId, partitionNames, isTempPart, tabletIdLists, relationHints, - Optional.ofNullable(tableSample), indexName, scanParams, tableSnapshot); + Optional.ofNullable(tableSample), indexName, scanParams, Optional.ofNullable(tableSnapshot)); LogicalPlan checkedRelation = LogicalPlanBuilderAssistant.withCheckPolicy(relation); LogicalPlan plan = withTableAlias(checkedRelation, ctx.tableAlias()); for (LateralViewContext lateralViewContext : ctx.lateralView()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java index 4dd8dd032cbda7e..15da1a9dad08e57 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java @@ -273,7 +273,7 @@ private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelatio return new LogicalSubQueryAlias<>(tableQualifier, hiveViewPlan); } hmsTable.setScanParams(unboundRelation.getScanParams()); - hmsTable.setTableSnapshotVersion(unboundRelation.getTableSnapshot()); + hmsTable.setTableSnapshotVersion(unboundRelation.getTableSnapshot().orElse(null)); return new LogicalFileScan(unboundRelation.getRelationId(), (HMSExternalTable) table, qualifierWithoutTableName, unboundRelation.getTableSample()); case ICEBERG_EXTERNAL_TABLE: