Skip to content

Commit

Permalink
add is_nereids field
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Apr 3, 2024
1 parent bd2784d commit 2ed6381
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
5 changes: 3 additions & 2 deletions be/src/runtime/fold_constant_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ Status FoldConstantExecutor::fold_constant_vexpr(const TFoldConstantParams& para
const auto& column_ptr = tmp_block.get_by_position(result_column).column;
const auto& column_type = tmp_block.get_by_position(result_column).type;
// 4 from fe: Config.be_exec_version maybe need remove after next version, now in 2.1
if (_runtime_state->be_exec_version() >= 4) {
if (_runtime_state->be_exec_version() >= 4 && params.is_nereids) {
auto* p_type_desc = expr_result.mutable_type_desc();
auto* p_values = expr_result.mutable_result_content();
res_type.to_protobuf(p_type_desc);
auto datatype_serde = column_type->get_serde();
RETURN_IF_ERROR(datatype_serde->write_column_to_pb(
*column_ptr->convert_to_full_column_if_const(), *p_values, 0, 1));
expr_result.set_success(true);
expr_result.set_content("");
// after refactor, this field is useless, but it's required
expr_result.set_content("ERROR");
expr_result.mutable_type()->set_type(t_type);
pexpr_result_map.mutable_map()->insert({n.first, expr_result});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.Cast;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.generator.TableGeneratingFunction;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Sleep;
import org.apache.doris.nereids.trees.expressions.literal.ArrayLiteral;
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
Expand Down Expand Up @@ -113,8 +114,8 @@ public class FoldConstantRuleOnBE implements ExpressionPatternRuleFactory {
public List<ExpressionPatternMatcher<? extends Expression>> buildRules() {
return ImmutableList.of(
root(Expression.class)
.whenCtx(FoldConstantRuleOnBE::isEnableFoldByBe)
.thenApply(FoldConstantRuleOnBE::foldByBE)
.whenCtx(FoldConstantRuleOnBE::isEnableFoldByBe)
.thenApply(FoldConstantRuleOnBE::foldByBE)
);
}

Expand Down Expand Up @@ -187,10 +188,10 @@ private static void collectConst(Expression expr, Map<String, Expression> constM
// eg: avg_state(1) return is agg function serialize data
// and some type can't find a literal to represent
if (expr.getDataType().isAggStateType() || expr.getDataType().isObjectType()
|| expr.getDataType().isVariantType() || expr.getDataType().isTimeV2Type()) {
|| expr.getDataType().isVariantType() || expr.getDataType().isTimeLikeType()) {
return;
}
if (skipSleepFunction(expr)) {
if (skipSleepFunction(expr) || (expr instanceof TableGeneratingFunction)) {
return;
}
String id = idGenerator.getNextId().toString();
Expand Down Expand Up @@ -256,6 +257,7 @@ private static Map<String, Expression> evalOnBE(Map<String, Map<String, TExpr>>
tParams.setVecExec(true);
tParams.setQueryOptions(tQueryOptions);
tParams.setQueryId(context.queryId());
tParams.setIsNereids(true);

// TODO: will be delete the debug log after find problem of timeout.
LOG.info("fold query {} ", DebugUtil.printId(context.queryId()));
Expand Down Expand Up @@ -436,19 +438,25 @@ public static List<Literal> getResultExpression(DataType type, PValues resultCon
resultContent.getChildElement(i));
List<Literal> valueLiteral = getResultExpression(mapType.getValueType(),
resultContent.getChildElement(i + 1));
MapLiteral mapLiteral = new MapLiteral(keyLiteral, valueLiteral);
MapLiteral mapLiteral = new MapLiteral(keyLiteral, valueLiteral, mapType);
res.add(mapLiteral);
}
} else if (type.isStructType()) {
StructType structType = (StructType) type;
int childCount = resultContent.getChildElementCount();
List<Literal> fields = new ArrayList<>(childCount);
List<List<Literal>> allFields = new ArrayList<>();
for (int i = 0; i < childCount; ++i) {
fields.add(getResultExpression(structType.getFields().get(i).getDataType(),
resultContent.getChildElement(i)).get(0));
allFields.add(getResultExpression(structType.getFields().get(i).getDataType(),
resultContent.getChildElement(i)));
}
for (int i = 0; i < allFields.get(0).size(); ++i) {
List<Literal> fields = new ArrayList<>();
for (int child = 0; child < childCount; ++child) {
fields.add(allFields.get(child).get(i));
}
StructLiteral structLiteral = new StructLiteral(fields, structType);
res.add(structLiteral);
}
StructLiteral structLiteral = new StructLiteral(fields);
res.add(structLiteral);
} else {
LOG.warn("the type: {} is not support, should implement it", type.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public MapLiteral(List<Literal> keys, List<Literal> values) {
this(keys, values, computeDataType(keys, values));
}

private MapLiteral(List<Literal> keys, List<Literal> values, DataType dataType) {
/**
* create MAP Literal with keys, values and datatype
*/
public MapLiteral(List<Literal> keys, List<Literal> values, DataType dataType) {
super(dataType);
this.keys = ImmutableList.copyOf(Objects.requireNonNull(keys, "keys should not be null"));
this.values = ImmutableList.copyOf(Objects.requireNonNull(values, "values should not be null"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public StructLiteral(List<Literal> fields) {
this(fields, computeDataType(fields));
}

private StructLiteral(List<Literal> fields, DataType dataType) {
/**
* create Struct Literal with fields and datatype
*/
public StructLiteral(List<Literal> fields, DataType dataType) {
super(dataType);
this.fields = ImmutableList.copyOf(Objects.requireNonNull(fields, "fields should not be null"));
Preconditions.checkArgument(dataType instanceof StructType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ private Map<String, Map<String, Expr>> calcConstExpr(Map<String, Map<String, TEx
tParams.setVecExec(true);
tParams.setQueryOptions(tQueryOptions);
tParams.setQueryId(context.queryId());
tParams.setIsNereids(false);

Future<InternalService.PConstantExprResult> future
= BackendServiceProxy.getInstance().foldConstantExpr(brpcAddress, tParams);
Expand Down
1 change: 1 addition & 0 deletions gensrc/thrift/PaloInternalService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ struct TFoldConstantParams {
3: optional bool vec_exec
4: optional TQueryOptions query_options
5: optional Types.TUniqueId query_id
6: optional bool is_nereids
}

// TransmitData
Expand Down

0 comments on commit 2ed6381

Please sign in to comment.