Java Code Examples for org.apache.calcite.sql.SqlOperandCountRange

The following examples show how to use org.apache.calcite.sql.SqlOperandCountRange. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Bats   Source File: OperandTypes.java    License: Apache License 2.0 6 votes vote down vote up
public static SqlOperandTypeChecker variadic(
    final SqlOperandCountRange range) {
  return new SqlOperandTypeChecker() {
    public boolean checkOperandTypes(
        SqlCallBinding callBinding,
        boolean throwOnFailure) {
      return range.isValidCount(callBinding.getOperandCount());
    }

    public SqlOperandCountRange getOperandCountRange() {
      return range;
    }

    public String getAllowedSignatures(SqlOperator op, String opName) {
      return opName + "(...)";
    }

    public boolean isOptional(int i) {
      return false;
    }

    public Consistency getConsistency() {
      return Consistency.NONE;
    }
  };
}
 
Example 2
Source Project: calcite   Source File: OperandTypes.java    License: Apache License 2.0 6 votes vote down vote up
public static SqlOperandTypeChecker variadic(
    final SqlOperandCountRange range) {
  return new SqlOperandTypeChecker() {
    public boolean checkOperandTypes(
        SqlCallBinding callBinding,
        boolean throwOnFailure) {
      return range.isValidCount(callBinding.getOperandCount());
    }

    public SqlOperandCountRange getOperandCountRange() {
      return range;
    }

    public String getAllowedSignatures(SqlOperator op, String opName) {
      return opName + "(...)";
    }

    public boolean isOptional(int i) {
      return false;
    }

    public Consistency getConsistency() {
      return Consistency.NONE;
    }
  };
}
 
Example 3
Source Project: Bats   Source File: SameOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  if (nOperands == -1) {
    return SqlOperandCountRanges.any();
  } else {
    return SqlOperandCountRanges.of(nOperands);
  }
}
 
Example 4
Source Project: Bats   Source File: CompositeOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Package private. Use {@link OperandTypes#and},
 * {@link OperandTypes#or}.
 */
CompositeOperandTypeChecker(
    Composition composition,
    ImmutableList<? extends SqlOperandTypeChecker> allowedRules,
    String allowedSignatures,
    SqlOperandCountRange range) {
  this.allowedRules = Objects.requireNonNull(allowedRules);
  this.composition = Objects.requireNonNull(composition);
  this.allowedSignatures = allowedSignatures;
  this.range = range;
  assert (range != null) == (composition == Composition.REPEAT);
  assert allowedRules.size() + (range == null ? 0 : 1) > 1;
}
 
Example 5
Source Project: Bats   Source File: CompositeOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
private int minMin(List<SqlOperandCountRange> ranges) {
  int min = Integer.MAX_VALUE;
  for (SqlOperandCountRange range : ranges) {
    min = Math.min(min, range.getMax());
  }
  return min;
}
 
Example 6
Source Project: Bats   Source File: CompositeOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
private int maxMax(List<SqlOperandCountRange> ranges) {
  int max = Integer.MIN_VALUE;
  for (SqlOperandCountRange range : ranges) {
    if (range.getMax() < 0) {
      if (composition == Composition.OR) {
        return -1;
      }
    } else {
      max = Math.max(max, range.getMax());
    }
  }
  return max;
}
 
Example 7
Source Project: Bats   Source File: FamilyOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  final int max = families.size();
  int min = max;
  while (min > 0 && optional.test(min - 1)) {
    --min;
  }
  return SqlOperandCountRanges.between(min, max);
}
 
Example 8
Source Project: flink   Source File: NumericExceptFirstOperandChecker.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SqlOperandCountRange getOperandCountRange() {
	if (nOperands == -1) {
		return SqlOperandCountRanges.any();
	} else {
		return SqlOperandCountRanges.of(nOperands);
	}
}
 
Example 9
Source Project: flink   Source File: NumericExceptFirstOperandChecker.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SqlOperandCountRange getOperandCountRange() {
	if (nOperands == -1) {
		return SqlOperandCountRanges.any();
	} else {
		return SqlOperandCountRanges.of(nOperands);
	}
}
 
Example 10
Source Project: calcite   Source File: OperandTypes.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a checker that passes if all of the rules pass for each operand,
 * using a given operand count strategy.
 */
public static SqlOperandTypeChecker repeat(SqlOperandCountRange range,
    SqlSingleOperandTypeChecker... rules) {
  return new CompositeOperandTypeChecker(
      CompositeOperandTypeChecker.Composition.REPEAT,
      ImmutableList.copyOf(rules), null, range);
}
 
Example 11
Source Project: calcite   Source File: SameOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  if (nOperands == -1) {
    return SqlOperandCountRanges.any();
  } else {
    return SqlOperandCountRanges.of(nOperands);
  }
}
 
Example 12
Source Project: calcite   Source File: CompositeOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Package private. Use {@link OperandTypes#and},
 * {@link OperandTypes#or}.
 */
CompositeOperandTypeChecker(
    Composition composition,
    ImmutableList<? extends SqlOperandTypeChecker> allowedRules,
    @Nullable String allowedSignatures,
    @Nullable SqlOperandCountRange range) {
  this.allowedRules = Objects.requireNonNull(allowedRules);
  this.composition = Objects.requireNonNull(composition);
  this.allowedSignatures = allowedSignatures;
  this.range = range;
  assert (range != null) == (composition == Composition.REPEAT);
  assert allowedRules.size() + (range == null ? 0 : 1) > 1;
}
 
Example 13
Source Project: calcite   Source File: CompositeOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
private int minMin(List<SqlOperandCountRange> ranges) {
  int min = Integer.MAX_VALUE;
  for (SqlOperandCountRange range : ranges) {
    min = Math.min(min, range.getMax());
  }
  return min;
}
 
Example 14
Source Project: calcite   Source File: CompositeOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
private int maxMax(List<SqlOperandCountRange> ranges) {
  int max = Integer.MIN_VALUE;
  for (SqlOperandCountRange range : ranges) {
    if (range.getMax() < 0) {
      if (composition == Composition.OR) {
        return -1;
      }
    } else {
      max = Math.max(max, range.getMax());
    }
  }
  return max;
}
 
Example 15
Source Project: calcite   Source File: FamilyOperandTypeChecker.java    License: Apache License 2.0 5 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  final int max = families.size();
  int min = max;
  while (min > 0 && optional.test(min - 1)) {
    --min;
  }
  return SqlOperandCountRanges.between(min, max);
}
 
Example 16
Source Project: Bats   Source File: SqlMultisetMemberOfOperator.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(2);
}
 
Example 17
Source Project: Bats   Source File: SqlJsonDepthFunction.java    License: Apache License 2.0 4 votes vote down vote up
@Override public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(1);
}
 
Example 18
Source Project: Bats   Source File: SqlSubstringFunction.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.between(2, 3);
}
 
Example 19
Source Project: Bats   Source File: SqlDatePartFunction.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(1);
}
 
Example 20
Source Project: Bats   Source File: SqlLikeOperator.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.between(2, 3);
}
 
Example 21
Source Project: Bats   Source File: SqlJsonArrayFunction.java    License: Apache License 2.0 4 votes vote down vote up
@Override public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.from(1);
}
 
Example 22
Source Project: Bats   Source File: SqlCaseOperator.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.any();
}
 
Example 23
Source Project: Bats   Source File: SqlItemOperator.java    License: Apache License 2.0 4 votes vote down vote up
@Override public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(2);
}
 
Example 24
Source Project: Bats   Source File: SqlCastFunction.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(2);
}
 
Example 25
Source Project: Bats   Source File: SqlJsonObjectFunction.java    License: Apache License 2.0 4 votes vote down vote up
@Override public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.from(1);
}
 
Example 26
Source Project: Bats   Source File: SqlJsonPrettyFunction.java    License: Apache License 2.0 4 votes vote down vote up
@Override public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(1);
}
 
Example 27
Source Project: calcite   Source File: AssignableOperandTypeChecker.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(paramTypes.size());
}
 
Example 28
Source Project: Bats   Source File: SqlJsonValueFunction.java    License: Apache License 2.0 4 votes vote down vote up
@Override public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.between(5, 6);
}
 
Example 29
Source Project: Bats   Source File: SqlOverlapsOperator.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.of(2);
}
 
Example 30
Source Project: Bats   Source File: SqlStdOperatorTable.java    License: Apache License 2.0 4 votes vote down vote up
public SqlOperandCountRange getOperandCountRange() {
  return SqlOperandCountRanges.between(1, 2);
}