use of org.apache.flink.table.data.ArrayData in project flink by apache.
the class ArrayWriter method doWrite.
@Override
public void doWrite(T in, int ordinal) {
if (!isNullAt(in, ordinal)) {
((ListVector) getValueVector()).startNewValue(getCount());
ArrayData array = readArray(in, ordinal);
for (int i = 0; i < array.size(); i++) {
elementWriter.write(array, i);
}
((ListVector) getValueVector()).endValue(getCount(), array.size());
}
}
use of org.apache.flink.table.data.ArrayData in project flink by apache.
the class RowDataVectorizer method setColumn.
private static void setColumn(int rowId, ListColumnVector listColumnVector, LogicalType type, RowData row, int columnId) {
ArrayData arrayData = row.getArray(columnId);
ArrayType arrayType = (ArrayType) type;
listColumnVector.lengths[rowId] = arrayData.size();
listColumnVector.offsets[rowId] = listColumnVector.childCount;
listColumnVector.childCount += listColumnVector.lengths[rowId];
listColumnVector.child.ensureSize(listColumnVector.childCount, listColumnVector.offsets[rowId] != 0);
RowData convertedRowData = convert(arrayData, arrayType.getElementType());
for (int i = 0; i < arrayData.size(); i++) {
setColumn((int) listColumnVector.offsets[rowId] + i, listColumnVector.child, arrayType.getElementType(), convertedRowData, i);
}
}
use of org.apache.flink.table.data.ArrayData in project flink by apache.
the class RowDataVectorizer method setColumn.
private static void setColumn(int rowId, MapColumnVector mapColumnVector, LogicalType type, RowData row, int columnId) {
MapData mapData = row.getMap(columnId);
MapType mapType = (MapType) type;
ArrayData keyArray = mapData.keyArray();
ArrayData valueArray = mapData.valueArray();
mapColumnVector.lengths[rowId] = mapData.size();
mapColumnVector.offsets[rowId] = mapColumnVector.childCount;
mapColumnVector.childCount += mapColumnVector.lengths[rowId];
mapColumnVector.keys.ensureSize(mapColumnVector.childCount, mapColumnVector.offsets[rowId] != 0);
mapColumnVector.values.ensureSize(mapColumnVector.childCount, mapColumnVector.offsets[rowId] != 0);
RowData convertedKeyRowData = convert(keyArray, mapType.getKeyType());
RowData convertedValueRowData = convert(valueArray, mapType.getValueType());
for (int i = 0; i < keyArray.size(); i++) {
setColumn((int) mapColumnVector.offsets[rowId] + i, mapColumnVector.keys, mapType.getKeyType(), convertedKeyRowData, i);
setColumn((int) mapColumnVector.offsets[rowId] + i, mapColumnVector.values, mapType.getValueType(), convertedValueRowData, i);
}
}
use of org.apache.flink.table.data.ArrayData in project flink by apache.
the class RowDataToCsvConverters method createArrayRowFieldConverter.
private static RowFieldConverter createArrayRowFieldConverter(ArrayType type) {
LogicalType elementType = type.getElementType();
final ArrayElementConverter elementConverter = createNullableArrayElementConverter(elementType);
return (csvMapper, container, row, pos) -> {
ArrayNode arrayNode = csvMapper.createArrayNode();
ArrayData arrayData = row.getArray(pos);
int numElements = arrayData.size();
for (int i = 0; i < numElements; i++) {
arrayNode.add(elementConverter.convert(csvMapper, arrayNode, arrayData, i));
}
return arrayNode;
};
}
use of org.apache.flink.table.data.ArrayData in project flink by apache.
the class InternalDataUtils method toGenericArray.
static GenericArrayData toGenericArray(ArrayData arrayData, LogicalType logicalType) {
final LogicalType innerElement = ((ArrayType) logicalType).getElementType();
final ArrayData.ElementGetter elementGetter = ArrayData.createElementGetter(innerElement);
final Object[] newArray = new Object[arrayData.size()];
for (int i = 0; i < arrayData.size(); i++) {
if (arrayData.isNullAt(i)) {
newArray[i] = null;
} else {
newArray[i] = toGenericInternalData(elementGetter.getElementOrNull(arrayData, i), innerElement);
}
}
return new GenericArrayData(newArray);
}
Aggregations