@Override public Map<?, ?> getMap(Object data) { if (data == null) { return null; } return ((LazyMap) data).getMap(); }
/** * Create a hierarchical LazyObject based on the given typeInfo. */ public static LazyObject<? extends ObjectInspector> createLazyObject(ObjectInspector oi) { ObjectInspector.Category c = oi.getCategory(); switch (c) { case PRIMITIVE: return createLazyPrimitiveClass((PrimitiveObjectInspector) oi); case MAP: return new LazyMap((LazyMapObjectInspector) oi); case LIST: return new LazyArray((LazyListObjectInspector) oi); case STRUCT: return new LazyStruct((LazySimpleStructObjectInspector) oi); case UNION: return new LazyUnion((LazyUnionObjectInspector) oi); } throw new RuntimeException("Hive LazySerDe Internal error."); }
enlargeArrays(); : keyValueSeparatorPosition); valueLength[mapSize] = elementByteEnd - (keyEnd[mapSize] + 1); LazyPrimitive<?, ?> lazyKey = uncheckedGetKey(mapSize); if (lazyKey == null) { LOG.warn("skipped empty entry or entry with empty key in the representation of column with MAP type.");
/** * Return the map object representing this LazyMap. Note that the keyObjects * will be Writable primitive objects. * * @return the map object */ public Map<Object, Object> getMap() { if (!parsed) { parse(); } if (cachedMap != null) { return cachedMap; } // Use LinkedHashMap to provide deterministic order cachedMap = new LinkedHashMap<Object, Object>(); // go through each element of the map for (int i = 0; i < mapSize; i++) { LazyPrimitive<?, ?> lazyKey = uncheckedGetKey(i); if (lazyKey == null) { continue; } Object key = lazyKey.getObject(); // do not overwrite if there are duplicate keys if (key != null && !cachedMap.containsKey(key)) { cachedMap.put(key, uncheckedGetValue(i)); } } return cachedMap; }
public static void assertMapDecode(String encodedMap, Map<? extends Object, ? extends Object> expectedMap) { LazyMap lazyMap = (LazyMap) createLazyObject(getLazySimpleMapObjectInspector( LAZY_STRING_OBJECT_INSPECTOR, getLazyStringObjectInspector(false, (byte) 0), (byte) 2, (byte) 3, new Text("\\N"), false, (byte) 0)); lazyMap.init(newByteArrayRef(encodedMap), 0, encodedMap.length()); Map<Object, Object> map = lazyMap.getMap(); assertEquals(map, expectedMap); }
/** * Get the key object with the index without checking parsed. * * @param index * The index into the array starting from 0 */ private LazyPrimitive<?, ?> uncheckedGetKey(int index) { if (keyInited[index]) { return keyObjects[index]; } int keyIBegin = keyStart[index]; int keyILength = keyEnd[index] - keyStart[index]; if (isNull(oi.getNullSequence(), bytes, keyIBegin, keyILength)) { return null; } keyInited[index] = true; if (keyObjects[index] == null) { keyObjects[index] = LazyFactory.createLazyPrimitiveClass( (PrimitiveObjectInspector) oi.getMapKeyObjectInspector()); } keyObjects[index].init(bytes, keyIBegin, keyILength); return keyObjects[index]; }
/** * Get the size of the map represented by this LazyMap. * * @return The size of the map, -1 for NULL map. */ public int getMapSize() { if (!parsed) { parse(); } return mapSize; }
@Override public int getMapSize(Object data) { if (data == null) { return -1; } return ((LazyMap) data).getMapSize(); }
@Override public Object getMapValueElement(Object data, Object key) { return ((data==null || key == null)? null : ((LazyMap) data).getMapValueElement(key)); }
parse(); LazyPrimitive<?, ?> lazyKeyI = uncheckedGetKey(i); if (lazyKeyI == null) { continue; return uncheckedGetValue(i);
public static void assertMapDecode(String encodedMap, Map<? extends Object, ? extends Object> expectedMap) { LazyMap lazyMap = (LazyMap) createLazyObject(getLazySimpleMapObjectInspector( LAZY_STRING_OBJECT_INSPECTOR, getLazyStringObjectInspector(false, (byte) 0), (byte) 2, (byte) 3, new Text("\\N"), false, (byte) 0)); lazyMap.init(newByteArrayRef(encodedMap), 0, encodedMap.length()); Map<Object, Object> map = lazyMap.getMap(); assertEquals(map, expectedMap); }
/** * 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 size of the map represented by this LazyMap. * * @return The size of the map, -1 for NULL map. */ public int getMapSize() { if (!parsed) { parse(); } return mapSize; }
@Override public int getMapSize(Object data) { if (data == null) { return -1; } return ((LazyMap) data).getMapSize(); }
@Override public Object getMapValueElement(Object data, Object key) { if (data == null) { return null; } return ((LazyMap) data).getMapValueElement(key); }
/** * Convert the given object to a lazy object using the given {@link ObjectInspector} * * @param obj Object to be converted to a {@link LazyObject} * @param objectInspector ObjectInspector used for the conversion * @return the created {@link LazyObject lazy object} * */ @SuppressWarnings({ "rawtypes", "unchecked" }) private Object toLazyMapObject(Object obj, ObjectInspector objectInspector) { if (obj == null) { return null; } // avro guarantees that the key will be of type string. So we just need to worry about // deserializing the value here LazyMap lazyMap = (LazyMap) LazyFactory.createLazyObject(objectInspector); Map map = lazyMap.getMap(); Map<Object, Object> origMap = (Map) obj; ObjectInspector keyObjectInspector = ((MapObjectInspector) objectInspector).getMapKeyObjectInspector(); ObjectInspector valueObjectInspector = ((MapObjectInspector) objectInspector).getMapValueObjectInspector(); for (Entry entry : origMap.entrySet()) { Object value = entry.getValue(); map.put(toLazyPrimitiveObject(entry.getKey(), keyObjectInspector), toLazyObject(value, valueObjectInspector)); } return lazyMap; }
/** * Return the map object representing this LazyMap. Note that the keyObjects * will be Writable primitive objects. * * @return the map object */ public Map<Object, Object> getMap() { if (!parsed) { parse(); } if (cachedMap != null) { return cachedMap; } // Use LinkedHashMap to provide deterministic order cachedMap = new LinkedHashMap<Object, Object>(); // go through each element of the map for (int i = 0; i < mapSize; i++) { LazyPrimitive<?, ?> lazyKey = uncheckedGetKey(i); if (lazyKey == null) { continue; } Object key = lazyKey.getObject(); // do not overwrite if there are duplicate keys if (key != null && !cachedMap.containsKey(key)) { cachedMap.put(key, uncheckedGetValue(i)); } } return cachedMap; }
public static void assertMapDecode(String encodedMap, Map<? extends Object, ? extends Object> expectedMap) { LazyMap lazyMap = (LazyMap) createLazyObject(getLazySimpleMapObjectInspector( LAZY_STRING_OBJECT_INSPECTOR, getLazyStringObjectInspector(false, (byte) 0), (byte) 2, (byte) 3, new Text("\\N"), false, (byte) 0)); lazyMap.init(newByteArrayRef(encodedMap), 0, encodedMap.length()); Map<Object, Object> map = lazyMap.getMap(); assertEquals(map, expectedMap); }
enlargeArrays(); : keyValueSeparatorPosition); valueLength[mapSize] = elementByteEnd - (keyEnd[mapSize] + 1); LazyPrimitive<?, ?> lazyKey = uncheckedGetKey(mapSize); if (lazyKey == null) { LOG.warn("skipped empty entry or entry with empty key in the representation of column with MAP type.");