private static void checkIntervalDayTimeArithmetic( String left, char operationType, String right, String expected) throws Exception { HiveIntervalDayTime leftInterval = left == null ? null : HiveIntervalDayTime.valueOf(left); HiveIntervalDayTime rightInterval = right == null ? null : HiveIntervalDayTime.valueOf(right); HiveIntervalDayTime expectedResult = expected == null ? null : HiveIntervalDayTime.valueOf(expected); HiveIntervalDayTime testResult = null; DateTimeMath dtm = new DateTimeMath(); switch (operationType) { case '-': testResult = dtm.subtract(leftInterval, rightInterval); break; case '+': testResult = dtm.add(leftInterval, rightInterval); break; default: throw new IllegalArgumentException("Invalid operation " + operationType); } assertEquals(String.format("%s %s %s", leftInterval, operationType, rightInterval), expectedResult, testResult); }
private static void checkIntervalYearMonthArithmetic( String left, char operationType, String right, String expected) throws Exception { HiveIntervalYearMonth leftInterval = left == null ? null: HiveIntervalYearMonth.valueOf(left); HiveIntervalYearMonth rightInterval = right == null ? null : HiveIntervalYearMonth.valueOf(right); HiveIntervalYearMonth expectedResult = expected == null ? null : HiveIntervalYearMonth.valueOf(expected); HiveIntervalYearMonth testResult = null; DateTimeMath dtm = new DateTimeMath(); switch (operationType) { case '-': testResult = dtm.subtract(leftInterval, rightInterval); break; case '+': testResult = dtm.add(leftInterval, rightInterval); break; default: throw new IllegalArgumentException("Invalid operation " + operationType); } assertEquals(String.format("%s %s %s", leftInterval, operationType, rightInterval), expectedResult, testResult); }
private static void checkTsArithmetic( String left, String right, String expected) throws Exception { Timestamp leftTs = null; if (left != null) { leftTs = Timestamp.valueOf(left); } Timestamp rightTs = null; if (left != null) { rightTs = Timestamp.valueOf(right); } HiveIntervalDayTime expectedResult = null; if (expected != null) { expectedResult = HiveIntervalDayTime.valueOf(expected); } DateTimeMath dtm = new DateTimeMath(); HiveIntervalDayTime testResult = dtm.subtract(leftTs, rightTs); assertEquals(String.format("%s - %s", leftTs, rightTs), expectedResult, testResult); } }
private static void checkTimestampIntervalYearMonthArithmetic( String left, char operationType, String right, String expected) throws Exception { Timestamp leftTs = null; if (left != null) { leftTs = Timestamp.valueOf(left); } HiveIntervalYearMonth rightInterval = null; if (right != null) { rightInterval = HiveIntervalYearMonth.valueOf(right); } Timestamp expectedResult = null; if (expected != null) { expectedResult = Timestamp.valueOf(expected); } Timestamp testResult = null; DateTimeMath dtm = new DateTimeMath(); switch (operationType) { case '-': testResult = dtm.subtract(leftTs, rightInterval); break; case '+': testResult = dtm.add(leftTs, rightInterval); break; default: throw new IllegalArgumentException("Invalid operation " + operationType); } assertEquals(String.format("%s %s %s", leftTs, operationType, rightInterval), expectedResult, testResult); }
private static void checkDateIntervalDayTimeArithmetic( String left, char operationType, String right, String expected) throws Exception { Date leftDt = null; if (left != null) { leftDt = Date.valueOf(left); } HiveIntervalYearMonth rightInterval = null; if (right != null) { rightInterval = HiveIntervalYearMonth.valueOf(right); } Date expectedResult = null; if (expected != null) { expectedResult = Date.valueOf(expected); } Date testResult = null; DateTimeMath dtm = new DateTimeMath(); switch (operationType) { case '-': testResult = dtm.subtract(leftDt, rightInterval); break; case '+': testResult = dtm.add(leftDt, rightInterval); break; default: throw new IllegalArgumentException("Invalid operation " + operationType); } assertEquals(String.format("%s %s %s", leftDt, operationType, rightInterval), expectedResult, testResult); }
private static void checkTsIntervalDayTimeArithmetic( String left, char operationType, String right, String expected) throws Exception { Timestamp leftTs = null; if (left != null) { leftTs = Timestamp.valueOf(left); } HiveIntervalDayTime rightInterval = right == null ? null : HiveIntervalDayTime.valueOf(right); Timestamp expectedResult = null; if (expected != null) { expectedResult = Timestamp.valueOf(expected); } Timestamp testResult = null; DateTimeMath dtm = new DateTimeMath(); switch (operationType) { case '-': testResult = dtm.subtract(leftTs, rightInterval); break; case '+': testResult = dtm.add(leftTs, rightInterval); break; default: throw new IllegalArgumentException("Invalid operation " + operationType); } assertEquals(String.format("%s %s %s", leftTs, operationType, rightInterval), expectedResult, testResult); }