Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ protected ArithmeticExpr(ArithmeticExpr other) {
@Override
public String toString() {
if (children.size() == 1) {
return op.toString() + " " + getChild(0).accept(ExprToSqlVisitor.INSTANCE, ToSqlParams.WITH_TABLE);
return op.toString() + " " + getChild(0);
} else {
return "(" + getChild(0).accept(ExprToSqlVisitor.INSTANCE, ToSqlParams.WITH_TABLE)
+ " " + op.toString()
+ " " + getChild(1).accept(ExprToSqlVisitor.INSTANCE, ToSqlParams.WITH_TABLE) + ")";
return "(" + getChild(0) + " " + op.toString() + " " + getChild(1) + ")";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TAggregateExpr;
import org.apache.doris.thrift.TBoolLiteral;
import org.apache.doris.thrift.TCaseExpr;
import org.apache.doris.thrift.TColumnRef;
Expand Down Expand Up @@ -493,7 +494,7 @@ public Void visitFunctionCallExpr(FunctionCallExpr expr, TExprNode msg) {
if (aggParams == null) {
aggParams = expr.getFnParams();
}
msg.setAggExpr(aggParams.createTAggregateExpr(expr.isMergeAggFn()));
msg.setAggExpr(createTAggregateExprFromFunctionParams(aggParams, expr.isMergeAggFn()));
} else {
msg.node_type = TExprNodeType.FUNCTION_CALL;
}
Expand All @@ -504,6 +505,20 @@ public Void visitFunctionCallExpr(FunctionCallExpr expr, TExprNode msg) {
return null;
}

public TAggregateExpr createTAggregateExprFromFunctionParams(FunctionParams functionParams, boolean isMergeAggFn) {
List<TTypeDesc> paramTypes = new ArrayList<>();
if (functionParams.exprs() != null) {
for (Expr expr : functionParams.exprs()) {
TTypeDesc desc = expr.getType().toThrift();
desc.setIsNullable(expr.isNullable());
paramTypes.add(desc);
}
}
TAggregateExpr aggExpr = new TAggregateExpr(isMergeAggFn);
aggExpr.setParamTypes(paramTypes);
return aggExpr;
}

@Override
public Void visitLambdaFunctionCallExpr(LambdaFunctionCallExpr expr, TExprNode msg) {
msg.node_type = TExprNodeType.LAMBDA_FUNCTION_CALL_EXPR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@

package org.apache.doris.analysis;

import org.apache.doris.thrift.TAggregateExpr;
import org.apache.doris.thrift.TTypeDesc;

import com.google.common.base.Preconditions;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -74,20 +70,6 @@ public FunctionParams clone(List<Expr> children) {
return new FunctionParams(isDistinct(), children);
}

public TAggregateExpr createTAggregateExpr(boolean isMergeAggFn) {
List<TTypeDesc> paramTypes = new ArrayList<>();
if (exprs != null) {
for (Expr expr : exprs) {
TTypeDesc desc = expr.getType().toThrift();
desc.setIsNullable(expr.isNullable());
paramTypes.add(desc);
}
}
TAggregateExpr aggExpr = new TAggregateExpr(isMergeAggFn);
aggExpr.setParamTypes(paramTypes);
return aggExpr;
}

public boolean isStar() {
return isStar;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ public static List<Expr> getOrderByExprs(List<OrderByElement> src) {
return result;
}

public String toSql() {
@Override
public String toString() {
StringBuilder strBuilder = new StringBuilder();
strBuilder.append(expr.accept(ExprToSqlVisitor.INSTANCE, ToSqlParams.WITH_TABLE));
strBuilder.append(expr);
strBuilder.append(isAsc ? " ASC" : " DESC");

// When ASC and NULLS LAST or DESC and NULLS FIRST, we do not print NULLS FIRST/LAST
// because it is the default behavior and we want to avoid printing NULLS FIRST/LAST
// because it is the default behavior. we want to avoid printing NULLS FIRST/LAST
// whenever possible as it is incompatible with Hive (SQL compatibility with Hive is
// important for views).
if (nullsFirstParam != null) {
Expand All @@ -97,11 +98,6 @@ public String toSql() {
return strBuilder.toString();
}

@Override
public String toString() {
return toSql();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public String getNodeExplainString(String prefix, TExplainLevel detailLevel) {
strings.clear();

for (OrderByElement element : orderByElements) {
strings.add(element.toSql());
strings.add(orderByElementToSql(element));
}

output.append(Joiner.on(", ").join(strings));
Expand All @@ -146,6 +146,29 @@ public String getNodeExplainString(String prefix, TExplainLevel detailLevel) {
return output.toString();
}


private String orderByElementToSql(OrderByElement orderByElement) {
StringBuilder strBuilder = new StringBuilder();
strBuilder.append(orderByElement.getExpr().accept(ExprToSqlVisitor.INSTANCE, ToSqlParams.WITH_TABLE));
strBuilder.append(orderByElement.getIsAsc() ? " ASC" : " DESC");

// When ASC and NULLS LAST or DESC and NULLS FIRST, we do not print NULLS FIRST/LAST
// because it is the default behavior and we want to avoid printing NULLS FIRST/LAST
// whenever possible as it is incompatible with Hive (SQL compatibility with Hive is
// important for views).
if (orderByElement.getNullsFirstParam() != null) {
if (orderByElement.getIsAsc() && orderByElement.getNullsFirstParam()) {
// If ascending, nulls are last by default, so only add if nulls first.
strBuilder.append(" NULLS FIRST");
} else if (!orderByElement.getIsAsc() && !orderByElement.getNullsFirstParam()) {
// If descending, nulls are first by default, so only add if nulls last.
strBuilder.append(" NULLS LAST");
}
}

return strBuilder.toString();
}

/**
* If `partitionExprs` is empty, the result must be output by single instance.
*
Expand Down
Loading