未验证 提交 b63c4aba 编写于 作者: L Liao Lanyu 提交者: GitHub

[IOTDB-4010] Use FilterAndProjectOperator for query that does not contain non-mappable UDF (#6929)

上级 6421f4ea
......@@ -56,6 +56,9 @@ public class FilterAndProjectOperator implements ProcessOperator {
private final OperatorContext operatorContext;
// false when we only need to do projection
private final boolean hasFilter;
public FilterAndProjectOperator(
OperatorContext operatorContext,
Operator inputOperator,
......@@ -65,7 +68,8 @@ public class FilterAndProjectOperator implements ProcessOperator {
List<ColumnTransformer> commonTransformerList,
List<LeafColumnTransformer> projectLeafColumnTransformerList,
List<ColumnTransformer> projectOutputTransformerList,
boolean hasNonMappableUDF) {
boolean hasNonMappableUDF,
boolean hasFilter) {
this.operatorContext = operatorContext;
this.inputOperator = inputOperator;
this.filterLeafColumnTransformerList = filterLeafColumnTransformerList;
......@@ -75,6 +79,7 @@ public class FilterAndProjectOperator implements ProcessOperator {
this.projectOutputTransformerList = projectOutputTransformerList;
this.hasNonMappableUDF = hasNonMappableUDF;
this.filterTsBlockBuilder = new TsBlockBuilder(8, filterOutputDataTypes);
this.hasFilter = hasFilter;
}
@Override
......@@ -89,6 +94,10 @@ public class FilterAndProjectOperator implements ProcessOperator {
return null;
}
if (!hasFilter) {
return getTransformedTsBlock(input);
}
TsBlock filterResult = getFilterTsBlock(input);
// contains non-mappable udf, we leave calculation for TransformOperator
......
......@@ -431,6 +431,9 @@ public class FunctionExpression extends Expression {
@Override
public boolean isMappable(TypeProvider typeProvider) {
if (isBuiltInAggregationFunctionExpression) {
return false;
}
return new UDTFInformationInferrer(functionName)
.getAccessStrategy(
expressions.stream().map(Expression::toString).collect(Collectors.toList()),
......
......@@ -796,9 +796,62 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
final Operator inputOperator = generateOnlyChildOperator(node, context);
final List<TSDataType> inputDataTypes = getInputColumnTypes(node, context.getTypeProvider());
final Map<String, List<InputLocation>> inputLocations = makeLayout(node);
final Expression[] projectExpressions = node.getOutputExpressions();
final TypeProvider typeProvider = context.getTypeProvider();
context.getTimeSliceAllocator().recordExecutionWeight(operatorContext, 1);
boolean hasNonMappableUDF = false;
for (Expression expression : projectExpressions) {
if (!expression.isMappable(typeProvider)) {
hasNonMappableUDF = true;
break;
}
}
// Use FilterAndProject Operator when project expressions are all mappable
if (!hasNonMappableUDF) {
// init project UDTFContext
UDTFContext projectContext = new UDTFContext(node.getZoneId());
projectContext.constructUdfExecutors(projectExpressions);
List<ColumnTransformer> projectOutputTransformerList = new ArrayList<>();
Map<Expression, ColumnTransformer> projectExpressionColumnTransformerMap = new HashMap<>();
// records LeafColumnTransformer of project expressions
List<LeafColumnTransformer> projectLeafColumnTransformerList = new ArrayList<>();
ColumnTransformerVisitor visitor = new ColumnTransformerVisitor();
ColumnTransformerVisitor.ColumnTransformerVisitorContext projectColumnTransformerContext =
new ColumnTransformerVisitor.ColumnTransformerVisitorContext(
projectContext,
typeProvider,
projectLeafColumnTransformerList,
inputLocations,
projectExpressionColumnTransformerMap,
ImmutableMap.of(),
ImmutableList.of(),
inputDataTypes,
inputLocations.size());
for (Expression expression : projectExpressions) {
projectOutputTransformerList.add(
visitor.process(expression, projectColumnTransformerContext));
}
return new FilterAndProjectOperator(
operatorContext,
inputOperator,
inputDataTypes,
ImmutableList.of(),
null,
ImmutableList.of(),
projectLeafColumnTransformerList,
projectOutputTransformerList,
false,
false);
}
try {
return new TransformOperator(
operatorContext,
......@@ -918,7 +971,8 @@ public class OperatorTreeGenerator extends PlanVisitor<Operator, LocalExecutionP
commonTransformerList,
projectLeafColumnTransformerList,
projectOutputTransformerList,
hasNonMappableUDF);
hasNonMappableUDF,
true);
// Project expressions don't contain Non-Mappable UDF, TransformOperator is not needed
if (!hasNonMappableUDF) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册