use of org.apache.flink.table.types.logical.LogicalTypeRoot.STRUCTURED_TYPE in project flink by apache.
the class DataViewUtils method extractDataViews.
/**
* Searches for data views in the data type of an accumulator and extracts them.
*/
public static List<DataViewSpec> extractDataViews(int aggIndex, DataType accumulatorDataType) {
final LogicalType accumulatorType = accumulatorDataType.getLogicalType();
if (!accumulatorType.is(ROW) && !accumulatorType.is(STRUCTURED_TYPE)) {
return Collections.emptyList();
}
final List<String> fieldNames = getFieldNames(accumulatorType);
final List<DataType> fieldDataTypes = accumulatorDataType.getChildren();
final List<DataViewSpec> specs = new ArrayList<>();
for (int fieldIndex = 0; fieldIndex < fieldDataTypes.size(); fieldIndex++) {
final DataType fieldDataType = fieldDataTypes.get(fieldIndex);
final LogicalType fieldType = fieldDataType.getLogicalType();
if (isDataView(fieldType, ListView.class)) {
specs.add(new ListViewSpec(createStateId(aggIndex, fieldNames.get(fieldIndex)), fieldIndex, fieldDataType.getChildren().get(0)));
} else if (isDataView(fieldType, MapView.class)) {
specs.add(new MapViewSpec(createStateId(aggIndex, fieldNames.get(fieldIndex)), fieldIndex, fieldDataType.getChildren().get(0), false));
}
if (fieldType.getChildren().stream().anyMatch(c -> hasNested(c, t -> isDataView(t, DataView.class)))) {
throw new TableException("Data views are only supported in the first level of a composite accumulator type.");
}
}
return specs;
}
Aggregations