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);
}
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);
}
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);
}
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);
}
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