use of org.apache.flink.table.runtime.dataview.MapViewSpec 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;
}
use of org.apache.flink.table.runtime.dataview.MapViewSpec in project flink by apache.
the class CommonPythonUtil method extractDataViewSpecs.
public static DataViewSpec[] extractDataViewSpecs(int index, DataType accType) {
if (!(accType instanceof FieldsDataType)) {
return new DataViewSpec[0];
}
FieldsDataType compositeAccType = (FieldsDataType) accType;
if (includesDataView(compositeAccType)) {
LogicalType logicalType = compositeAccType.getLogicalType();
if (logicalType instanceof RowType) {
List<DataType> childrenDataTypes = compositeAccType.getChildren();
return IntStream.range(0, childrenDataTypes.size()).mapToObj(i -> {
DataType childDataType = childrenDataTypes.get(i);
LogicalType childLogicalType = childDataType.getLogicalType();
if ((childLogicalType instanceof RowType) && includesDataView((FieldsDataType) childDataType)) {
throw new TableException("For Python AggregateFunction, DataView cannot be used in the" + " nested columns of the accumulator. ");
} else if ((childLogicalType instanceof StructuredType) && ListView.class.isAssignableFrom(((StructuredType) childLogicalType).getImplementationClass().get())) {
return new ListViewSpec("agg" + index + "$" + ((RowType) logicalType).getFieldNames().get(i), i, childDataType.getChildren().get(0));
} else if ((childLogicalType instanceof StructuredType) && MapView.class.isAssignableFrom(((StructuredType) childLogicalType).getImplementationClass().get())) {
return new MapViewSpec("agg" + index + "$" + ((RowType) logicalType).getFieldNames().get(i), i, childDataType.getChildren().get(0), false);
}
return null;
}).filter(Objects::nonNull).toArray(DataViewSpec[]::new);
} else {
throw new TableException("For Python AggregateFunction you can only use DataView in " + "Row type.");
}
} else {
return new DataViewSpec[0];
}
}
Aggregations