Search in sources :

Example 11 with ArrayData

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());
    }
}
Also used : ListVector(org.apache.arrow.vector.complex.ListVector) ArrayData(org.apache.flink.table.data.ArrayData)

Example 12 with ArrayData

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);
    }
}
Also used : ArrayType(org.apache.flink.table.types.logical.ArrayType) RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) ArrayData(org.apache.flink.table.data.ArrayData)

Example 13 with ArrayData

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);
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) MapData(org.apache.flink.table.data.MapData) MapType(org.apache.flink.table.types.logical.MapType) ArrayData(org.apache.flink.table.data.ArrayData)

Example 14 with ArrayData

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;
    };
}
Also used : Arrays(java.util.Arrays) SQL_TIMESTAMP_FORMAT(org.apache.flink.formats.common.TimeFormats.SQL_TIMESTAMP_FORMAT) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) RowType(org.apache.flink.table.types.logical.RowType) ArrayNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode) TimestampType(org.apache.flink.table.types.logical.TimestampType) SQL_TIMESTAMP_WITH_LOCAL_TIMEZONE_FORMAT(org.apache.flink.formats.common.TimeFormats.SQL_TIMESTAMP_WITH_LOCAL_TIMEZONE_FORMAT) DecimalType(org.apache.flink.table.types.logical.DecimalType) LocalTime(java.time.LocalTime) ISO_LOCAL_DATE(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) RowData(org.apache.flink.table.data.RowData) TimestampData(org.apache.flink.table.data.TimestampData) ObjectNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode) DecimalData(org.apache.flink.table.data.DecimalData) ArrayType(org.apache.flink.table.types.logical.ArrayType) Serializable(java.io.Serializable) Converter(org.apache.flink.formats.common.Converter) ArrayData(org.apache.flink.table.data.ArrayData) LogicalType(org.apache.flink.table.types.logical.LogicalType) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Internal(org.apache.flink.annotation.Internal) ISO_LOCAL_TIME(java.time.format.DateTimeFormatter.ISO_LOCAL_TIME) ContainerNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ContainerNode) CsvMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvMapper) LogicalType(org.apache.flink.table.types.logical.LogicalType) ArrayNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode) ArrayData(org.apache.flink.table.data.ArrayData)

Example 15 with ArrayData

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);
}
Also used : ArrayType(org.apache.flink.table.types.logical.ArrayType) GenericArrayData(org.apache.flink.table.data.GenericArrayData) LogicalType(org.apache.flink.table.types.logical.LogicalType) GenericArrayData(org.apache.flink.table.data.GenericArrayData) ArrayData(org.apache.flink.table.data.ArrayData)

Aggregations

ArrayData (org.apache.flink.table.data.ArrayData)16 LogicalType (org.apache.flink.table.types.logical.LogicalType)6 GenericRowData (org.apache.flink.table.data.GenericRowData)5 RowData (org.apache.flink.table.data.RowData)5 ArrayType (org.apache.flink.table.types.logical.ArrayType)4 HashMap (java.util.HashMap)3 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)3 DecimalData (org.apache.flink.table.data.DecimalData)3 GenericArrayData (org.apache.flink.table.data.GenericArrayData)3 MapData (org.apache.flink.table.data.MapData)3 TimestampData (org.apache.flink.table.data.TimestampData)3 Serializable (java.io.Serializable)2 LocalDate (java.time.LocalDate)2 LocalTime (java.time.LocalTime)2 ISO_LOCAL_DATE (java.time.format.DateTimeFormatter.ISO_LOCAL_DATE)2 Arrays (java.util.Arrays)2 Schema (org.apache.avro.Schema)2 Internal (org.apache.flink.annotation.Internal)2 SQL_TIMESTAMP_FORMAT (org.apache.flink.formats.common.TimeFormats.SQL_TIMESTAMP_FORMAT)2 SQL_TIMESTAMP_WITH_LOCAL_TIMEZONE_FORMAT (org.apache.flink.formats.common.TimeFormats.SQL_TIMESTAMP_WITH_LOCAL_TIMEZONE_FORMAT)2