use of org.apache.flink.table.data.GenericMapData in project flink by apache.
the class JsonToRowDataConverters method createMapConverter.
private JsonToRowDataConverter createMapConverter(String typeSummary, LogicalType keyType, LogicalType valueType) {
if (!keyType.is(LogicalTypeFamily.CHARACTER_STRING)) {
throw new UnsupportedOperationException("JSON format doesn't support non-string as key type of map. " + "The type is: " + typeSummary);
}
final JsonToRowDataConverter keyConverter = createConverter(keyType);
final JsonToRowDataConverter valueConverter = createConverter(valueType);
return jsonNode -> {
Iterator<Map.Entry<String, JsonNode>> fields = jsonNode.fields();
Map<Object, Object> result = new HashMap<>();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> entry = fields.next();
Object key = keyConverter.convert(TextNode.valueOf(entry.getKey()));
Object value = valueConverter.convert(entry.getValue());
result.put(key, value);
}
return new GenericMapData(result);
};
}
use of org.apache.flink.table.data.GenericMapData 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.GenericMapData in project flink by apache.
the class OrcBulkRowDataWriterTest method initInput.
@Before
public void initInput() {
input = new ArrayList<>();
fieldTypes = new LogicalType[4];
fieldTypes[0] = new VarCharType();
fieldTypes[1] = new IntType();
List<RowType.RowField> arrayRowFieldList = Collections.singletonList(new RowType.RowField("_col2_col0", new VarCharType()));
fieldTypes[2] = new ArrayType(new RowType(arrayRowFieldList));
List<RowType.RowField> mapRowFieldList = Arrays.asList(new RowType.RowField("_col3_col0", new VarCharType()), new RowType.RowField("_col3_col1", new TimestampType()));
fieldTypes[3] = new MapType(new VarCharType(), new RowType(mapRowFieldList));
{
GenericRowData rowData = new GenericRowData(4);
rowData.setField(0, new BinaryStringData("_col_0_string_1"));
rowData.setField(1, 1);
GenericRowData arrayValue1 = new GenericRowData(1);
arrayValue1.setField(0, new BinaryStringData("_col_2_row_0_string_1"));
GenericRowData arrayValue2 = new GenericRowData(1);
arrayValue2.setField(0, new BinaryStringData("_col_2_row_1_string_1"));
GenericArrayData arrayData = new GenericArrayData(new Object[] { arrayValue1, arrayValue2 });
rowData.setField(2, arrayData);
GenericRowData mapValue1 = new GenericRowData(2);
mapValue1.setField(0, new BinaryStringData(("_col_3_map_value_string_1")));
mapValue1.setField(1, TimestampData.fromTimestamp(new Timestamp(3600000)));
Map<StringData, RowData> mapDataMap = new HashMap<>();
mapDataMap.put(new BinaryStringData("_col_3_map_key_1"), mapValue1);
GenericMapData mapData = new GenericMapData(mapDataMap);
rowData.setField(3, mapData);
input.add(rowData);
}
{
GenericRowData rowData = new GenericRowData(4);
rowData.setField(0, new BinaryStringData("_col_0_string_2"));
rowData.setField(1, 2);
GenericRowData arrayValue1 = new GenericRowData(1);
arrayValue1.setField(0, new BinaryStringData("_col_2_row_0_string_2"));
GenericRowData arrayValue2 = new GenericRowData(1);
arrayValue2.setField(0, new BinaryStringData("_col_2_row_1_string_2"));
GenericArrayData arrayData = new GenericArrayData(new Object[] { arrayValue1, arrayValue2 });
rowData.setField(2, arrayData);
GenericRowData mapValue1 = new GenericRowData(2);
mapValue1.setField(0, new BinaryStringData(("_col_3_map_value_string_2")));
mapValue1.setField(1, TimestampData.fromTimestamp(new Timestamp(3600000)));
Map<StringData, RowData> mapDataMap = new HashMap<>();
mapDataMap.put(new BinaryStringData("_col_3_map_key_2"), mapValue1);
GenericMapData mapData = new GenericMapData(mapDataMap);
rowData.setField(3, mapData);
input.add(rowData);
}
}
Aggregations