use of org.apache.flink.table.data.GenericArrayData in project flink by apache.
the class JsonToRowDataConverters method createArrayConverter.
private JsonToRowDataConverter createArrayConverter(ArrayType arrayType) {
JsonToRowDataConverter elementConverter = createConverter(arrayType.getElementType());
final Class<?> elementClass = LogicalTypeUtils.toInternalConversionClass(arrayType.getElementType());
return jsonNode -> {
final ArrayNode node = (ArrayNode) jsonNode;
final Object[] array = (Object[]) Array.newInstance(elementClass, node.size());
for (int i = 0; i < node.size(); i++) {
final JsonNode innerNode = node.get(i);
array[i] = elementConverter.convert(innerNode);
}
return new GenericArrayData(array);
};
}
use of org.apache.flink.table.data.GenericArrayData 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);
}
}
use of org.apache.flink.table.data.GenericArrayData in project flink by apache.
the class CsvToRowDataConverters method createArrayConverter.
private CsvToRowDataConverter createArrayConverter(ArrayType arrayType) {
final CsvToRowDataConverter elementConverter = createNullableConverter(arrayType.getElementType());
final Class<?> elementClass = LogicalTypeUtils.toInternalConversionClass(arrayType.getElementType());
return jsonNode -> {
final ArrayNode node = (ArrayNode) jsonNode;
final Object[] array = (Object[]) Array.newInstance(elementClass, node.size());
for (int i = 0; i < node.size(); i++) {
final JsonNode innerNode = node.get(i);
array[i] = elementConverter.convert(innerNode);
}
return new GenericArrayData(array);
};
}
use of org.apache.flink.table.data.GenericArrayData in project flink by apache.
the class ArrayDataAssert method asGeneric.
public ArrayDataAssert asGeneric(LogicalType logicalType) {
GenericArrayData actual = InternalDataUtils.toGenericArray(this.actual, logicalType);
return new ArrayDataAssert(actual).usingComparator((x, y) -> {
// Avoid converting actual again
x = x == actual ? x : InternalDataUtils.toGenericArray(x, logicalType);
y = y == actual ? y : InternalDataUtils.toGenericArray(y, logicalType);
if (Objects.equals(x, y)) {
return 0;
}
return Objects.hashCode(x) < Objects.hashCode(y) ? -1 : 1;
});
}
use of org.apache.flink.table.data.GenericArrayData 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