morrySnow commented on code in PR #32867:
URL: https://github.com/apache/doris/pull/32867#discussion_r1540349632
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java:
##########
@@ -216,43 +217,11 @@ private Map<String, Expression> evalOnBE(Map<String,
Map<String, TExpr>> paramMa
if (result.getStatus().getStatusCode() == 0) {
for (Entry<String, InternalService.PExprResultMap> e :
result.getExprResultMapMap().entrySet()) {
for (Entry<String, InternalService.PExprResult> e1 :
e.getValue().getMapMap().entrySet()) {
- PScalarType pScalarType = e1.getValue().getType();
- TPrimitiveType tPrimitiveType =
TPrimitiveType.findByValue(pScalarType.getType());
- PrimitiveType primitiveType =
PrimitiveType.fromThrift(Objects.requireNonNull(tPrimitiveType));
Expression ret;
if (e1.getValue().getSuccess()) {
- DataType type;
- if (PrimitiveType.ARRAY == primitiveType
- || PrimitiveType.MAP == primitiveType
- || PrimitiveType.STRUCT == primitiveType
- || PrimitiveType.AGG_STATE ==
primitiveType) {
- ret = constMap.get(e1.getKey());
- } else {
- if (primitiveType == PrimitiveType.CHAR) {
-
Preconditions.checkState(pScalarType.hasLen(),
- "be return char type without len");
- type =
CharType.createCharType(pScalarType.getLen());
- } else if (primitiveType ==
PrimitiveType.VARCHAR) {
-
Preconditions.checkState(pScalarType.hasLen(),
- "be return varchar type without
len");
- type =
VarcharType.createVarcharType(pScalarType.getLen());
- } else if (primitiveType ==
PrimitiveType.DECIMALV2) {
- type = DecimalV2Type.createDecimalV2Type(
- pScalarType.getPrecision(),
pScalarType.getScale());
- } else if (primitiveType ==
PrimitiveType.DATETIMEV2) {
- type =
DateTimeV2Type.of(pScalarType.getScale());
- } else if (primitiveType ==
PrimitiveType.DECIMAL32
- || primitiveType ==
PrimitiveType.DECIMAL64
- || primitiveType ==
PrimitiveType.DECIMAL128
- || primitiveType ==
PrimitiveType.DECIMAL256) {
- type =
DecimalV3Type.createDecimalV3TypeLooseCheck(
- pScalarType.getPrecision(),
pScalarType.getScale());
- } else {
- type =
DataType.fromCatalogType(ScalarType.createType(
-
PrimitiveType.fromThrift(tPrimitiveType)));
- }
- ret =
Literal.of(e1.getValue().getContent()).castTo(type);
- }
+ PTypeDesc pTypeDesc = e1.getValue().getPType();
Review Comment:
why not use a tree to represent complex type? what's advantage of list? How
to express if the elements in complex types support non-null in the future
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java:
##########
@@ -216,43 +217,11 @@ private Map<String, Expression> evalOnBE(Map<String,
Map<String, TExpr>> paramMa
if (result.getStatus().getStatusCode() == 0) {
for (Entry<String, InternalService.PExprResultMap> e :
result.getExprResultMapMap().entrySet()) {
for (Entry<String, InternalService.PExprResult> e1 :
e.getValue().getMapMap().entrySet()) {
- PScalarType pScalarType = e1.getValue().getType();
- TPrimitiveType tPrimitiveType =
TPrimitiveType.findByValue(pScalarType.getType());
- PrimitiveType primitiveType =
PrimitiveType.fromThrift(Objects.requireNonNull(tPrimitiveType));
Expression ret;
if (e1.getValue().getSuccess()) {
- DataType type;
- if (PrimitiveType.ARRAY == primitiveType
- || PrimitiveType.MAP == primitiveType
- || PrimitiveType.STRUCT == primitiveType
- || PrimitiveType.AGG_STATE ==
primitiveType) {
- ret = constMap.get(e1.getKey());
- } else {
- if (primitiveType == PrimitiveType.CHAR) {
-
Preconditions.checkState(pScalarType.hasLen(),
- "be return char type without len");
- type =
CharType.createCharType(pScalarType.getLen());
- } else if (primitiveType ==
PrimitiveType.VARCHAR) {
-
Preconditions.checkState(pScalarType.hasLen(),
- "be return varchar type without
len");
- type =
VarcharType.createVarcharType(pScalarType.getLen());
- } else if (primitiveType ==
PrimitiveType.DECIMALV2) {
- type = DecimalV2Type.createDecimalV2Type(
- pScalarType.getPrecision(),
pScalarType.getScale());
- } else if (primitiveType ==
PrimitiveType.DATETIMEV2) {
- type =
DateTimeV2Type.of(pScalarType.getScale());
- } else if (primitiveType ==
PrimitiveType.DECIMAL32
- || primitiveType ==
PrimitiveType.DECIMAL64
- || primitiveType ==
PrimitiveType.DECIMAL128
- || primitiveType ==
PrimitiveType.DECIMAL256) {
- type =
DecimalV3Type.createDecimalV3TypeLooseCheck(
- pScalarType.getPrecision(),
pScalarType.getScale());
- } else {
- type =
DataType.fromCatalogType(ScalarType.createType(
-
PrimitiveType.fromThrift(tPrimitiveType)));
- }
- ret =
Literal.of(e1.getValue().getContent()).castTo(type);
- }
+ PTypeDesc pTypeDesc = e1.getValue().getPType();
+ DataType type =
convertToNereidsType(pTypeDesc.getTypesList(), 0).key();
+ ret =
Literal.of(e1.getValue().getContent()).castTo(type);
Review Comment:
i think, we'd better refactor fold constant on be. we should not rely on
string as ser/de infra. we should use a better way to ser/de literal expression
just like what we do in thrift.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]