You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "zhangstar333 (via GitHub)" <gi...@apache.org> on 2023/04/10 13:34:56 UTC
[GitHub] [doris] zhangstar333 commented on a diff in pull request #18388: [feature](array) Add array_last lambda function
zhangstar333 commented on code in PR #18388:
URL: https://github.com/apache/doris/pull/18388#discussion_r1161724992
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/LambdaFunctionCallExpr.java:
##########
@@ -198,12 +202,50 @@ public void analyzeImpl(Analyzer analyzer) throws AnalysisException {
argTypes[1] = getChild(1).getType();
}
fn = getBuiltinFunction(fnName.getFunction(), argTypes,
- Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
+ Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
if (fn == null) {
LOG.warn("fn {} not exists", this.toSqlImpl());
throw new AnalysisException(getFunctionNotFoundError(collectChildReturnTypes()));
}
fn.setReturnType(getChild(0).getType());
+ } else if ( fnName.getFunction().equalsIgnoreCase("array_last") ) {
+
+ List<Expr> params = new ArrayList<>();
+ for (int i = 0; i <= childSize - 1; ++i) {
+ params.add(getChild(i));
+ }
+ LambdaFunctionCallExpr filterFunc = new LambdaFunctionCallExpr("array_filter", params);
+ //filterFunc.analyzeImpl(analyzer);
+ IntLiteral indexParam = new IntLiteral(-1, Type.INT);
+ params = Lists.newArrayList(filterFunc, indexParam) ;
+
+ Type[] argTypesForCallExpr = new Type[2];
+ argTypesForCallExpr[0] = getChild(0).getType();
+ argTypesForCallExpr[1] = getChild(1).getType();
+ FunctionCallExpr callExpr = new FunctionCallExpr("element_at", params) ;
+ callExpr.analyzeImpl(analyzer);
+
+ this.setFnName(arrayCloneExpr) ;
+
+ this.children.clear() ;
+ this.children.add(callExpr);
+
+ argTypes = new Type[1] ;
+ argTypes[0] = getChild(0).getType();
+
+ fn = getBuiltinFunction(arrayCloneExpr.getFunction(), argTypes, Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
+ if (fn == null) {
+ LOG.warn("fn element_at not exists");
+ throw new AnalysisException(getFunctionNotFoundError(collectChildReturnTypes()));
+ }
+ fn.setReturnType(getChild(0).getType());
+ } else if ( fnName.getFunction().equalsIgnoreCase("array_clone_expr") ) {
Review Comment:
I think is better to rewrite array_last(lambda,array)--->element_at(array_filter,-1)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org