Search in sources :

Example 6 with StringData

use of org.apache.flink.table.data.StringData in project flink by apache.

the class JsonObjectAggFunction method merge.

public void merge(Accumulator acc, Iterable<Accumulator> others) throws Exception {
    for (final Accumulator other : others) {
        for (final StringData key : other.map.keys()) {
            assertKeyNotPresent(acc, key);
            acc.map.put(key, other.map.get(key));
        }
    }
}
Also used : StringData(org.apache.flink.table.data.StringData)

Example 7 with StringData

use of org.apache.flink.table.data.StringData in project flink by apache.

the class OrcBulkRowDataWriterTest method readMap.

/**
 * Read MapColumnVector with specify schema {@literal
 * map<string,struct<_col3_col0:string,_col3_col1:timestamp>>}.
 */
private static MapData readMap(MapColumnVector mapVector, int row) {
    int offset = (int) mapVector.offsets[row];
    StringData keyData = readStringData((BytesColumnVector) mapVector.keys, offset);
    GenericRowData valueData = new GenericRowData(2);
    StructColumnVector structVector = (StructColumnVector) mapVector.values;
    BytesColumnVector bytesVector = (BytesColumnVector) structVector.fields[0];
    TimestampColumnVector timestampVector = (TimestampColumnVector) structVector.fields[1];
    StringData strValueData = readStringData(bytesVector, offset);
    TimestampData timestampData = readTimestamp(timestampVector, offset);
    valueData.setField(0, strValueData);
    valueData.setField(1, timestampData);
    Map<StringData, RowData> mapDataMap = new HashMap<>();
    mapDataMap.put(keyData, valueData);
    return new GenericMapData(mapDataMap);
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) GenericMapData(org.apache.flink.table.data.GenericMapData) TimestampData(org.apache.flink.table.data.TimestampData) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) StructColumnVector(org.apache.hadoop.hive.ql.exec.vector.StructColumnVector) HashMap(java.util.HashMap) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) GenericRowData(org.apache.flink.table.data.GenericRowData) BinaryStringData(org.apache.flink.table.data.binary.BinaryStringData) StringData(org.apache.flink.table.data.StringData)

Example 8 with StringData

use of org.apache.flink.table.data.StringData in project flink by apache.

the class ListAggWithRetractAggFunction method merge.

public void merge(ListAggWithRetractAccumulator acc, Iterable<ListAggWithRetractAccumulator> its) throws Exception {
    for (ListAggWithRetractAccumulator otherAcc : its) {
        // merge list of acc and other
        List<StringData> buffer = new ArrayList<>();
        for (StringData binaryString : acc.list.get()) {
            buffer.add(binaryString);
        }
        for (StringData binaryString : otherAcc.list.get()) {
            buffer.add(binaryString);
        }
        // merge retract list of acc and other
        List<StringData> retractBuffer = new ArrayList<>();
        for (StringData binaryString : acc.retractList.get()) {
            retractBuffer.add(binaryString);
        }
        for (StringData binaryString : otherAcc.retractList.get()) {
            retractBuffer.add(binaryString);
        }
        // merge list & retract list
        List<StringData> newRetractBuffer = new ArrayList<>();
        for (StringData binaryString : retractBuffer) {
            if (!buffer.remove(binaryString)) {
                newRetractBuffer.add(binaryString);
            }
        }
        // update to acc
        acc.list.clear();
        acc.list.addAll(buffer);
        acc.retractList.clear();
        acc.retractList.addAll(newRetractBuffer);
    }
}
Also used : ArrayList(java.util.ArrayList) BinaryStringData(org.apache.flink.table.data.binary.BinaryStringData) StringData(org.apache.flink.table.data.StringData)

Example 9 with StringData

use of org.apache.flink.table.data.StringData in project flink by apache.

the class JsonArrayAggFunction method getValue.

@Override
public String getValue(Accumulator acc) {
    final ArrayNode rootNode = createArrayNode();
    try {
        for (final StringData item : acc.list.get()) {
            final JsonNode itemNode = getNodeFactory().rawValueNode(new RawValue(item.toString()));
            rootNode.add(itemNode);
        }
    } catch (Exception e) {
        throw new TableException("The accumulator state could not be serialized.", e);
    }
    return serializeJson(rootNode);
}
Also used : TableException(org.apache.flink.table.api.TableException) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) SqlJsonUtils.createArrayNode(org.apache.flink.table.runtime.functions.SqlJsonUtils.createArrayNode) ArrayNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode) StringData(org.apache.flink.table.data.StringData) RawValue(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue) TableException(org.apache.flink.table.api.TableException)

Example 10 with StringData

use of org.apache.flink.table.data.StringData in project flink by apache.

the class ListAggWsWithRetractAggFunction method merge.

public void merge(ListAggWsWithRetractAccumulator acc, Iterable<ListAggWsWithRetractAccumulator> its) throws Exception {
    for (ListAggWsWithRetractAccumulator otherAcc : its) {
        if (!otherAcc.list.get().iterator().hasNext() && !otherAcc.retractList.get().iterator().hasNext()) {
            // otherAcc is empty, skip it
            continue;
        }
        acc.delimiter = otherAcc.delimiter;
        // merge list of acc and other
        List<StringData> buffer = new ArrayList<>();
        for (StringData binaryString : acc.list.get()) {
            buffer.add(binaryString);
        }
        for (StringData binaryString : otherAcc.list.get()) {
            buffer.add(binaryString);
        }
        // merge retract list of acc and other
        List<StringData> retractBuffer = new ArrayList<>();
        for (StringData binaryString : acc.retractList.get()) {
            retractBuffer.add(binaryString);
        }
        for (StringData binaryString : otherAcc.retractList.get()) {
            retractBuffer.add(binaryString);
        }
        // merge list & retract list
        List<StringData> newRetractBuffer = new ArrayList<>();
        for (StringData binaryString : retractBuffer) {
            if (!buffer.remove(binaryString)) {
                newRetractBuffer.add(binaryString);
            }
        }
        // update to acc
        acc.list.clear();
        acc.list.addAll(buffer);
        acc.retractList.clear();
        acc.retractList.addAll(newRetractBuffer);
    }
}
Also used : ArrayList(java.util.ArrayList) BinaryStringData(org.apache.flink.table.data.binary.BinaryStringData) StringData(org.apache.flink.table.data.StringData)

Aggregations

StringData (org.apache.flink.table.data.StringData)14 GenericRowData (org.apache.flink.table.data.GenericRowData)5 BinaryStringData (org.apache.flink.table.data.binary.BinaryStringData)5 GenericArrayData (org.apache.flink.table.data.GenericArrayData)3 Test (org.junit.Test)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)2 RawValue (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue)2 TableException (org.apache.flink.table.api.TableException)2 GenericMapData (org.apache.flink.table.data.GenericMapData)2 RowData (org.apache.flink.table.data.RowData)2 TimestampData (org.apache.flink.table.data.TimestampData)2 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)2 ListAggWsWithRetractAccumulator (org.apache.flink.table.runtime.functions.aggregate.ListAggWsWithRetractAggFunction.ListAggWsWithRetractAccumulator)2 VarCharType (org.apache.flink.table.types.logical.VarCharType)2 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)2 StructColumnVector (org.apache.hadoop.hive.ql.exec.vector.StructColumnVector)2 Assert (org.junit.Assert)2 BigDecimal (java.math.BigDecimal)1