Search in sources :

Example 1 with DateTimeMath

use of org.apache.hadoop.hive.ql.util.DateTimeMath in project hive by apache.

the class TestDateTimeMath method checkTsIntervalDayTimeArithmetic.

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

Example 2 with DateTimeMath

use of org.apache.hadoop.hive.ql.util.DateTimeMath in project hive by apache.

the class TestDateTimeMath method checkIntervalYearMonthArithmetic.

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

Example 3 with DateTimeMath

use of org.apache.hadoop.hive.ql.util.DateTimeMath in project hive by apache.

the class TestDateTimeMath method checkTsArithmetic.

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

Example 4 with DateTimeMath

use of org.apache.hadoop.hive.ql.util.DateTimeMath in project hive by apache.

the class TestDateTimeMath method checkTimestampIntervalYearMonthArithmetic.

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

Example 5 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(org.apache.hadoop.hive.common.type.Date)

Aggregations

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