Search in sources :

Example 6 with DateTimeMath

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);
}
Also used : DateTimeMath(org.apache.hadoop.hive.ql.util.DateTimeMath) HiveIntervalYearMonth(org.apache.hadoop.hive.common.type.HiveIntervalYearMonth) Date(java.sql.Date)

Aggregations

DateTimeMath (org.apache.hadoop.hive.ql.util.DateTimeMath)6 Timestamp (java.sql.Timestamp)3 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)3 HiveIntervalYearMonth (org.apache.hadoop.hive.common.type.HiveIntervalYearMonth)3 Date (java.sql.Date)1