This is an automated email from the ASF dual-hosted git repository.
mrhhsg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 7e886ee237a [opt](fe) Add alias element_at as struct_element (#56898)
7e886ee237a is described below
commit 7e886ee237a7c9f847f3ff01768d989ee0c2cf77
Author: Jerry Hu <[email protected]>
AuthorDate: Mon Oct 13 22:05:50 2025 +0800
[opt](fe) Add alias element_at as struct_element (#56898)
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
.../trees/expressions/functions/scalar/ElementAt.java | 15 ++++++++++++++-
.../struct_functions/test_struct_functions.groovy | 8 ++++----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java
index 99f63bab15c..b24d46c98a4 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java
@@ -21,11 +21,13 @@ import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.RewriteWhenAnalyze;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.ArrayType;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.types.MapType;
+import org.apache.doris.nereids.types.StructType;
import org.apache.doris.nereids.types.VarcharType;
import org.apache.doris.nereids.types.VariantType;
import org.apache.doris.nereids.types.coercion.AnyDataType;
@@ -40,7 +42,7 @@ import java.util.List;
* ScalarFunction 'element_at'. This class is generated by GenerateFunction.
*/
public class ElementAt extends ScalarFunction
- implements BinaryExpression, ExplicitlyCastableSignature,
AlwaysNullable {
+ implements BinaryExpression, ExplicitlyCastableSignature,
AlwaysNullable, RewriteWhenAnalyze {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(new FollowToAnyDataType(0))
@@ -79,6 +81,17 @@ public class ElementAt extends ScalarFunction
@Override
public List<FunctionSignature> getSignatures() {
+ if (child(0).getDataType() instanceof StructType) {
+ return new StructElement(child(0), child(1)).getSignatures();
+ }
return SIGNATURES;
}
+
+ @Override
+ public Expression rewriteWhenAnalyze() {
+ if (child(0).getDataType() instanceof StructType) {
+ return new StructElement(child(0), child(1));
+ }
+ return this;
+ }
}
diff --git
a/regression-test/suites/query_p0/sql_functions/struct_functions/test_struct_functions.groovy
b/regression-test/suites/query_p0/sql_functions/struct_functions/test_struct_functions.groovy
index e3581967a2a..97a099dbbbd 100644
---
a/regression-test/suites/query_p0/sql_functions/struct_functions/test_struct_functions.groovy
+++
b/regression-test/suites/query_p0/sql_functions/struct_functions/test_struct_functions.groovy
@@ -43,10 +43,10 @@ suite("test_struct_functions") {
qt_select_all "SELECT * FROM ${tableName} ORDER BY k1"
- qt_select_struct_element_1 "SELECT
struct_element(k2,'f1'),struct_element(k2,'f2'),struct_element(k2,'f3'),struct_element(k2,'f4'),struct_element(k2,'f5')
FROM ${tableName} ORDER BY k1"
- qt_select_struct_element_2 "SELECT
struct_element(k3,'f1'),struct_element(k3,'f2'),struct_element(k3,'f3') FROM
${tableName} ORDER BY k1"
- qt_select_struct_element_3 "SELECT
struct_element(k4,1),struct_element(k4,2),struct_element(k4,3),struct_element(k4,4)
FROM ${tableName} ORDER BY k1"
- qt_select_struct_element_4 "SELECT
struct_element(k5,1),struct_element(k5,2),struct_element(k5,3) FROM
${tableName} ORDER BY k1"
+ qt_select_struct_element_1 "SELECT
element_at(k2,'f1'),element_at(k2,'f2'),element_at(k2,'f3'),element_at(k2,'f4'),element_at(k2,'f5')
FROM ${tableName} ORDER BY k1"
+ qt_select_struct_element_2 "SELECT
element_at(k3,'f1'),element_at(k3,'f2'),element_at(k3,'f3') FROM ${tableName}
ORDER BY k1"
+ qt_select_struct_element_3 "SELECT
element_at(k4,1),element_at(k4,2),element_at(k4,3),element_at(k4,4) FROM
${tableName} ORDER BY k1"
+ qt_select_struct_element_4 "SELECT
element_at(k5,1),element_at(k5,2),element_at(k5,3) FROM ${tableName} ORDER BY
k1"
//The precision of the decimal type in the test select is inconsistent
with the precision of the function named_struct containing the decimal type.
sql """ drop table if exists t01 --force """;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]