use of org.apache.hadoop.hive.ql.util.DateTimeMath in project hive by apache.
the class TestDateTimeMath method checkDateIntervalDayTimeArithmetic.
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);
}
Aggregations