use of org.apache.flink.table.expressions.UnresolvedReferenceExpression 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.expressions.UnresolvedReferenceExpression 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;
}
use of org.apache.flink.table.expressions.UnresolvedReferenceExpression in project flink by apache.
the class AliasOperationUtils method createAliasList.
/**
* Creates a list of valid alias expressions. Resulting expression might still contain {@link
* UnresolvedReferenceExpression}.
*
* @param aliases aliases to validate
* @param child relational operation on top of which to apply the aliases
* @return validated list of aliases
*/
static List<Expression> createAliasList(List<Expression> aliases, QueryOperation child) {
ResolvedSchema childSchema = child.getResolvedSchema();
if (aliases.size() > childSchema.getColumnCount()) {
throw new ValidationException("Aliasing more fields than we actually have.");
}
List<ValueLiteralExpression> fieldAliases = aliases.stream().map(f -> f.accept(aliasLiteralValidator)).collect(Collectors.toList());
List<String> childNames = childSchema.getColumnNames();
return IntStream.range(0, childNames.size()).mapToObj(idx -> {
UnresolvedReferenceExpression oldField = unresolvedRef(childNames.get(idx));
if (idx < fieldAliases.size()) {
ValueLiteralExpression alias = fieldAliases.get(idx);
return unresolvedCall(BuiltInFunctionDefinitions.AS, oldField, alias);
} else {
return oldField;
}
}).collect(Collectors.toList());
}
use of org.apache.flink.table.expressions.UnresolvedReferenceExpression in project flink by apache.
the class DeclarativeExpressionResolver method defaultMethod.
@Override
protected ResolvedExpression defaultMethod(Expression expression) {
if (expression instanceof UnresolvedReferenceExpression) {
UnresolvedReferenceExpression expr = (UnresolvedReferenceExpression) expression;
String name = expr.getName();
int localIndex = ArrayUtils.indexOf(function.aggBufferAttributes(), expr);
if (localIndex == -1) {
// case, the input is aggregate buffers which sent by local aggregate.
if (isMerge) {
return toMergeInputExpr(name, ArrayUtils.indexOf(function.mergeOperands(), expr));
} else {
return toAccInputExpr(name, ArrayUtils.indexOf(function.operands(), expr));
}
} else {
return toAggBufferExpr(name, localIndex);
}
} else if (expression instanceof UnresolvedCallExpression) {
UnresolvedCallExpression unresolvedCall = (UnresolvedCallExpression) expression;
return resolver.resolve(ApiExpressionUtils.unresolvedCall(unresolvedCall.getFunctionDefinition(), unresolvedCall.getChildren().stream().map(c -> c.accept(DeclarativeExpressionResolver.this)).collect(Collectors.toList())));
} else if (expression instanceof ResolvedExpression) {
return (ResolvedExpression) expression;
} else {
return resolver.resolve(expression);
}
}
Aggregations