[ https://issues.apache.org/jira/browse/CALCITE-7181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18020001#comment-18020001 ]
Zhen Chen commented on CALCITE-7181: ------------------------------------ Thanks [~julianhyde] I tried the value 9823372036854775807 (where the BIGINT maximum is 9223372036854775807; I changed the second digit to 8), and using BigDecimal at the Java layer works well in this case. However, when I use 19223372036854775807 (by adding a 1 in front of the BIGINT maximum), it results in an error (DECIMAL(19, 0) overflow; of course, this is related to the maximum precision supported by DECIMAL in different databases). This aligns with your point that it depends on the data implementation. I’ve also reconfirmed that extracting numbers from RexNode currently uses RexLiteral. Therefore, I’ve updated the code to use BigDecimal, and I hope you can take a look when you have time to see if this approach is reasonable. > FETCH in SortRemoveRedundantRule do not support BIGINT > ------------------------------------------------------ > > Key: CALCITE-7181 > URL: https://issues.apache.org/jira/browse/CALCITE-7181 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.40.0 > Reporter: Zhen Chen > Assignee: Zhen Chen > Priority: Major > Labels: pull-request-available > Fix For: 1.41.0 > > > This case can not work. > {code:java} > @Test void testSortRemoveWhenInputValuesMaxRowCntLessOrEqualLimitFetch2() { > final String sql = "select * from\n" > + "(VALUES 1,2,3,4,5,6) as t1 limit 3000000000"; > sql(sql) > .withRule(CoreRules.SORT_REMOVE_REDUNDANT) > .check(); > } > {code} > {code:java} > Integer overflow: 3000000000 is out of range for INT > java.lang.ArithmeticException: Integer overflow: 3000000000 is out of range > for INT > at org.apache.calcite.rex.RexLiteral.intValue(RexLiteral.java:1280) > at > org.apache.calcite.rel.rules.SortRemoveRedundantRule.getRowCountThreshold(SortRemoveRedundantRule.java:133) > at > org.apache.calcite.rel.rules.SortRemoveRedundantRule.onMatch(SortRemoveRedundantRule.java:117) > at > org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:350) > at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:527) > at > org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:419) > at > org.apache.calcite.plan.hep.HepPlanner.executeRuleInstance(HepPlanner.java:242) > at > org.apache.calcite.plan.hep.HepInstruction$RuleInstance$State.execute(HepInstruction.java:178) > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)