Java Code Examples for org.apache.calcite.sql.validate.SqlMonotonicity#CONSTANT

The following examples show how to use org.apache.calcite.sql.validate.SqlMonotonicity#CONSTANT . 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: SqlBinaryOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  if (getName().equals("/")) {
    final SqlMonotonicity mono0 = call.getOperandMonotonicity(0);
    final SqlMonotonicity mono1 = call.getOperandMonotonicity(1);
    if (mono1 == SqlMonotonicity.CONSTANT) {
      if (call.isOperandLiteral(1, false)) {
        switch (call.getOperandLiteralValue(1, BigDecimal.class).signum()) {
        case -1:

          // mono / -ve constant --> reverse mono, unstrict
          return mono0.reverse().unstrict();
        case 0:

          // mono / zero --> constant (infinity!)
          return SqlMonotonicity.CONSTANT;
        default:

          // mono / +ve constant * mono1 --> mono, unstrict
          return mono0.unstrict();
        }
      }
    }
  }

  return super.getMonotonicity(call);
}
 
Example 2
Source File: SqlBinaryOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  if (getName().equals("/")) {
    final SqlMonotonicity mono0 = call.getOperandMonotonicity(0);
    final SqlMonotonicity mono1 = call.getOperandMonotonicity(1);
    if (mono1 == SqlMonotonicity.CONSTANT) {
      if (call.isOperandLiteral(1, false)) {
        switch (call.getOperandLiteralValue(1, BigDecimal.class).signum()) {
        case -1:

          // mono / -ve constant --> reverse mono, unstrict
          return mono0.reverse().unstrict();
        case 0:

          // mono / zero --> constant (infinity!)
          return SqlMonotonicity.CONSTANT;
        default:

          // mono / +ve constant * mono1 --> mono, unstrict
          return mono0.unstrict();
        }
      }
    }
  }

  return super.getMonotonicity(call);
}
 
Example 3
Source File: SqlSubstringFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  // SUBSTRING(x FROM 0 FOR constant) has same monotonicity as x
  if (call.getOperandCount() == 3) {
    final SqlMonotonicity mono0 = call.getOperandMonotonicity(0);
    if ((mono0 != SqlMonotonicity.NOT_MONOTONIC)
        && call.getOperandMonotonicity(1) == SqlMonotonicity.CONSTANT
        && call.getOperandLiteralValue(1, BigDecimal.class)
            .equals(BigDecimal.ZERO)
        && call.getOperandMonotonicity(2) == SqlMonotonicity.CONSTANT) {
      return mono0.unstrict();
    }
  }
  return super.getMonotonicity(call);
}
 
Example 4
Source File: SqlSubstringFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  // SUBSTRING(x FROM 0 FOR constant) has same monotonicity as x
  if (call.getOperandCount() == 3) {
    final SqlMonotonicity mono0 = call.getOperandMonotonicity(0);
    if ((mono0 != SqlMonotonicity.NOT_MONOTONIC)
        && call.getOperandMonotonicity(1) == SqlMonotonicity.CONSTANT
        && call.getOperandLiteralValue(1, BigDecimal.class)
            .equals(BigDecimal.ZERO)
        && call.getOperandMonotonicity(2) == SqlMonotonicity.CONSTANT) {
      return mono0.unstrict();
    }
  }
  return super.getMonotonicity(call);
}
 
Example 5
Source File: SqlDynamicParam.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
  return SqlMonotonicity.CONSTANT;
}
 
Example 6
Source File: SqlBaseContextVariable.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  return SqlMonotonicity.CONSTANT;
}
 
Example 7
Source File: SqlLiteral.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
  return SqlMonotonicity.CONSTANT;
}
 
Example 8
Source File: SqlDataTypeSpec.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
  return SqlMonotonicity.CONSTANT;
}
 
Example 9
Source File: SqlDynamicParam.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
  return SqlMonotonicity.CONSTANT;
}
 
Example 10
Source File: SqlBaseContextVariable.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  return SqlMonotonicity.CONSTANT;
}
 
Example 11
Source File: SqlLiteral.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
  return SqlMonotonicity.CONSTANT;
}
 
Example 12
Source File: SqlDataTypeSpec.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
  return SqlMonotonicity.CONSTANT;
}