forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2953055
commit f0c9882
Showing
10 changed files
with
560 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CancelCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.nereids.trees.plans.commands; | ||
|
||
import org.apache.doris.analysis.Expr; | ||
import org.apache.doris.common.AnalysisException; | ||
import org.apache.doris.nereids.CascadesContext; | ||
import org.apache.doris.nereids.analyzer.UnboundSlot; | ||
import org.apache.doris.nereids.glue.translator.ExpressionTranslator; | ||
import org.apache.doris.nereids.glue.translator.PlanTranslatorContext; | ||
import org.apache.doris.nereids.properties.PhysicalProperties; | ||
import org.apache.doris.nereids.trees.expressions.BinaryOperator; | ||
import org.apache.doris.nereids.trees.expressions.CompoundPredicate; | ||
import org.apache.doris.nereids.trees.expressions.Expression; | ||
import org.apache.doris.nereids.trees.expressions.Like; | ||
import org.apache.doris.nereids.trees.expressions.Not; | ||
import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral; | ||
import org.apache.doris.nereids.trees.plans.PlanType; | ||
import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation; | ||
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; | ||
import org.apache.doris.qe.ConnectContext; | ||
import org.apache.doris.qe.StmtExecutor; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
/** | ||
* cancel load command | ||
*/ | ||
public abstract class CancelCommand extends Command implements ForwardWithSync { | ||
public CancelCommand(PlanType type) { | ||
super(type); | ||
} | ||
|
||
@Override | ||
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return null; | ||
} | ||
|
||
/** | ||
* translate to legacy expr, which do not need complex expression and table columns | ||
*/ | ||
public Expr translateToLegacyExpr(ConnectContext ctx, Expression expression) { | ||
LogicalEmptyRelation plan = new LogicalEmptyRelation( | ||
ConnectContext.get().getStatementContext().getNextRelationId(), | ||
new ArrayList<>()); | ||
CascadesContext cascadesContext = CascadesContext.initContext(ctx.getStatementContext(), plan, | ||
PhysicalProperties.ANY); | ||
PlanTranslatorContext planTranslatorContext = new PlanTranslatorContext(cascadesContext); | ||
return ExpressionTranslator.translate(expression, planTranslatorContext); | ||
} | ||
|
||
/** | ||
* check where filter for cancel load/export commands | ||
* @param expression where clause | ||
* @param supportedColumns only these kind of columns is supported | ||
* @throws AnalysisException analyze exceptions | ||
*/ | ||
public void checkWhereFilter(Expression expression, Map<String, String> supportedColumns) throws AnalysisException { | ||
if (null == expression) { | ||
throw new AnalysisException("Where clause can't be null"); | ||
} else if (expression instanceof Like) { | ||
likeCheck(expression, supportedColumns); | ||
} else if (expression instanceof BinaryOperator) { | ||
binaryCheck(expression, supportedColumns); | ||
} else if (expression instanceof CompoundPredicate) { | ||
compoundCheck(expression, supportedColumns); | ||
} else { | ||
throw new AnalysisException("Only support like/binary/compound predicate"); | ||
} | ||
} | ||
|
||
private void checkColumn(Expression expr, boolean like, Map<String, String> supportedColumns) | ||
throws AnalysisException { | ||
if (!(expr.child(0) instanceof UnboundSlot)) { | ||
throw new AnalysisException("Current only support label and state, invalid column: " | ||
+ expr.child(0).toSql()); | ||
} | ||
String inputCol = ((UnboundSlot) expr.child(0)).getName(); | ||
if (!supportedColumns.keySet().contains(inputCol.toLowerCase())) { | ||
throw new AnalysisException("Current only support label and state, invalid column: " + inputCol); | ||
} | ||
if (!(expr.child(1) instanceof StringLikeLiteral)) { | ||
throw new AnalysisException("Value must be a string"); | ||
} | ||
|
||
String inputValue = ((StringLikeLiteral) expr.child(1)).getStringValue(); | ||
if (Strings.isNullOrEmpty(inputValue)) { | ||
throw new AnalysisException("Value can't be null"); | ||
} | ||
|
||
if (inputCol.equalsIgnoreCase("label")) { | ||
supportedColumns.put("label", inputValue); | ||
} | ||
|
||
if (inputCol.equalsIgnoreCase("state")) { | ||
if (like) { | ||
throw new AnalysisException("Only label can use like"); | ||
} | ||
supportedColumns.put("state", inputValue); | ||
} | ||
} | ||
|
||
private void likeCheck(Expression expr, Map<String, String> supportedColumns) throws AnalysisException { | ||
checkColumn(expr, true, supportedColumns); | ||
} | ||
|
||
private void binaryCheck(Expression expr, Map<String, String> supportedColumns) throws AnalysisException { | ||
checkColumn(expr, false, supportedColumns); | ||
} | ||
|
||
private void compoundCheck(Expression expr, Map<String, String> supportedColumns) throws AnalysisException { | ||
// current only support label and state | ||
if (expr instanceof Not) { | ||
throw new AnalysisException("Current not support NOT operator"); | ||
} | ||
for (int i = 0; i < 2; i++) { | ||
Expression child = expr.child(i); | ||
if (child instanceof CompoundPredicate) { | ||
throw new AnalysisException("Current not support nested clause"); | ||
} else if (child instanceof Like) { | ||
likeCheck(child, supportedColumns); | ||
} else if (child instanceof BinaryOperator) { | ||
binaryCheck(child, supportedColumns); | ||
} else { | ||
throw new AnalysisException("Only support like/binary predicate"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.