This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 c86d6c9b800 [fix](Nereids) could not query variant that not from table
(#33704)
c86d6c9b800 is described below
commit c86d6c9b800fb695a07de43032b1b0a030a3e0ab
Author: morrySnow <[email protected]>
AuthorDate: Tue Apr 16 17:19:07 2024 +0800
[fix](Nereids) could not query variant that not from table (#33704)
---
.../doris/nereids/glue/translator/ExpressionTranslator.java | 6 ++++--
.../apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java | 8 +++++++-
regression-test/data/variant_p0/sql/select_from_value.out | 4 ++++
regression-test/suites/variant_p0/sql/select_from_value.sql | 1 +
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java
index cc2034aa746..6c7a1bd82c1 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java
@@ -209,8 +209,10 @@ public class ExpressionTranslator extends
DefaultExpressionVisitor<Expr, PlanTra
}
SlotReference rewrittenSlot = (SlotReference)
context.getConnectContext()
.getStatementContext().getRewrittenSlotRefByOriginalExpr(elementAt);
- Preconditions.checkNotNull(rewrittenSlot);
- return context.findSlotRef(rewrittenSlot.getExprId());
+ // rewrittenSlot == null means variant is not from table. so keep
element_at function
+ if (rewrittenSlot != null) {
+ return context.findSlotRef(rewrittenSlot.getExprId());
+ }
}
return visitScalarFunction(elementAt, context);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
index 607d9fc1912..cc85bc01323 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
@@ -101,6 +101,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
/** ExpressionAnalyzer */
@@ -423,7 +424,12 @@ public class ExpressionAnalyzer extends
SubExprAnalyzer<ExpressionRewriteContext
&&
!ConnectContext.get().getSessionVariable().isEnableRewriteElementAtToSlot()) {
return boundFunction;
}
- Slot slot =
boundFunction.getInputSlots().stream().findFirst().get();
+ // TODO: push down logic here is very tricky, we will refactor it
later
+ Set<Slot> inputSlots = boundFunction.getInputSlots();
+ if (inputSlots.isEmpty()) {
+ return boundFunction;
+ }
+ Slot slot = inputSlots.iterator().next();
if (slot.hasUnbound()) {
slot = (Slot) slot.accept(this, context);
}
diff --git a/regression-test/data/variant_p0/sql/select_from_value.out
b/regression-test/data/variant_p0/sql/select_from_value.out
new file mode 100644
index 00000000000..ef562a658e9
--- /dev/null
+++ b/regression-test/data/variant_p0/sql/select_from_value.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select_from_value --
+"b"
+
diff --git a/regression-test/suites/variant_p0/sql/select_from_value.sql
b/regression-test/suites/variant_p0/sql/select_from_value.sql
new file mode 100644
index 00000000000..389aa0df61f
--- /dev/null
+++ b/regression-test/suites/variant_p0/sql/select_from_value.sql
@@ -0,0 +1 @@
+select cast('{"a":"b"}' as variant)['a'];
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]