imay closed pull request #248: Support AnalyticExpr in View URL: https://github.com/apache/incubator-doris/pull/248
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/fe/src/main/java/org/apache/doris/analysis/AnalyticExpr.java b/fe/src/main/java/org/apache/doris/analysis/AnalyticExpr.java index 3587b47b..b813e1b8 100644 --- a/fe/src/main/java/org/apache/doris/analysis/AnalyticExpr.java +++ b/fe/src/main/java/org/apache/doris/analysis/AnalyticExpr.java @@ -17,6 +17,7 @@ package org.apache.doris.analysis; +import com.google.common.base.Joiner; import org.apache.doris.analysis.AnalyticWindow.Boundary; import org.apache.doris.analysis.AnalyticWindow.BoundaryType; import org.apache.doris.catalog.AggregateFunction; @@ -171,33 +172,6 @@ public Expr clone() { return new AnalyticExpr(this); } - // @Override - // public String toSqlImpl() { - // if (sqlString_ != null) return sqlString_; - // StringBuilder sb = new StringBuilder(); - // sb.append(fnCall.toSql()).append(" OVER ("); - // boolean needsSpace = false; - // if (!partitionExprs.isEmpty()) { - // sb.append("PARTITION BY ").append(Expr.toSql(partitionExprs)); - // needsSpace = true; - // } - // if (!orderByElements_.isEmpty()) { - // List<String> orderByStrings = Lists.newArrayList(); - // for (OrderByElement e: orderByElements) { - // orderByStrings.add(e.toSql()); - // } - // if (needsSpace) sb.append(" "); - // sb.append("ORDER BY ").append(Joiner.on(", ").join(orderByStrings)); - // needsSpace = true; - // } - // if (window != null) { - // if (needsSpace) sb.append(" "); - // sb.append(window.toSql()); - // } - // sb.append(")"); - // return sb.toString(); - // } - @Override public String debugString() { return Objects.toStringHelper(this) @@ -812,6 +786,44 @@ protected Expr substituteImpl(ExprSubstitutionMap sMap, Analyzer analyzer) @Override public String toSql() { - return ""; + if (sqlString != null) { + return sqlString; + } + StringBuilder sb = new StringBuilder(); + sb.append(fnCall.toSql()).append(" OVER ("); + boolean needsSpace = false; + if (!partitionExprs.isEmpty()) { + sb.append("PARTITION BY ").append(exprListToSql(partitionExprs)); + needsSpace = true; + } + if (!orderByElements.isEmpty()) { + List<String> orderByStrings = Lists.newArrayList(); + for (OrderByElement e : orderByElements) { + orderByStrings.add(e.toSql()); + } + if (needsSpace) { + sb.append(" "); + } + sb.append("ORDER BY ").append(Joiner.on(", ").join(orderByStrings)); + needsSpace = true; + } + if (window != null) { + if (needsSpace) { + sb.append(" "); + } + sb.append(window.toSql()); + } + sb.append(")"); + return sb.toString(); + } + + private String exprListToSql(List<? extends Expr> exprs) { + if (exprs == null || exprs.isEmpty()) + return ""; + List<String> strings = Lists.newArrayList(); + for (Expr expr : exprs) { + strings.add(expr.toSql()); + } + return Joiner.on(", ").join(strings); } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For additional commands, e-mail: dev-h...@doris.apache.org