Search in sources :

Example 1 with SessionWithGapOnTimeWithAlias

use of org.apache.flink.table.api.SessionWithGapOnTimeWithAlias 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);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) TumbleWithSizeOnTimeWithAlias(org.apache.flink.table.api.TumbleWithSizeOnTimeWithAlias) SlideWithSizeAndSlideOnTimeWithAlias(org.apache.flink.table.api.SlideWithSizeAndSlideOnTimeWithAlias) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) SessionWithGapOnTimeWithAlias(org.apache.flink.table.api.SessionWithGapOnTimeWithAlias)

Aggregations

SessionWithGapOnTimeWithAlias (org.apache.flink.table.api.SessionWithGapOnTimeWithAlias)1 SlideWithSizeAndSlideOnTimeWithAlias (org.apache.flink.table.api.SlideWithSizeAndSlideOnTimeWithAlias)1 TableException (org.apache.flink.table.api.TableException)1 TumbleWithSizeOnTimeWithAlias (org.apache.flink.table.api.TumbleWithSizeOnTimeWithAlias)1 ValidationException (org.apache.flink.table.api.ValidationException)1 CallExpression (org.apache.flink.table.expressions.CallExpression)1 Expression (org.apache.flink.table.expressions.Expression)1 FieldReferenceExpression (org.apache.flink.table.expressions.FieldReferenceExpression)1 ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)1 UnresolvedReferenceExpression (org.apache.flink.table.expressions.UnresolvedReferenceExpression)1 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)1