public Timestamp add(Timestamp ts, HiveIntervalYearMonth interval) { if (ts == null || interval == null) { return null; } Timestamp tsResult = new Timestamp(0); add(ts, interval, tsResult); return tsResult; }
public Date subtract(Date left, HiveIntervalYearMonth right) { if (left == null || right == null) { return null; } Date dtResult = new Date(0); subtract(left, right, dtResult); return dtResult; }
public long addMonthsToNanosLocal(long nanos, int months) { long result = addMonthsToMillisLocal(nanos / 1000000, months) * 1000000 + (nanos % 1000000); return result; }
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); }
HiveIntervalYearMonth iym2 = PrimitiveObjectInspectorUtils.getHiveIntervalYearMonth( arguments[intervalArg2Idx].get(), inputOIs[intervalArg2Idx]); return handleIntervalYearMonthResult(dtm.subtract(iym1, iym2)); Date dt1 = PrimitiveObjectInspectorUtils.getDate( arguments[dtArg1Idx].get(), inputOIs[dtArg1Idx]); return handleDateResult(dtm.subtract(dt1, iym1)); Timestamp ts1 = PrimitiveObjectInspectorUtils.getTimestamp( arguments[dtArg1Idx].get(), inputOIs[dtArg1Idx]); return handleTimestampResult(dtm.subtract(ts1, iym1)); HiveIntervalDayTime idt2 = PrimitiveObjectInspectorUtils.getHiveIntervalDayTime( arguments[intervalArg2Idx].get(), inputOIs[intervalArg2Idx]); return handleIntervalDayTimeResult(dtm.subtract(idt1, idt2)); Timestamp ts1 = PrimitiveObjectInspectorUtils.getTimestamp( arguments[dtArg1Idx].get(), inputOIs[dtArg1Idx]); return handleTimestampResult(dtm.subtract(ts1, idt1)); Timestamp ts2 = PrimitiveObjectInspectorUtils.getTimestamp( arguments[dtArg2Idx].get(), inputOIs[dtArg2Idx]); return handleIntervalDayTimeResult(dtm.subtract(ts1, ts2)); Date dt1 = PrimitiveObjectInspectorUtils.getDate( arguments[dtArg1Idx].get(), inputOIs[dtArg1Idx]); return handleDateResult(dtm.add(dt1, -intVal));
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); } }
public long addMonthsToNanosUtc(long nanos, int months) { long result = addMonthsToMillisUtc(nanos / 1000000, months) * 1000000 + (nanos % 1000000); return result; }
public long addMonthsToNanos(long nanos, int months) { long result = addMonthsToMillis(nanos / 1000000, months) * 1000000 + (nanos % 1000000); return result; }
outputVector[0] = dtm.addMonthsToDays((vector[0]), - (int) value); for(int j = 0; j != n; j++) { int i = sel[j]; outputVector[i] = dtm.addMonthsToDays((vector[i]), - (int) value); outputVector[i] = dtm.addMonthsToDays((vector[i]), - (int) value); for(int j = 0; j != n; j++) { int i = sel[j]; outputVector[i] = dtm.addMonthsToDays((vector[i]), - (int) value); outputIsNull[i] = inputIsNull[i]; outputVector[i] = dtm.addMonthsToDays((vector[i]), - (int) value);
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); }
public boolean add(Timestamp ts, HiveIntervalYearMonth interval, Timestamp result) { if (ts == null || interval == null) { return false; } // Attempt to match Oracle semantics for timestamp arithmetic, // where timestamp arithmetic is done in UTC, then converted back to local timezone long resultMillis = addMonthsToMillisUtc(ts.getTime(), interval.getTotalMonths()); result.setTime(resultMillis); result.setNanos(ts.getNanos()); return true; }
@Deprecated public boolean add(java.sql.Timestamp ts, HiveIntervalYearMonth interval, java.sql.Timestamp result) { if (ts == null || interval == null) { return false; } // Attempt to match Oracle semantics for timestamp arithmetic, // where timestamp arithmetic is done in UTC, then converted back to local timezone long resultMillis = addMonthsToMillis(ts.getTime(), interval.getTotalMonths()); result.setTime(resultMillis); result.setNanos(ts.getNanos()); return true; }
outputVector[0] = dtm.addMonthsToDays((vector[0]), + (int) value); for(int j = 0; j != n; j++) { int i = sel[j]; outputVector[i] = dtm.addMonthsToDays((vector[i]), + (int) value); outputVector[i] = dtm.addMonthsToDays((vector[i]), + (int) value); for(int j = 0; j != n; j++) { int i = sel[j]; outputVector[i] = dtm.addMonthsToDays((vector[i]), + (int) value); outputIsNull[i] = inputIsNull[i]; outputVector[i] = dtm.addMonthsToDays((vector[i]), + (int) value);
public Timestamp add(HiveIntervalDayTime interval, Timestamp ts) { if (ts == null || interval == null) { return null; } Timestamp tsResult = new Timestamp(0); add(interval, ts, tsResult); return tsResult; }
public Timestamp subtract(Timestamp left, HiveIntervalYearMonth right) { if (left == null || right == null) { return null; } Timestamp tsResult = new Timestamp(0); subtract(left, right, tsResult); return tsResult; }
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); }
public boolean add(Date dt, HiveIntervalYearMonth interval, Date result) { if (dt == null || interval == null) { return false; } // Since Date millis value is in local timezone representation, do date arithmetic // using local timezone so the time remains at the start of the day. long resultMillis = addMonthsToMillisLocal(dt.getTime(), interval.getTotalMonths()); result.setTime(resultMillis); return true; }
public boolean add(HiveIntervalYearMonth interval, Timestamp ts, Timestamp result) { if (ts == null || interval == null) { return false; } // Attempt to match Oracle semantics for timestamp arithmetic, // where timestamp arithmetic is done in UTC, then converted back to local timezone long resultMillis = addMonthsToMillisUtc(ts.getTime(), interval.getTotalMonths()); result.setTime(resultMillis); result.setNanos(ts.getNanos()); return true; }
@Deprecated public boolean add(HiveIntervalYearMonth interval, java.sql.Timestamp ts, java.sql.Timestamp result) { if (ts == null || interval == null) { return false; } long resultMillis = addMonthsToMillis(ts.getTime(), interval.getTotalMonths()); result.setTime(resultMillis); result.setNanos(ts.getNanos()); return true; }
outputVector[0] = dtm.addMonthsToDays(value, + (int) vector[0]); for(int j = 0; j != n; j++) { int i = sel[j]; outputVector[i] = dtm.addMonthsToDays(value, + (int) vector[i]); outputVector[i] = dtm.addMonthsToDays(value, + (int) vector[i]); for(int j = 0; j != n; j++) { int i = sel[j]; outputVector[i] = dtm.addMonthsToDays(value, + (int) vector[i]); outputIsNull[i] = inputIsNull[i]; outputVector[i] = dtm.addMonthsToDays(value, + (int) vector[i]);