[ https://issues.apache.org/jira/browse/PHOENIX-6823?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17640716#comment-17640716 ]
ASF GitHub Bot commented on PHOENIX-6823: ----------------------------------------- stoty commented on code in PR #1530: URL: https://github.com/apache/phoenix/pull/1530#discussion_r1034771915 ########## phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java: ########## @@ -688,4 +720,1207 @@ public void testFloorDateExpressionForWeek() throws Exception { Date resultDate = (Date)result; assertEquals(DateUtil.parseDate("2016-01-04 00:00:00"), resultDate); } + + private RoundDateExpression getRoundMsExpression(String s, TimeUnit u, int m) throws SQLException { + return (RoundDateExpression)RoundDateExpression.create(LiteralExpression.newConstant(s), u, m ); + } + + // The three tests below are backported from PHOENIX-5066. + // When PHOENIX-5066 lands, these can be removed as redundant. + + @Test + public void testRoundingGMT() throws SQLException { + // We operate on Instants for time units up to Days, simply counting millis + + RoundDateExpression oddWholeSecondExp = + getRoundMsExpression("2022-11-11 11:11:11", TimeUnit.SECOND, 1); + java.sql.Timestamp oddWholeSecond = + new java.sql.Timestamp(DateUtil.parseDate("2022-11-11 11:11:11").getTime()); + long lowerBoundaryOddWholeSecond = oddWholeSecond.getTime() - HALF_SEC; + long upperBoundaryOddWholeSecond = oddWholeSecond.getTime() + HALF_SEC - 1; + assertEquals(lowerBoundaryOddWholeSecond, + oddWholeSecondExp.rangeLower(oddWholeSecond.getTime())); + assertEquals(upperBoundaryOddWholeSecond, + oddWholeSecondExp.rangeUpper(oddWholeSecond.getTime())); + assertEquals(oddWholeSecond, + new java.sql.Timestamp(oddWholeSecondExp.roundTime(lowerBoundaryOddWholeSecond))); + assertNotEquals(oddWholeSecond, + new java.sql.Timestamp(oddWholeSecondExp.roundTime(lowerBoundaryOddWholeSecond - 1))); + assertEquals(oddWholeSecond, + new java.sql.Timestamp(oddWholeSecondExp.roundTime(upperBoundaryOddWholeSecond))); + assertNotEquals(oddWholeSecond, + new java.sql.Timestamp(oddWholeSecondExp.roundTime(upperBoundaryOddWholeSecond + 1))); + Review Comment: Yes, I was thinking about how save some copy-paste, but did not find a solution I liked. > calling Joda-based round() function on temporal PK field causes division by > zero error > -------------------------------------------------------------------------------------- > > Key: PHOENIX-6823 > URL: https://issues.apache.org/jira/browse/PHOENIX-6823 > Project: Phoenix > Issue Type: Bug > Components: core > Affects Versions: 5.2.0, 5.1.2 > Reporter: Istvan Toth > Assignee: Istvan Toth > Priority: Major > > > {noformat} > 0: jdbc:phoenix:> create table bubu (df date primary key); > No rows affected (0.689 seconds) > 0: jdbc:phoenix:> select * from bubu where round(df,'YEAR',1)=DATE > '2022-01-01 00:00:00'; > java.lang.ArithmeticException: / by zero > at > org.apache.phoenix.expression.function.RoundDateExpression$1.getKeyRange(RoundDateExpression.java:272) > ...{noformat} > This is caused by getKeyRange not being updated when the Joda-based time > units were added. > Also, the keyrange pushdown logic is just wrong, even for the non-joda cases. -- This message was sent by Atlassian Jira (v8.20.10#820010)