/** * Creates an ArrayType by specifying the data type of elements ({@code elementType}) and * whether the array contains null values ({@code containsNull}). */ public static ArrayType createArrayType(DataType elementType, boolean containsNull) { if (elementType == null) { throw new IllegalArgumentException("elementType should not be null."); } return new ArrayType(elementType, containsNull); }
private static void appendValue(WritableColumnVector dst, DataType t, Row src, int fieldIdx) { if (t instanceof ArrayType) { ArrayType at = (ArrayType)t; if (src.isNullAt(fieldIdx)) { dst.appendNull(); } else { List<Object> values = src.getList(fieldIdx); dst.appendArray(values.size()); for (Object o : values) { appendValue(dst.arrayData(), at.elementType(), o); } } } else if (t instanceof StructType) { StructType st = (StructType)t; if (src.isNullAt(fieldIdx)) { dst.appendStruct(true); } else { dst.appendStruct(false); Row c = src.getStruct(fieldIdx); for (int i = 0; i < st.fields().length; i++) { appendValue(dst.getChild(i), st.fields()[i].dataType(), c, i); } } } else { appendValue(dst, t, src.get(fieldIdx)); } }
@Override public Type list(Types.ListType list, Supplier<Type> elementResult) { Preconditions.checkArgument(current instanceof ArrayType, "Not an array: %s", current); ArrayType array = (ArrayType) current; Preconditions.checkArgument(array.containsNull() || !list.isElementOptional(), "Cannot project an array of optional elements as required elements: %s", array); this.current = array.elementType(); try { Type elementType = elementResult.get(); if (list.elementType() == elementType) { return list; } // must be a projected element type, create a new list if (list.isElementOptional()) { return Types.ListType.ofOptional(list.elementId(), elementType); } else { return Types.ListType.ofRequired(list.elementId(), elementType); } } finally { this.current = array; } }
@Override public Type array(ArrayType array, Type elementType) { if (array.containsNull()) { return Types.ListType.ofOptional(getNextId(), elementType); } else { return Types.ListType.ofRequired(getNextId(), elementType); } }
@Override public Type list(Types.ListType list, Supplier<Type> elementResult) { Preconditions.checkArgument(current instanceof ArrayType, "Not an array: %s", current); ArrayType array = (ArrayType) current; Preconditions.checkArgument(array.containsNull() || !list.isElementOptional(), "Cannot project an array of optional elements as required elements: %s", array); this.current = array.elementType(); try { Type elementType = elementResult.get(); if (list.elementType() == elementType) { return list; } // must be a projected element type, create a new list if (list.isElementOptional()) { return Types.ListType.ofOptional(list.elementId(), elementType); } else { return Types.ListType.ofRequired(list.elementId(), elementType); } } finally { this.current = array; } }
Object elementValue = toRowValue(obj, arrayType.elementType(), elementPath); if (elementValue == null && !arrayType.containsNull()) { throw new IllegalArgumentException("Null value is not allowed for array element at " + elementPath);
/** * Creates an ArrayType by specifying the data type of elements ({@code elementType}). * The field of {@code containsNull} is set to {@code true}. */ public static ArrayType createArrayType(DataType elementType) { if (elementType == null) { throw new IllegalArgumentException("elementType should not be null."); } return new ArrayType(elementType, true); }
private static void appendValue(ColumnVector dst, DataType t, Row src, int fieldIdx) { if (t instanceof ArrayType) { ArrayType at = (ArrayType)t; if (src.isNullAt(fieldIdx)) { dst.appendNull(); } else { List<Object> values = src.getList(fieldIdx); dst.appendArray(values.size()); for (Object o : values) { appendValue(dst.arrayData(), at.elementType(), o); } } } else if (t instanceof StructType) { StructType st = (StructType)t; if (src.isNullAt(fieldIdx)) { dst.appendStruct(true); } else { dst.appendStruct(false); Row c = src.getStruct(fieldIdx); for (int i = 0; i < st.fields().length; i++) { appendValue(dst.getChildColumn(i), st.fields()[i].dataType(), c, i); } } } else { appendValue(dst, t, src.get(fieldIdx)); } }
Object elementValue = toRowValue(obj, arrayType.elementType(), elementPath); if (elementValue == null && !arrayType.containsNull()) { throw new IllegalArgumentException("Null value is not allowed for array element at " + elementPath);
/** * Creates an ArrayType by specifying the data type of elements ({@code elementType}) and * whether the array contains null values ({@code containsNull}). */ public static ArrayType createArrayType(DataType elementType, boolean containsNull) { if (elementType == null) { throw new IllegalArgumentException("elementType should not be null."); } return new ArrayType(elementType, containsNull); }
private static void appendValue(WritableColumnVector dst, DataType t, Row src, int fieldIdx) { if (t instanceof ArrayType) { ArrayType at = (ArrayType)t; if (src.isNullAt(fieldIdx)) { dst.appendNull(); } else { List<Object> values = src.getList(fieldIdx); dst.appendArray(values.size()); for (Object o : values) { appendValue(dst.arrayData(), at.elementType(), o); } } } else if (t instanceof StructType) { StructType st = (StructType)t; if (src.isNullAt(fieldIdx)) { dst.appendStruct(true); } else { dst.appendStruct(false); Row c = src.getStruct(fieldIdx); for (int i = 0; i < st.fields().length; i++) { appendValue(dst.getChild(i), st.fields()[i].dataType(), c, i); } } } else { appendValue(dst, t, src.get(fieldIdx)); } }
Object elementValue = toRowValue(obj, arrayType.elementType(), elementPath); if (elementValue == null && !arrayType.containsNull()) { throw new IllegalArgumentException("Null value is not allowed for array element at " + elementPath);
/** * Creates an ArrayType by specifying the data type of elements ({@code elementType}). * The field of {@code containsNull} is set to {@code true}. */ public static ArrayType createArrayType(DataType elementType) { if (elementType == null) { throw new IllegalArgumentException("elementType should not be null."); } return new ArrayType(elementType, true); }
int childCapacity = capacity; if (type instanceof ArrayType) { childType = ((ArrayType)type).elementType(); } else { childType = DataTypes.ByteType;
case "array": DataType elementType = ((ArrayType) type).elementType(); ArrayList<Object> arrayList = new ArrayList<>(); type, elementType, value)); } else if (!((ArrayType) type).containsNull()) { throw new RuntimeException(String.format("Type[%s] - Element cannot be 'null': %s[null]", type, elementType)); type, elementType, value)); } else if (!((ArrayType) type).containsNull()) { throw new RuntimeException(String.format("Type[%s] - Value cannot be 'null': %s[null]", type, elementType));
/** * Creates an ArrayType by specifying the data type of elements ({@code elementType}) and * whether the array contains null values ({@code containsNull}). */ public static ArrayType createArrayType(DataType elementType, boolean containsNull) { if (elementType == null) { throw new IllegalArgumentException("elementType should not be null."); } return new ArrayType(elementType, containsNull); }
int childCapacity = capacity; if (type instanceof ArrayType) { childType = ((ArrayType)type).elementType(); } else { childType = DataTypes.ByteType;
if (arrayType.elementType() == DataTypes.ByteType) { return Schema.of(Schema.Type.BYTES); Schema componentSchema = dataTypeToSchema(arrayType.elementType(), recordCounter); return Schema.arrayOf(arrayType.containsNull() ? Schema.nullableOf(componentSchema) : componentSchema);
/** * Creates an ArrayType by specifying the data type of elements ({@code elementType}). * The field of {@code containsNull} is set to {@code true}. */ public static ArrayType createArrayType(DataType elementType) { if (elementType == null) { throw new IllegalArgumentException("elementType should not be null."); } return new ArrayType(elementType, true); }
int childCapacity = capacity; if (type instanceof ArrayType) { childType = ((ArrayType)type).elementType(); } else { childType = DataTypes.ByteType;