@Override public List<?> getList(Object data) { if (data == null) { return null; } LazyArray array = (LazyArray) data; return array.getList(); }
/** * 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."); }
/** * Returns the actual primitive object at the index position inside the array * represented by this LazyObject. */ public Object getListElementObject(int index) { if (!parsed) { parse(); } if (index < 0 || index >= arrayLength) { return null; } return uncheckedGetElement(index); }
/** * Returns -1 for null array. */ public int getListLength() { if (!parsed) { parse(); } return arrayLength; }
@Override public Object getListElement(Object data, int index) { if (data == null) { return null; } LazyArray array = (LazyArray) data; return array.getListElementObject(index); }
@Override public int getListLength(Object data) { if (data == null) { return -1; } LazyArray array = (LazyArray) data; return array.getListLength(); }
/** * 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(); }
/** * Returns the List of actual primitive objects. Returns null for null array. */ public List<Object> getList() { if (!parsed) { parse(); } if (arrayLength == -1) { return null; } if (cachedList != null) { return cachedList; } cachedList = new ArrayList<Object>(arrayLength); for (int index = 0; index < arrayLength; index++) { cachedList.add(uncheckedGetElement(index)); } return cachedList; } }
/** * Returns -1 for null array. */ public int getListLength() { if (!parsed) { parse(); } return arrayLength; }
@Override public Object getListElement(Object data, int index) { if (data == null) { return null; } LazyArray array = (LazyArray) data; return array.getListElementObject(index); }
@Override public int getListLength(Object data) { if (data == null) { return -1; } LazyArray array = (LazyArray) data; return array.getListLength(); }
/** * 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(); }
/** * 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} * */ private Object toLazyListObject(Object obj, ObjectInspector objectInspector) { if (obj == null) { return null; } List<?> listObj = (List<?>) obj; LazyArray retList = (LazyArray) LazyFactory.createLazyObject(objectInspector); List<Object> lazyList = retList.getList(); ObjectInspector listElementOI = ((ListObjectInspector) objectInspector).getListElementObjectInspector(); for (int i = 0; i < listObj.size(); i++) { lazyList.add(toLazyObject(listObj.get(i), listElementOI)); } return retList; }
/** * Returns the actual primitive object at the index position inside the array * represented by this LazyObject. */ public Object getListElementObject(int index) { if (!parsed) { parse(); } if (index < 0 || index >= arrayLength) { return null; } return uncheckedGetElement(index); }
var nums = new LazyArray([1,2,3,4,5,6,7,8,9]); var multiplesOf2 = nums.filter(...); var multiplesOf3 = nums.filter(...); var greaterThan7 = nums.filter(...); nums.iterate();
/** * Returns -1 for null array. */ public int getListLength() { if (!parsed) { parse(); } return arrayLength; }
@Override public Object getListElement(Object data, int index) { if (data == null) { return null; } LazyArray array = (LazyArray) data; return array.getListElementObject(index); }
@Override public int getListLength(Object data) { if (data == null) { return -1; } LazyArray array = (LazyArray) data; return array.getListLength(); }