use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class OperationTreeBuilder method map.
public QueryOperation map(Expression mapFunction, QueryOperation child) {
Expression resolvedMapFunction = mapFunction.accept(lookupResolver);
if (!isFunctionOfKind(resolvedMapFunction, FunctionKind.SCALAR)) {
throw new ValidationException("Only a scalar function can be used in the map operator.");
}
Expression expandedFields = unresolvedCall(BuiltInFunctionDefinitions.FLATTEN, resolvedMapFunction);
return project(Collections.singletonList(expandedFields), child, false);
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class SortOperationFactory method createLimitWithFetch.
/**
* Creates a valid {@link SortQueryOperation} with fetch (possibly merged into a preceding
* {@link SortQueryOperation}).
*
* @param fetch fetch to limit
* @param child relational expression on top of which to apply the sort operation
* @param postResolverFactory factory for creating resolved expressions
* @return valid sort operation with applied offset
*/
QueryOperation createLimitWithFetch(int fetch, QueryOperation child, PostResolverFactory postResolverFactory) {
SortQueryOperation previousSort = validateAndGetChildSort(child, postResolverFactory);
if (fetch < 0) {
throw new ValidationException("Fetch should be greater or equal 0");
}
int offset = Math.max(previousSort.getOffset(), 0);
return new SortQueryOperation(previousSort.getOrder(), previousSort.getChild(), offset, fetch);
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class AggregateOperationFactory method validateAndCreateSessionWindow.
private ResolvedGroupWindow validateAndCreateSessionWindow(SessionWithGapOnTimeWithAlias window, String windowName, FieldReferenceExpression timeField) {
ValueLiteralExpression windowGap = getAsValueLiteral(window.getGap(), "A session window expects a gap value literal.");
final LogicalType windowGapType = windowGap.getOutputDataType().getLogicalType();
if (!windowGapType.is(INTERVAL_DAY_TIME)) {
throw new ValidationException("A session window expects a gap literal of a day-time interval type.");
}
return ResolvedGroupWindow.sessionWindow(windowName, timeField, windowGap);
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class AggregateOperationFactory method createResolvedWindow.
/**
* Converts an API class to a resolved window for planning with expressions already resolved. It
* performs following validations:
*
* <ul>
* <li>The alias is represented with an unresolved reference
* <li>The time attribute is a single field reference of a {@link
* TimeIndicatorTypeInfo}(stream), {@link SqlTimeTypeInfo}(batch), or {@link
* BasicTypeInfo#LONG_TYPE_INFO}(batch) type
* <li>The size & slide are value literals of either {@link BasicTypeInfo#LONG_TYPE_INFO}, or
* {@link TimeIntervalTypeInfo} type
* <li>The size & slide are of the same type
* <li>The gap is a value literal of a {@link TimeIntervalTypeInfo} type
* </ul>
*
* @param window window to resolve
* @param resolver resolver to resolve potential unresolved field references
* @return window with expressions resolved
*/
ResolvedGroupWindow createResolvedWindow(GroupWindow window, ExpressionResolver resolver) {
Expression alias = window.getAlias();
if (!(alias instanceof UnresolvedReferenceExpression)) {
throw new ValidationException("Only unresolved reference supported for alias of a group window.");
}
final String windowName = ((UnresolvedReferenceExpression) alias).getName();
FieldReferenceExpression timeField = getValidatedTimeAttribute(window, resolver);
if (window instanceof TumbleWithSizeOnTimeWithAlias) {
return validateAndCreateTumbleWindow((TumbleWithSizeOnTimeWithAlias) window, windowName, timeField);
} else if (window instanceof SlideWithSizeAndSlideOnTimeWithAlias) {
return validateAndCreateSlideWindow((SlideWithSizeAndSlideOnTimeWithAlias) window, windowName, timeField);
} else if (window instanceof SessionWithGapOnTimeWithAlias) {
return validateAndCreateSessionWindow((SessionWithGapOnTimeWithAlias) window, windowName, timeField);
} else {
throw new TableException("Unknown window type: " + window);
}
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class FieldInfoUtils method extractFieldInfoFromAtomicType.
private static List<FieldInfo> extractFieldInfoFromAtomicType(TypeInformation<?> atomicType, Expression[] exprs) {
List<FieldInfo> fields = new ArrayList<>(exprs.length);
boolean alreadyReferenced = false;
for (int i = 0; i < exprs.length; i++) {
Expression expr = exprs[i];
if (expr instanceof UnresolvedReferenceExpression) {
if (alreadyReferenced) {
throw new ValidationException("Too many fields referenced from an atomic type.");
}
alreadyReferenced = true;
String name = ((UnresolvedReferenceExpression) expr).getName();
fields.add(new FieldInfo(name, i, fromLegacyInfoToDataType(atomicType)));
} else if (isRowTimeExpression(expr)) {
UnresolvedReferenceExpression reference = getChildAsReference(expr);
fields.add(createTimeAttributeField(reference, TimestampKind.ROWTIME, null));
} else if (isProcTimeExpression(expr)) {
UnresolvedReferenceExpression reference = getChildAsReference(expr);
fields.add(createTimeAttributeField(reference, TimestampKind.PROCTIME, null));
} else {
throw new ValidationException("Field reference expression expected.");
}
}
return fields;
}
Aggregations