use of org.apache.flink.table.runtime.dataview.DataViewSpec 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