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));
}
}
}
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);
}
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);
}
}
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);
}
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);
}
}
Aggregations