@Override public void copy(int inputIdx, int count, int outputIdx) { // Date is given as number of days, we store as millis final long[] input = inputVector.vector; if (inputVector.isRepeating) { if (inputVector.isNull[0]) { return; // If all repeating values are null, then there is no need to write anything to vector } final long value = input[0] * MILLIS_PER_DAY; for (int i = 0; i < count; i++, outputIdx++) { outputVector.set(outputIdx, value); } } else if (inputVector.noNulls) { for (int i = 0; i < count; i++, inputIdx++, outputIdx++) { outputVector.set(outputIdx, input[inputIdx] * MILLIS_PER_DAY); } } else { final boolean isNull[] = inputVector.isNull; for (int i = 0; i < count; i++, inputIdx++, outputIdx++) { if (!isNull[inputIdx]) { outputVector.set(outputIdx, input[inputIdx] * MILLIS_PER_DAY); } } } } }
public void populate(final int count){ for (int i = 0; i < count; i++) { if(value != null) { ((DateMilliVector) vector).setSafe(i, value); } } vector.setValueCount(count); }
@Override public FieldVector getNewVector( String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { return new DateMilliVector(name, fieldType, allocator); }
/** * Same as {@link #set(int, long)} except that it handles the * case when index is greater than or equal to existing * value capacity {@link #getValueCapacity()}. * * @param index position of element * @param value value of element */ public void setSafe(int index, long value) { handleSafe(index); set(index, value); }
private static Pair<DateMilliVector, ResultVerifier> testDateMilliVector(final int startIndexInCurrentOutput, final int startIndexInJob) { DateMilliVector colDateV = new DateMilliVector("colDate", allocator); colDateV.allocateNew(5); colDateV.set(0, 234); colDateV.set(1, -2342); colDateV.setNull(2); colDateV.set(3, 384928359245L); colDateV.set(4, 2342893433L); ResultVerifier verifier = new ResultVerifier() { @Override public void verify(DataPOJO output) { int index = startIndexInCurrentOutput; assertEquals("1970-01-01", output.extractValue("colDate", index++)); assertEquals("1969-12-31", output.extractValue("colDate", index++)); assertNull(output.extractValue("colDate", index++)); assertEquals("1982-03-14", output.extractValue("colDate", index++)); assertEquals("1970-01-28", output.extractValue("colDate", index++)); } }; return Pair.of(colDateV, verifier); }
private void decodeDate(IntVector input, DateMilliVector output, IntVector dictionary) { // dates are stored as int32 in parquet dictionaries if (hasSv2) { final SelectionVector2 sv2 = incoming.getSelectionVector2(); for (int i = 0; i < recordsConsumedCurrentBatch; ++i) { final int svIndex = sv2.getIndex(i); if (input.isNull(svIndex)) { output.setNull(svIndex); } else { final int id = input.get(svIndex); output.setSafe(svIndex, dictionary.get(id) * (long) DateTimeConstants.MILLIS_PER_DAY); } } } else { for (int i = 0; i < recordsConsumedCurrentBatch; ++i) { if (input.isNull(i)) { output.setNull(i); } else { int id = input.get(i); output.setSafe(i, dictionary.get(id) * (long) DateTimeConstants.MILLIS_PER_DAY); } } } }
public void writeNull() { vector.setNull(idx()); vector.setValueCount(idx()+1); } }
@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); } }
public void getFieldById(int fieldId, NullableDateMilliHolder holder) { ((DateMilliVector) vectors[fieldId]).get(currentIndex, holder); }
public void loadData(SerializedField metadata, ArrowBuf buffer) { /* clear the current buffers (if any) */ vector.clear(); /* get the metadata children */ final SerializedField bitsField = metadata.getChild(0); final SerializedField valuesField = metadata.getChild(1); final int valuesLength = buffer.capacity(); vector.allocateNew(metadata.getValueCount()); /* set inner validity buffer */ setValidityBuffer(bitsField); /* load inner value buffer */ vector.valueBuffer.close(); loadDataBuffer(valuesField, buffer.slice(0, valuesLength)); }
switch (type.getMode()) { case REQUIRED: ((DateMilliVector) vector).setSafe(index, (DateMilliHolder) holder); return; case OPTIONAL: if (holder instanceof NullableDateMilliHolder) { if (((NullableDateMilliHolder) holder).isSet == 1) { ((DateMilliVector) vector).setSafe(index, (NullableDateMilliHolder) holder); } else { ((DateMilliVector) vector).isSafe(index); ((DateMilliVector) vector).setSafe(index, (DateMilliHolder) holder);
public void allocate(){ vector.allocateNew(); }
/** * Get the element at the given index from the vector. * * @param index position of element * @return element at given index */ public long get(int index) throws IllegalStateException { if (isSet(index) == 0) { throw new IllegalStateException("Value at index is null"); } return valueBuffer.getLong(index * TYPE_WIDTH); }
public Field getField(){ return vector.getField(); }
@Override public boolean isNull(int index) { return ac.isNull(index); }
@Override public void clear() { vector.clear(); }
/** * Same as {@link #set(int, NullableDateMilliHolder)} except that it handles the * case when index is greater than or equal to existing * value capacity {@link #getValueCapacity()}. * * @param index position of element * @param holder nullable data holder for value of element */ public void setSafe(int index, NullableDateMilliHolder holder) throws IllegalArgumentException { handleSafe(index); set(index, holder); }
@Override public void set(ValueVector v, int index) { if(obj != null){ ((DateMilliVector) v).setSafe(index, obj.toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis()); } }