Search in sources :

Example 1 with ArgumentCount

use of org.apache.flink.table.types.inference.ArgumentCount in project flink by apache.

the class OrInputTypeStrategy method commonMax.

/**
 * Returns the common maximum argument count or null if undefined.
 */
@Nullable
private static Integer commonMax(List<ArgumentCount> counts) {
    // max=5, max=3, max=0           -> max=5
    // max=5, max=3, max=0, max=null -> max=null
    int commonMax = Integer.MIN_VALUE;
    for (ArgumentCount count : counts) {
        final Optional<Integer> max = count.getMaxCount();
        if (!max.isPresent()) {
            return null;
        }
        commonMax = Math.max(commonMax, max.get());
    }
    if (commonMax == Integer.MIN_VALUE) {
        return null;
    }
    return commonMax;
}
Also used : ArgumentCount(org.apache.flink.table.types.inference.ArgumentCount) ConstantArgumentCount(org.apache.flink.table.types.inference.ConstantArgumentCount) Nullable(javax.annotation.Nullable)

Example 2 with ArgumentCount

use of org.apache.flink.table.types.inference.ArgumentCount in project flink by apache.

the class OrInputTypeStrategy method commonMin.

// --------------------------------------------------------------------------------------------
/**
 * Returns the common minimum argument count or null if undefined.
 */
@Nullable
private static Integer commonMin(List<ArgumentCount> counts) {
    // min=5, min=3, min=0           -> min=0
    // min=5, min=3, min=0, min=null -> min=null
    int commonMin = Integer.MAX_VALUE;
    for (ArgumentCount count : counts) {
        final Optional<Integer> min = count.getMinCount();
        if (!min.isPresent()) {
            return null;
        }
        commonMin = Math.min(commonMin, min.get());
    }
    if (commonMin == Integer.MAX_VALUE) {
        return null;
    }
    return commonMin;
}
Also used : ArgumentCount(org.apache.flink.table.types.inference.ArgumentCount) ConstantArgumentCount(org.apache.flink.table.types.inference.ConstantArgumentCount) Nullable(javax.annotation.Nullable)

Example 3 with ArgumentCount

use of org.apache.flink.table.types.inference.ArgumentCount in project flink by apache.

the class OrInputTypeStrategy method getArgumentCount.

@Override
public ArgumentCount getArgumentCount() {
    final List<ArgumentCount> counts = new AbstractList<ArgumentCount>() {

        public ArgumentCount get(int index) {
            return inputStrategies.get(index).getArgumentCount();
        }

        public int size() {
            return inputStrategies.size();
        }
    };
    final Integer min = commonMin(counts);
    final Integer max = commonMax(counts);
    final ArgumentCount compositeCount = new ArgumentCount() {

        @Override
        public boolean isValidCount(int count) {
            for (ArgumentCount c : counts) {
                if (c.isValidCount(count)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public Optional<Integer> getMinCount() {
            return Optional.ofNullable(min);
        }

        @Override
        public Optional<Integer> getMaxCount() {
            return Optional.ofNullable(max);
        }
    };
    // use constant count if applicable
    if (min == null || max == null) {
        // no boundaries
        return compositeCount;
    }
    for (int i = min; i <= max; i++) {
        if (!compositeCount.isValidCount(i)) {
            // not the full range
            return compositeCount;
        }
    }
    if (min.equals(max)) {
        return ConstantArgumentCount.of(min);
    }
    return ConstantArgumentCount.between(min, max);
}
Also used : ArgumentCount(org.apache.flink.table.types.inference.ArgumentCount) ConstantArgumentCount(org.apache.flink.table.types.inference.ConstantArgumentCount) AbstractList(java.util.AbstractList)

Aggregations

ArgumentCount (org.apache.flink.table.types.inference.ArgumentCount)3 ConstantArgumentCount (org.apache.flink.table.types.inference.ConstantArgumentCount)3 Nullable (javax.annotation.Nullable)2 AbstractList (java.util.AbstractList)1