[
https://issues.apache.org/jira/browse/HIVE-18537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17908844#comment-17908844
]
guriguri commented on HIVE-18537:
---------------------------------
I fixed calcite 1.6.0 (using AggregateProjectPullUpConstantsRule.java of
calcite 1.17.0) because there were too many errors when it was complied with
calcite 1.17.0 in Hive 2.1.1.
{code:java}
diff --git
a/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectPullUpConstantsRule.java
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectPullUpConstantsRule.java
index bb7797e..649544d 100644
---
a/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectPullUpConstantsRule.java
+++
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectPullUpConstantsRule.java
@@ -26,6 +26,7 @@
import org.apache.calcite.rel.logical.LogicalAggregate;
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
+import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexInputRef;
@@ -212,14 +213,23 @@ public void onMatch(RelOptRuleCall call) {
if (i >= groupCount) {
// Aggregate expressions' names and positions are unchanged.
expr = relBuilder.field(i - map.size());
- } else if (map.containsKey(i)) {
- // Re-generate the constant expression in the project.
- expr = map.get(i);
} else {
- // Project the aggregation expression, in its original
- // position.
- expr = relBuilder.field(source);
- ++source;
+ int pos = aggregate.getGroupSet().nth(i);
+ if (map.containsKey(pos)) {
+ // Re-generate the constant expression in the project.
+ RelDataType originalType =
+
aggregate.getRowType().getFieldList().get(projects.size()).getType();
+ if (!originalType.equals(map.get(pos).getType())) {
+ expr = rexBuilder.makeCast(originalType, map.get(pos), true);
+ } else {
+ expr = map.get(pos);
+ }
+ } else {
+ // Project the aggregation expression, in its original
+ // position.
+ expr = relBuilder.field(source);
+ ++source;
+ }
}
projects.add(Pair.of(expr, field.getName()));
} {code}
> [Calcite-CBO] Queries with a nested distinct clause and a windowing function
> seem to fail with calcite Assertion error
> ----------------------------------------------------------------------------------------------------------------------
>
> Key: HIVE-18537
> URL: https://issues.apache.org/jira/browse/HIVE-18537
> Project: Hive
> Issue Type: Bug
> Components: Hive
> Affects Versions: 2.1.0, 2.3.2, 3.1.2
> Reporter: Amruth Sampath
> Priority: Critical
>
> Sample test case to re-produce the issue. The issue does not occur if
> *hive.cbo.enable=false*
> {code:java}
> create table test_cbo (
> `a` BIGINT,
> `b` STRING,
> `c` TIMESTAMP,
> `d` STRING
> );
> SELECT 1
> FROM
> (SELECT
> DISTINCT
> a AS a_,
> b AS b_,
> rank() over (partition BY a ORDER BY c DESC) AS c_,
> d AS d_
> FROM test_cbo
> WHERE b = 'some_filter' ) n
> WHERE c_ = 1;
> {code}
> Fails with,
> {code:java}
> Exception in thread "main" java.lang.AssertionError: Internal error: Cannot
> add expression of different type to set:
> set type is RecordType(BIGINT a_, INTEGER c_, VARCHAR(2147483647) CHARACTER
> SET "UTF-16LE" COLLATE "ISO-8859-1$en_US$primary" d_) NOT NULL
> expression type is RecordType(BIGINT a_, VARCHAR(2147483647) CHARACTER SET
> "UTF-16LE" COLLATE "ISO-8859-1$en_US$primary" c_, INTEGER d_) NOT NULL
> set is rel#112:HiveAggregate.HIVE.[](input=HepRelVertex#121,group={0, 2, 3})
> expression is HiveProject#123{code}
> This might be related to https://issues.apache.org/jira/browse/CALCITE-1868.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)