Refine search
@Override public String toString() { return intervalValue.toString(); } }
@Override protected HiveIntervalDayTime getIntervalDayTime(String arg) { return HiveIntervalDayTime.valueOf(arg); } }
@Override protected HiveIntervalDayTime getIntervalDayTime(String arg) { BigDecimal bd = new BigDecimal(arg); BigDecimal bdSeconds = new BigDecimal(bd.toBigInteger()); BigDecimal bdNanos = bd.subtract(bdSeconds); return new HiveIntervalDayTime(0, 0, 0, bdSeconds.intValueExact(), bdNanos.multiply(NANOS_PER_SEC_BD).intValue()); } }
/** * Fill all the vector entries with a HiveIntervalDayTime. * @param intervalDayTime */ public void fill(HiveIntervalDayTime intervalDayTime) { isRepeating = true; isNull[0] = false; totalSeconds[0] = intervalDayTime.getTotalSeconds(); nanos[0] = intervalDayTime.getNanos(); }
public boolean add(HiveIntervalDayTime left, HiveIntervalDayTime right, HiveIntervalDayTime result) { if (left == null || right == null) { return false; } nanosResult.addNanos(left.getNanos(), right.getNanos()); long totalSeconds = left.getTotalSeconds() + right.getTotalSeconds() + nanosResult.seconds; result.set(totalSeconds, nanosResult.nanos); return true; }
@Override public String toString() { // If normalize() was used, then day-hour-minute-second-nanos should have the same sign. // This is currently working with that assumption. boolean isNegative = (totalSeconds < 0 || nanos < 0); String daySecondSignStr = isNegative ? "-" : ""; return String.format("%s%d %02d:%02d:%02d.%09d", daySecondSignStr, Math.abs(getDays()), Math.abs(getHours()), Math.abs(getMinutes()), Math.abs(getSeconds()), Math.abs(getNanos())); }
break; case BYTE: calciteLiteral = rexBuilder.makeExactLiteral(new BigDecimal((Byte) value), calciteDataType); break; case SHORT: calciteLiteral = rexBuilder.makeExactLiteral(new BigDecimal((Short) value), calciteDataType); break; case INT: calciteLiteral = rexBuilder.makeExactLiteral(new BigDecimal((Integer) value)); break; case LONG: } else { c = Calendar.getInstance(); c.setTimeInMillis(((Timestamp)value).getTime()); case INTERVAL_YEAR_MONTH: BigDecimal totalMonths = BigDecimal.valueOf(((HiveIntervalYearMonth) value).getTotalMonths()); calciteLiteral = rexBuilder.makeIntervalLiteral(totalMonths, new SqlIntervalQualifier(TimeUnit.YEAR, TimeUnit.MONTH, new SqlParserPos(1,1))); .valueOf(((HiveIntervalDayTime) value).getTotalSeconds() * 1000); BigDecimal nanosValueBd = BigDecimal.valueOf(((HiveIntervalDayTime) value).getNanos(), 6); calciteLiteral = rexBuilder.makeIntervalLiteral(secsValueBd.add(nanosValueBd),
case HiveParser.TOK_INTERVAL_YEAR_MONTH_LITERAL: return new ExprNodeConstantDesc(TypeInfoFactory.intervalYearMonthTypeInfo, HiveIntervalYearMonth.valueOf(intervalString)); case HiveParser.TOK_INTERVAL_DAY_TIME_LITERAL: return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo, HiveIntervalDayTime.valueOf(intervalString)); case HiveParser.TOK_INTERVAL_YEAR_LITERAL: return new ExprNodeConstantDesc(TypeInfoFactory.intervalYearMonthTypeInfo, new HiveIntervalYearMonth(Integer.parseInt(intervalString), 0)); case HiveParser.TOK_INTERVAL_MONTH_LITERAL: return new ExprNodeConstantDesc(TypeInfoFactory.intervalYearMonthTypeInfo, case HiveParser.TOK_INTERVAL_DAY_LITERAL: return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo, new HiveIntervalDayTime(Integer.parseInt(intervalString), 0, 0, 0, 0)); case HiveParser.TOK_INTERVAL_HOUR_LITERAL: return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo, new HiveIntervalDayTime(0, Integer.parseInt(intervalString), 0, 0, 0)); case HiveParser.TOK_INTERVAL_MINUTE_LITERAL: return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo, new HiveIntervalDayTime(0, 0, Integer.parseInt(intervalString), 0, 0)); case HiveParser.TOK_INTERVAL_SECOND_LITERAL: BigDecimal bd = new BigDecimal(intervalString); BigDecimal bdSeconds = new BigDecimal(bd.toBigInteger()); BigDecimal bdNanos = bd.subtract(bdSeconds); return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo, new HiveIntervalDayTime(0, 0, 0, bdSeconds.intValueExact(), bdNanos.multiply(NANOS_PER_SEC_BD).intValue())); default:
field = patternMatcher.group(5); if (field != null) { BigDecimal bdSeconds = new BigDecimal(field); if (bdSeconds.compareTo(IntervalDayTimeUtils.MAX_INT_BD) > 0) { throw new IllegalArgumentException("seconds value of " + bdSeconds + " too large"); seconds = sign * bdSeconds.intValue(); nanos = sign * bdSeconds.subtract(new BigDecimal(bdSeconds.toBigInteger())) .multiply(IntervalDayTimeUtils.NANOS_PER_SEC_BD).intValue(); result = new HiveIntervalDayTime(days, hours, minutes, seconds, nanos); } catch (Exception err) { throw new IllegalArgumentException("Error parsing interval day-time string: " + strVal, err);
Object value = literal.getValue3(); if (value instanceof Long) { value = new Timestamp((Long)value); BigDecimal monthsBd = (BigDecimal) literal.getValue(); return new ExprNodeConstantDesc(TypeInfoFactory.intervalYearMonthTypeInfo, new HiveIntervalYearMonth(monthsBd.intValue())); BigDecimal millisBd = (BigDecimal) literal.getValue(); BigDecimal secsBd = millisBd.divide(BigDecimal.valueOf(1000)); return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo, new HiveIntervalDayTime(secsBd));
return Timestamp.valueOf((String) value); case TIMESTAMPLOCALTZ_TYPE: return TimestampTZUtil.parse((String) value); case DECIMAL_TYPE: return new BigDecimal((String)value); case DATE_TYPE: return Date.valueOf((String) value); case INTERVAL_YEAR_MONTH_TYPE: return HiveIntervalYearMonth.valueOf((String) value); case INTERVAL_DAY_TIME_TYPE: return HiveIntervalDayTime.valueOf((String) value); case ARRAY_TYPE: case MAP_TYPE:
type = HiveParser.TOK_INTERVAL_YEAR_MONTH_LITERAL; BigDecimal monthsBd = (BigDecimal) literal.getValue(); HiveIntervalYearMonth intervalYearMonth = new HiveIntervalYearMonth(monthsBd.intValue()); val = "'" + intervalYearMonth.toString() + "'"; BigDecimal secsBd = millisBd.divide(BigDecimal.valueOf(1000)); HiveIntervalDayTime intervalDayTime = new HiveIntervalDayTime(secsBd); val = "'" + intervalDayTime.toString() + "'";
@Deprecated public boolean add(HiveIntervalDayTime interval, java.sql.Timestamp ts, java.sql.Timestamp result) { if (ts == null || interval == null) { return false; } nanosResult.addNanos(ts.getNanos(), interval.getNanos()); long newMillis = ts.getTime() + TimeUnit.SECONDS.toMillis(interval.getTotalSeconds() + nanosResult.seconds); result.setTime(newMillis); result.setNanos(nanosResult.nanos); return true; }
timestampValues[i] = new Timestamp(0); intervalDayTimeValues[i] = new HiveIntervalDayTime();
@Deprecated public boolean subtract(java.sql.Timestamp left, java.sql.Timestamp right, HiveIntervalDayTime result) { if (left == null || right == null) { return false; } nanosResult.addNanos(left.getNanos(), -(right.getNanos())); long totalSeconds = TimeUnit.MILLISECONDS.toSeconds(left.getTime()) - TimeUnit.MILLISECONDS.toSeconds(right.getTime()) + nanosResult.seconds; result.set(totalSeconds, nanosResult.nanos); return true; } }
if (!value.equals(expected)) { TestCase.fail("HiveIntervalYearMonth field mismatch (expected " + expected.toString() + " found " + value.toString() + ")"); if (!value.equals(expected)) { TestCase.fail("HiveIntervalDayTime field mismatch (expected " + expected.toString() + " found " + value.toString() + ")");
@Test @Concurrent(count=4) @Repeating(repetition=100) public void testToString() throws Exception { assertEquals("0 00:00:00.000000000", HiveIntervalDayTime.valueOf("0 00:00:00").toString()); assertEquals("3 04:05:06.123456000", HiveIntervalDayTime.valueOf("3 04:05:06.123456").toString()); assertEquals("-3 04:05:06.123456000", HiveIntervalDayTime.valueOf("-3 04:05:06.123456").toString()); assertEquals("1 00:00:00.000000000", HiveIntervalDayTime.valueOf("1 00:00:00").toString()); assertEquals("-1 00:00:00.000000000", HiveIntervalDayTime.valueOf("-1 00:00:00").toString()); assertEquals("0 00:00:00.880000000", HiveIntervalDayTime.valueOf("0 00:00:00.88").toString()); assertEquals("-0 00:00:00.880000000", HiveIntervalDayTime.valueOf("-0 00:00:00.88").toString()); // Mixed sign cases assertEquals("-3 04:05:06.000000007", new HiveIntervalDayTime(-3, -4, -5, -6, -7).toString()); assertEquals("3 04:05:06.000000007", new HiveIntervalDayTime(3, 4, 5, 6, 7).toString()); }