private static long formatDateAsLong(Object object, DateObjectInspector inspector) { if (object instanceof LazyDate) { return ((LazyDate) object).getWritableObject().getDays(); } if (object instanceof DateWritable) { return ((DateWritable) object).getDays(); } // Hive will return java.sql.Date at midnight in JVM time zone long millisLocal = inspector.getPrimitiveJavaObject(object).getTime(); // Convert it to midnight in UTC long millisUtc = DateTimeZone.getDefault().getMillisKeepLocal(DateTimeZone.UTC, millisLocal); // Convert midnight UTC to days return TimeUnit.MILLISECONDS.toDays(millisUtc); }
private Date readDateValue(String dateStr) { // try either yyyy-mm-dd, or integer representing days since epoch try { DateWritable writableVal = new DateWritable(java.sql.Date.valueOf(dateStr)); return new Date(writableVal.getDays()); } catch (IllegalArgumentException err) { // Fallback to integer parsing LOG.debug("Reading date value as days since epoch: " + dateStr); return new Date(Long.parseLong(dateStr)); } } }
@Override public void assignObjectValue(Object val, int destIndex) throws HiveException { if (val == null) { assignNull(destIndex); } else { DateWritable bw = (DateWritable) val; assignLong(bw.getDays(), destIndex); } } }.init(outputBatch, (LongColumnVector) destCol);
@Override void write(Object obj) throws IOException { super.write(obj); if (obj != null) { // Using the Writable here as it's used directly for writing as well as for stats. DateWritable val = ((DateObjectInspector) inspector).getPrimitiveWritableObject(obj); indexStatistics.updateDate(val); writer.write(val.getDays()); if (createBloomFilter) { bloomFilter.addLong(val.getDays()); } } }
int value = dateWriteable.getDays(); int maxValue = range.maxValue.intValue(); int minValue = range.minValue.intValue();
@Override protected void update(Object p, PrimitiveObjectInspector inputOI) { // DateWritable is mutable, DateStatsAgg needs its own copy DateWritable v = new DateWritable((DateWritable) inputOI.getPrimitiveWritableObject(p)); //Update min counter if new value is less than min seen so far if (min == null || v.compareTo(min) < 0) { min = v; } //Update max counter if new value is greater than max seen so far if (max == null || v.compareTo(max) > 0) { max = v; } // Add value to NumDistinctValue Estimator numDV.addToEstimator(v.getDays()); }
if (colTypeLowerCase == serdeConstants.DATE_TYPE_NAME) { DateWritable writableVal = new DateWritable(java.sql.Date.valueOf(boundValue)); value = writableVal.getDays(); } else { value = new Integer(boundValue);
private void unpackDateStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) { if (fName.equals("countnulls")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getDateStats().setNumNulls(v); } else if (fName.equals("numdistinctvalues")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getDateStats().setNumDVs(v); } else if (fName.equals("max")) { DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o); statsObj.getStatsData().getDateStats().setHighValue(new Date(v.getDays())); } else if (fName.equals("min")) { DateWritable v = ((DateObjectInspector) oi).getPrimitiveWritableObject(o); statsObj.getStatsData().getDateStats().setLowValue(new Date(v.getDays())); } else if (fName.equals("ndvbitvector")) { PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi; String v = ((StringObjectInspector) poi).getPrimitiveJavaObject(o); statsObj.getStatsData().getDateStats().setBitVectors(v);; } }
case DATE: ((LongColumnVector) batch.cols[projectionColumnNum]).vector[batchIndex] = ((DateWritable) object).getDays(); break; case FLOAT:
DateWritable vDate = ((DateObjectInspector)inputOI). getPrimitiveWritableObject(parameters[0]); bf.addLong(vDate.getDays()); break; case TIMESTAMP:
LongColumnVector vector = (LongColumnVector) column; vector.vector[rowId] = ((DateObjectInspector) inspector) .getPrimitiveWritableObject(obj).getDays(); break;
actualValue = new SqlDate(((DateWritable) actualValue).getDays());
DateWritable vDate = ((DateObjectInspector) valObjectInspector). getPrimitiveWritableObject(arguments[0].get()); return bloomFilter.testLong(vDate.getDays()); case TIMESTAMP: Timestamp vTimeStamp = ((TimestampObjectInspector) valObjectInspector).
dateWritable.set(date); ((LongColumnVector) batch.cols[projectionColumnNum]).vector[batchIndex] = dateWritable.getDays();
LongColumnVector lcv = (LongColumnVector) batch.cols[offset + colIndex]; if (writableCol != null) { lcv.vector[rowIndex] = ((DateWritable) writableCol).getDays(); lcv.isNull[rowIndex] = false; } else {
actualValue = new SqlDate(((DateWritable) actualValue).getDays());
case DATE: ((LongColumnVector) batch.cols[projectionColumnNum]).vector[batchIndex] = deserializeRead.currentDateWritable.getDays(); break; case FLOAT:
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final DateWritable writeable = ((DateObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue); ((DateMilliVector) outputVV).setSafe(outputIndex, writeable.getDays() * MILLIS_PER_DAY); } }