Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
vinlee19 committed Nov 8, 2024
1 parent cd42fcc commit 321564d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ public LogicalPlan visitLoad(DorisParser.LoadContext ctx) {
List<String> tableName = RelationUtil.getQualifierName(ConnectContext.get(), nameParts);
List<String> colNames = (ddc.columns == null ? ImmutableList.of() : visitIdentifierList(ddc.columns));
List<String> columnsFromPath = (ddc.columnsFromPath == null ? ImmutableList.of()
: visitIdentifierList(ddc.columnsFromPath.identifierList()));
: visitIdentifierList(ddc.columnsFromPath.identifierList()));
List<String> partitions = ddc.partition == null ? ImmutableList.of() : visitIdentifierList(ddc.partition);
// TODO: multi location
List<String> multiFilePaths = new ArrayList<>();
Expand All @@ -1236,16 +1236,16 @@ public LogicalPlan visitLoad(DorisParser.LoadContext ctx) {
}

LoadTask.MergeType mergeType = ddc.mergeType() == null ? LoadTask.MergeType.APPEND
: LoadTask.MergeType.valueOf(ddc.mergeType().getText());
: LoadTask.MergeType.valueOf(ddc.mergeType().getText());

Optional<String> fileFormat = ddc.format == null ? Optional.empty()
: Optional.of(visitIdentifierOrText(ddc.format));
Optional<String> separator = ddc.separator == null ? Optional.empty() : Optional.of(ddc.separator.getText()
.substring(1, ddc.separator.getText().length() - 1));
.substring(1, ddc.separator.getText().length() - 1));
Optional<String> comma = ddc.comma == null ? Optional.empty() : Optional.of(ddc.comma.getText()
.substring(1, ddc.comma.getText().length() - 1));
.substring(1, ddc.comma.getText().length() - 1));
Map<String, String> dataProperties = ddc.propertyClause() == null ? new HashMap<>()
: visitPropertyClause(ddc.propertyClause());
: visitPropertyClause(ddc.propertyClause());
dataDescriptions.add(new BulkLoadDataDesc(
tableName,
partitions,
Expand Down Expand Up @@ -1321,8 +1321,8 @@ public LogicalSubQueryAlias<Plan> visitAliasQuery(AliasQueryContext ctx) {
LogicalPlan queryPlan = plan(ctx.query());
Optional<List<String>> columnNames = optionalVisit(ctx.columnAliases(), () ->
ctx.columnAliases().identifier().stream()
.map(RuleContext::getText)
.collect(ImmutableList.toImmutableList())
.map(RuleContext::getText)
.collect(ImmutableList.toImmutableList())
);
return new LogicalSubQueryAlias<>(ctx.identifier().getText(), columnNames, queryPlan);
});
Expand Down Expand Up @@ -1741,7 +1741,7 @@ public Expression visitComparison(ComparisonContext ctx) {
return new NullSafeEqual(left, right);
default:
throw new ParseException("Unsupported comparison expression: "
+ operator.getSymbol().getText(), ctx);
+ operator.getSymbol().getText(), ctx);
}
});
}
Expand Down Expand Up @@ -1986,7 +1986,7 @@ public Expression visitDate_add(Date_addContext ctx) {
Expression timeStamp = (Expression) visit(ctx.timestamp);
Expression amount = (Expression) visit(ctx.unitsAmount);
if (ctx.unit == null) {
// use "DAY" as unit by default
//use "DAY" as unit by default
return new DaysAdd(timeStamp, amount);
}

Expand Down Expand Up @@ -2048,7 +2048,7 @@ public Expression visitDate_sub(Date_subContext ctx) {
Expression timeStamp = (Expression) visit(ctx.timestamp);
Expression amount = (Expression) visit(ctx.unitsAmount);
if (ctx.unit == null) {
// use "DAY" as unit by default
//use "DAY" as unit by default
return new DaysSub(timeStamp, amount);
}

Expand Down Expand Up @@ -2180,11 +2180,11 @@ public Expression visitDoublePipes(DorisParser.DoublePipesContext ctx) {
/**
* Create a value based [[CaseWhen]] expression. This has the following SQL form:
* {{{
* CASE [expression]
* WHEN [value] THEN [expression]
* ...
* ELSE [expression]
* END
* CASE [expression]
* WHEN [value] THEN [expression]
* ...
* ELSE [expression]
* END
* }}}
*/
@Override
Expand Down Expand Up @@ -2357,8 +2357,8 @@ private WindowExpression withWindowSpec(WindowSpecContext ctx, Expression functi
List<OrderExpression> orderKeyList = Lists.newArrayList();
if (ctx.sortClause() != null) {
orderKeyList = visit(ctx.sortClause().sortItem(), OrderKey.class).stream()
.map(orderKey -> new OrderExpression(orderKey))
.collect(Collectors.toList());
.map(orderKey -> new OrderExpression(orderKey))
.collect(Collectors.toList());
}

if (ctx.windowFrame() != null) {
Expand Down Expand Up @@ -2667,8 +2667,8 @@ public List<String> visitIdentifierList(IdentifierListContext ctx) {
@Override
public List<String> visitIdentifierSeq(IdentifierSeqContext ctx) {
return ctx.ident.stream()
.map(RuleContext::getText)
.collect(ImmutableList.toImmutableList());
.map(RuleContext::getText)
.collect(ImmutableList.toImmutableList());
}

@Override
Expand Down Expand Up @@ -2849,10 +2849,10 @@ public PartitionTableInfo visitPartitionTable(DorisParser.PartitionTableContext
})
.collect(ImmutableList.toImmutableList());
return new PartitionTableInfo(
isAutoPartition,
ctx.RANGE() != null ? "RANGE" : "LIST",
ctx.partitions != null ? visitPartitionsDef(ctx.partitions) : null,
partitionList);
isAutoPartition,
ctx.RANGE() != null ? "RANGE" : "LIST",
ctx.partitions != null ? visitPartitionsDef(ctx.partitions) : null,
partitionList);
}

@Override
Expand Down Expand Up @@ -2958,9 +2958,9 @@ public IndexDefinition visitIndexDef(IndexDefContext ctx) {
List<String> indexCols = visitIdentifierList(ctx.cols);
Map<String, String> properties = visitPropertyItemList(ctx.properties);
String indexType = ctx.indexType != null ? ctx.indexType.getText().toUpperCase() : null;
// comment should remove '\' and '(") at the beginning and end
//comment should remove '\' and '(") at the beginning and end
String comment = ctx.comment == null ? "" : LogicalPlanBuilderAssistant.escapeBackSlash(
ctx.comment.getText().substring(1, ctx.STRING_LITERAL().getText().length() - 1));
ctx.comment.getText().substring(1, ctx.STRING_LITERAL().getText().length() - 1));
// change BITMAP index to INVERTED index
if (Config.enable_create_bitmap_index_as_inverted_index
&& "BITMAP".equalsIgnoreCase(indexType)) {
Expand Down Expand Up @@ -3409,7 +3409,7 @@ public Object visitCommentRelationHint(CommentRelationHintContext ctx) {
}

protected LogicalPlan withProjection(LogicalPlan input, SelectColumnClauseContext selectCtx,
Optional<AggClauseContext> aggCtx, boolean isDistinct) {
Optional<AggClauseContext> aggCtx, boolean isDistinct) {
return ParserUtils.withOrigin(selectCtx, () -> {
if (aggCtx.isPresent()) {
if (isDistinct) {
Expand Down Expand Up @@ -3454,12 +3454,12 @@ private LogicalPlan withRelations(LogicalPlan inputPlan, List<RelationContext> r

private LogicalPlan withFilter(LogicalPlan input, Optional<WhereClauseContext> whereCtx) {
return input.optionalMap(whereCtx, () ->
new LogicalFilter<>(ExpressionUtils.extractConjunctionToSet(
getExpression(whereCtx.get().booleanExpression())), input));
new LogicalFilter<>(ExpressionUtils.extractConjunctionToSet(
getExpression(whereCtx.get().booleanExpression())), input));
}

private LogicalPlan withAggregate(LogicalPlan input, SelectColumnClauseContext selectCtx,
Optional<AggClauseContext> aggCtx) {
Optional<AggClauseContext> aggCtx) {
return input.optionalMap(aggCtx, () -> {
GroupingElementContext groupingElementContext = aggCtx.get().groupingElement();
List<NamedExpression> namedExpressions = getNamedExpressions(selectCtx.namedExpressionSeq());
Expand Down Expand Up @@ -3513,22 +3513,22 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
break;
case DorisParser.LIKE:
outExpression = new Like(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
case DorisParser.RLIKE:
case DorisParser.REGEXP:
outExpression = new Regexp(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
case DorisParser.IN:
if (ctx.query() == null) {
outExpression = new InPredicate(
valueExpression,
withInList(ctx)
valueExpression,
withInList(ctx)
);
} else {
outExpression = new InSubquery(
Expand All @@ -3552,38 +3552,38 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
case DorisParser.MATCH:
case DorisParser.MATCH_ANY:
outExpression = new MatchAny(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
case DorisParser.MATCH_ALL:
outExpression = new MatchAll(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
case DorisParser.MATCH_PHRASE:
outExpression = new MatchPhrase(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
case DorisParser.MATCH_PHRASE_PREFIX:
outExpression = new MatchPhrasePrefix(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
case DorisParser.MATCH_REGEXP:
outExpression = new MatchRegexp(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
case DorisParser.MATCH_PHRASE_EDGE:
outExpression = new MatchPhraseEdge(
valueExpression,
getExpression(ctx.pattern)
valueExpression,
getExpression(ctx.pattern)
);
break;
default:
Expand Down Expand Up @@ -4010,7 +4010,6 @@ public SetDefaultStorageVaultCommand visitSetDefaultStorageVault(SetDefaultStora

@Override
public Object visitRefreshCatalog(RefreshCatalogContext ctx) {

if (ctx.name != null) {
String catalogName = ctx.name.getText();
Map<String, String> properties = visitPropertyClause(ctx.propertyClause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,18 @@ public RefreshCatalogCommand(String catalogName, Map<String, String> properties)
this.properties = properties;
}

private void checkCatalogRules() throws AnalysisException {
private void validate() throws AnalysisException {
Util.checkCatalogAllRules(catalogName);
if (catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
throw new AnalysisException("Internal catalog name can't be refresh.");
}
}

private void checkCatalogAccess() throws AnalysisException {
if (!Env.getCurrentEnv().getAccessManager().checkCtlPriv(
ConnectContext.get(), catalogName, PrivPredicate.SHOW)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED_ERROR,
PrivPredicate.SHOW.getPrivs().toString(), catalogName);
}
}

private void setInvalidCache() {
if (properties != null) {
// Set to false only if user set the property "invalid_cache"="false"
invalidCache = !(properties.get(INVALID_CACHE) != null && properties.get(INVALID_CACHE)
Expand All @@ -82,7 +78,6 @@ private void setInvalidCache() {
}

private void refreshCatalogInternal(CatalogIf catalog) {

if (!catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
((ExternalCatalog) catalog).onRefreshCache(invalidCache);
LOG.info("refresh catalog {} with invalidCache {}", catalogName, invalidCache);
Expand All @@ -103,9 +98,7 @@ public void handleRefreshCatalog() throws AnalysisException {

@Override
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
checkCatalogRules();
checkCatalogAccess();
setInvalidCache();
validate();
handleRefreshCatalog();
}

Expand Down

0 comments on commit 321564d

Please sign in to comment.