/** * Get the field out of the row without checking parsed. * * @return The value of the field */ @SuppressWarnings("rawtypes") private Object uncheckedGetField() { LazyObject field = (LazyObject) this.field; if (fieldInited) { return field.getObject(); } fieldInited = true; int fieldStart = startPosition; int fieldLength = start + length - startPosition; if (isNull(oi.getNullSequence(), bytes, fieldStart, fieldLength)) { field.setNull(); } else { field.init(bytes, fieldStart, fieldLength); } return field.getObject(); }
/** * Get the field out of the row without checking parsed. * * @return The value of the field */ private Object uncheckedGetField() { Text nullSequence = oi.getNullSequence(); int fieldLength = start + length - startPosition; if (fieldLength != 0 && fieldLength == nullSequence.getLength() && LazyUtils.compare(bytes.getData(), startPosition, fieldLength, nullSequence.getBytes(), 0, nullSequence.getLength()) == 0) { return null; } if (!fieldInited) { fieldInited = true; field.init(bytes, startPosition, fieldLength); } return field.getObject(); }
@Override public void init(ByteArrayRef bytes, int start, int length) { super.init(bytes, start, length); this.bytes = bytes; this.start = start; this.length = length; assert start >= 0; assert start + length <= bytes.getData().length; }
return v == null ? v : v.getObject(); } else { return _value;
/** * Get the field out of the row without checking parsed. This is called by * both getField and getFieldsAsList. * * @param fieldID * The id of the field starting from 0. * @param nullSequence * The sequence representing NULL value. * @return The value of the field */ private Object uncheckedGetField(int fieldID) { Text nullSequence = oi.getNullSequence(); // Test the length first so in most cases we avoid doing a byte[] // comparison. int fieldByteBegin = startPosition[fieldID]; int fieldLength = startPosition[fieldID + 1] - startPosition[fieldID] - 1; if ((fieldLength < 0) || (fieldLength == nullSequence.getLength() && LazyUtils.compare(bytes .getData(), fieldByteBegin, fieldLength, nullSequence.getBytes(), 0, nullSequence.getLength()) == 0)) { return null; } if (!fieldInited[fieldID]) { fieldInited[fieldID] = true; fields[fieldID].init(bytes, fieldByteBegin, fieldLength); } return fields[fieldID].getObject(); }
/** * Convert the given object to a lazy object using the given {@link ObjectInspector} * * @param obj Object to be converted to a {@link LazyObject} * @param oi ObjectInspector used for the conversion * @return the created {@link LazyObject lazy object} * */ private LazyObject<? extends ObjectInspector> toLazyPrimitiveObject(Object obj, ObjectInspector oi) { if (obj == null) { return null; } LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(oi); ByteArrayRef ref = new ByteArrayRef(); String objAsString = obj.toString().trim(); ref.setData(objAsString.getBytes()); // initialize the lazy object lazyObject.init(ref, 0, ref.getData().length); return lazyObject; }
/** * Get the value in the map for the given key. * * @param key * @return */ @Override public Object getMapValueElement(Object key) { if (!getParsed()) { parse(); } for (Map.Entry<Object, Object> entry : cachedMap.entrySet()) { LazyPrimitive<?, ?> lazyKeyI = (LazyPrimitive<?, ?>) entry.getKey(); // getWritableObject() will convert LazyPrimitive to actual primitive // writable objects. Object keyI = lazyKeyI.getWritableObject(); if (keyI == null) { continue; } if (keyI.equals(key)) { // Got a match, return the value LazyObject<?> v = (LazyObject<?>) entry.getValue(); return v == null ? v : v.getObject(); } } return null; }
/** * Get the element without checking out-of-bound index. */ private Object uncheckedGetElement(int index) { if (elementInited[index]) { return arrayElements[index].getObject(); } elementInited[index] = true; int elementStart = startPosition[index]; int elementLength = startPosition[index + 1] - elementStart - 1; if (arrayElements[index] == null) { arrayElements[index] = LazyFactory.createLazyObject(oi.getListElementObjectInspector()); } if (isNull(oi.getNullSequence(), bytes, elementStart, elementLength)) { arrayElements[index].setNull(); } else { arrayElements[index].init(bytes, elementStart, elementLength); } return arrayElements[index].getObject(); }
private void parseObjectColumn(int column, byte[] bytes, int start, int length) { boolean wasNull; if (length == "\\N".length() && bytes[start] == '\\' && bytes[start + 1] == 'N') { wasNull = true; } else { LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(fieldInspectors[column]); ByteArrayRef byteArrayRef = new ByteArrayRef(); byteArrayRef.setData(bytes); lazyObject.init(byteArrayRef, start, length); objects[column] = getBlockObject(types[column], lazyObject.getObject(), fieldInspectors[column]); wasNull = false; } nulls[column] = wasNull; } @Override
/** * Create an initialize a {@link LazyObject} with the given bytes for the given fieldID. * * @param fieldID * field for which the object is to be created * @param bytes * value with which the object is to be initialized with * @return initialized {@link LazyObject} * */ public LazyObject<? extends ObjectInspector> toLazyObject(int fieldID, byte[] bytes) { ObjectInspector fieldOI = oi.getAllStructFieldRefs().get(fieldID).getFieldObjectInspector(); LazyObject<? extends ObjectInspector> lazyObject = LazyFactory .createLazyObject(fieldOI); ByteArrayRef ref = new ByteArrayRef(); ref.setData(bytes); // initialize the lazy object lazyObject.init(ref, 0, ref.getData().length); return lazyObject; }
/** * Get the value in the map for the given key. * * @param key * The key, a column qualifier, from the map * @return The object in the map at the given key */ @Override public Object getMapValueElement(Object key) { if (!getParsed()) { parse(); } for (Map.Entry<Object,Object> entry : cachedMap.entrySet()) { LazyPrimitive<?,?> lazyKey = (LazyPrimitive<?,?>) entry.getKey(); // getWritableObject() will convert LazyPrimitive to actual primitive // writable objects. Object keyI = lazyKey.getWritableObject(); if (keyI == null) { continue; } if (keyI.equals(key)) { // Got a match, return the value LazyObject<?> v = (LazyObject<?>) entry.getValue(); return v == null ? v : v.getObject(); } } return null; }
/** * Get the value object with the index without checking parsed. * * @param index * The index into the array starting from 0 */ private Object uncheckedGetValue(int index) { if (valueInited[index]) { return valueObjects[index].getObject(); } valueInited[index] = true; Text nullSequence = oi.getNullSequence(); int valueIBegin = keyEnd[index] + 1; int valueILength = valueLength[index]; if (valueObjects[index] == null) { valueObjects[index] = LazyFactory.createLazyObject(oi.getMapValueObjectInspector()); } if (isNull(oi.getNullSequence(), bytes, valueIBegin, valueILength)) { valueObjects[index].setNull(); } else { valueObjects[index].init(bytes, valueIBegin, valueILength); } return valueObjects[index].getObject(); }
/** * Get the element without checking out-of-bound index. */ private Object uncheckedGetElement(int index) { Text nullSequence = oi.getNullSequence(); int elementLength = startPosition[index + 1] - startPosition[index] - 1; if (elementLength == nullSequence.getLength() && 0 == LazyUtils .compare(bytes.getData(), startPosition[index], elementLength, nullSequence.getBytes(), 0, nullSequence.getLength())) { return null; } else { if (!elementInited[index]) { elementInited[index] = true; if (arrayElements[index] == null) { arrayElements[index] = LazyFactory .createLazyObject(((ListObjectInspector) oi) .getListElementObjectInspector()); } arrayElements[index].init(bytes, startPosition[index], elementLength); } } return arrayElements[index].getObject(); }
/** * Create an initialize a {@link LazyObject} with the given bytes for the given fieldID. * * @param fieldID field for which the object is to be created * @param bytes value with which the object is to be initialized with * @return initialized {@link LazyObject} * */ public LazyObject<? extends ObjectInspector> toLazyObject(int fieldID, byte[] bytes) { ObjectInspector fieldOI = oi.getAllStructFieldRefs().get(fieldID).getFieldObjectInspector(); LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(fieldOI); ByteArrayRef ref = new ByteArrayRef(); ref.setData(bytes); // initialize the lazy object lazyObject.init(ref, 0, ref.getData().length); return lazyObject; } }
/** * Get the value in the map for the given key. * * @param key * The key, a column qualifier, from the map * @return The object in the map at the given key */ @Override public Object getMapValueElement(Object key) { if (!getParsed()) { parse(); } for (Map.Entry<Object,Object> entry : cachedMap.entrySet()) { LazyPrimitive<?,?> lazyKey = (LazyPrimitive<?,?>) entry.getKey(); // getWritableObject() will convert LazyPrimitive to actual primitive // writable objects. Object keyI = lazyKey.getWritableObject(); if (keyI == null) { continue; } if (keyI.equals(key)) { // Got a match, return the value LazyObject<?> v = (LazyObject<?>) entry.getValue(); return v == null ? v : v.getObject(); } } return null; }
/** * Create an initialize a {@link LazyObject} with the given bytes for the given fieldID. * * @param fieldID field for which the object is to be created * @param bytes value with which the object is to be initialized with * * @return initialized {@link LazyObject} * */ @Override public LazyObject<? extends ObjectInspector> toLazyObject(int fieldID, byte[] bytes) { ObjectInspector fieldOI = oi.getAllStructFieldRefs().get(fieldID).getFieldObjectInspector(); LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(fieldOI); ByteArrayRef ref = new ByteArrayRef(); ref.setData(bytes); // initialize the lazy object lazyObject.init(ref, 0, ref.getData().length); return lazyObject; } }