Skip to content

Commit

Permalink
optimize antlr expr
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbutao committed May 14, 2024
1 parent afe401d commit f18eb36
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<Integer, Integer>> indexInSqlString;

private final TableSnapshot tableSnapshot;
private final Optional<TableSnapshot> tableSnapshot;

public UnboundRelation(RelationId id, List<String> 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<String> nameParts, List<String> 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<String> nameParts, List<String> partNames, boolean isTempPart,
List<Long> tabletIds, List<String> hints, Optional<TableSample> tableSample, Optional<String> 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<String> nameParts, List<String> partNames, boolean isTempPart,
List<Long> tabletIds, List<String> hints, Optional<TableSample> tableSample, Optional<String> indexName,
TableScanParams scanParams, TableSnapshot tableSnapshot) {
TableScanParams scanParams, Optional<TableSnapshot> tableSnapshot) {
this(id, nameParts, Optional.empty(), Optional.empty(),
partNames, isTempPart, tabletIds, hints, tableSample, indexName, scanParams, Optional.empty(),
tableSnapshot);
Expand All @@ -90,13 +91,13 @@ public UnboundRelation(RelationId id, List<String> nameParts, Optional<GroupExpr
Optional<LogicalProperties> logicalProperties, List<String> partNames, boolean isTempPart,
List<Long> tabletIds, List<String> hints, Optional<TableSample> tableSample, Optional<String> 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<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,
TableSnapshot tableSnapshot) {
Optional<TableSnapshot> tableSnapshot) {
this(id, nameParts, Optional.empty(), Optional.empty(),
partNames, isTempPart, tabletIds, hints, tableSample, indexName, scanParams, indexInSqlString,
tableSnapshot);
Expand All @@ -109,7 +110,7 @@ public UnboundRelation(RelationId id, List<String> nameParts, Optional<GroupExpr
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,
TableSnapshot tableSnapshot) {
Optional<TableSnapshot> 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"));
Expand Down Expand Up @@ -211,7 +212,7 @@ public Optional<Pair<Integer, Integer>> getIndexInSqlString() {
return indexInSqlString;
}

public TableSnapshot getTableSnapshot() {
public Optional<TableSnapshot> getTableSnapshot() {
return tableSnapshot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f18eb36

Please sign in to comment.