Java Code Examples for org.apache.calcite.sql.SqlKind#MINUS

The following examples show how to use org.apache.calcite.sql.SqlKind#MINUS . 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 File: TypeCoercionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Coerces operands in binary arithmetic expressions to NUMERIC types.
 *
 * <p>For binary arithmetic operators like [+, -, *, /, %]:
 * If the operand is VARCHAR,
 * coerce it to data type of the other operand if its data type is NUMERIC;
 * If the other operand is DECIMAL,
 * coerce the STRING operand to max precision/scale DECIMAL.
 */
public boolean binaryArithmeticCoercion(SqlCallBinding binding) {
  // Assume the operator has NUMERIC family operand type checker.
  SqlOperator operator = binding.getOperator();
  SqlKind kind = operator.getKind();
  boolean coerced = false;
  // Binary operator
  if (binding.getOperandCount() == 2) {
    final RelDataType type1 = binding.getOperandType(0);
    final RelDataType type2 = binding.getOperandType(1);
    // Special case for datetime + interval or datetime - interval
    if (kind == SqlKind.PLUS || kind == SqlKind.MINUS) {
      if (SqlTypeUtil.isInterval(type1) || SqlTypeUtil.isInterval(type2)) {
        return false;
      }
    }
    // Binary arithmetic operator like: + - * / %
    if (kind.belongsTo(SqlKind.BINARY_ARITHMETIC)) {
      coerced = binaryArithmeticWithStrings(binding, type1, type2);
    }
  }
  return coerced;
}
 
Example 2
Source File: SqlDatetimeSubtractionOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlDatetimeSubtractionOperator() {
  super(
      "-",
      SqlKind.MINUS,
      40,
      true,
      ReturnTypes.ARG2_NULLABLE,
      InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR);
}
 
Example 3
Source File: SqlDatetimeSubtractionOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlDatetimeSubtractionOperator() {
  super(
      "-",
      SqlKind.MINUS,
      40,
      true,
      ReturnTypes.ARG2_NULLABLE,
      InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR);
}
 
Example 4
Source File: DruidTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
private boolean isSupportedPostAggOperation(SqlKind kind) {
  return kind == SqlKind.PLUS
          || kind == SqlKind.MINUS
          || kind == SqlKind.DIVIDE
          || kind == SqlKind.TIMES;
}