Java Code Examples for org.apache.calcite.sql.SqlOperatorBinding#getOperandLiteralValue()

The following examples show how to use org.apache.calcite.sql.SqlOperatorBinding#getOperandLiteralValue() . 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: SqlDotOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
  final RelDataType recordType = opBinding.getOperandType(0);
  switch (recordType.getSqlTypeName()) {
  case ROW:
    final String fieldName =
        opBinding.getOperandLiteralValue(1, String.class);
    final RelDataType type = opBinding.getOperandType(0)
        .getField(fieldName, false, false)
        .getType();
    if (recordType.isNullable()) {
      return typeFactory.createTypeWithNullability(type, true);
    } else {
      return type;
    }
  default:
    throw new AssertionError();
  }
}
 
Example 2
Source File: SqlDotOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
  final RelDataType recordType = opBinding.getOperandType(0);
  switch (recordType.getSqlTypeName()) {
  case ROW:
    final String fieldName =
        opBinding.getOperandLiteralValue(1, String.class);
    final RelDataType type = opBinding.getOperandType(0)
        .getField(fieldName, false, false)
        .getType();
    if (recordType.isNullable()) {
      return typeFactory.createTypeWithNullability(type, true);
    } else {
      return type;
    }
  default:
    throw new AssertionError();
  }
}
 
Example 3
Source File: SqlExtractFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  switch (call.getOperandLiteralValue(0, TimeUnitRange.class)) {
  case YEAR:
    return call.getOperandMonotonicity(1).unstrict();
  default:
    return SqlMonotonicity.NOT_MONOTONIC;
  }
}
 
Example 4
Source File: FlinkReturnTypes.java    From flink with Apache License 2.0 5 votes vote down vote up
private BigDecimal getArg1Literal(SqlOperatorBinding opBinding) {
	try {
		return opBinding.getOperandLiteralValue(1, BigDecimal.class);
	} catch (Throwable e) {
		return null;
	}
}
 
Example 5
Source File: FlinkReturnTypes.java    From flink with Apache License 2.0 5 votes vote down vote up
private BigDecimal getArg1Literal(SqlOperatorBinding opBinding) {
	try {
		return opBinding.getOperandLiteralValue(1, BigDecimal.class);
	} catch (Throwable e) {
		return null;
	}
}
 
Example 6
Source File: SqlExtractFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
  switch (call.getOperandLiteralValue(0, TimeUnitRange.class)) {
  case YEAR:
    return call.getOperandMonotonicity(1).unstrict();
  default:
    return SqlMonotonicity.NOT_MONOTONIC;
  }
}
 
Example 7
Source File: SqlItemOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
  final RelDataType operandType = opBinding.getOperandType(0);
  switch (operandType.getSqlTypeName()) {
  case ARRAY:
    return typeFactory.createTypeWithNullability(
        operandType.getComponentType(), true);
  case MAP:
    return typeFactory.createTypeWithNullability(operandType.getValueType(),
        true);
  case ROW:
    String fieldName = opBinding.getOperandLiteralValue(1, String.class);
    RelDataTypeField field = operandType.getField(fieldName, false, false);
    if (field == null) {
      throw new AssertionError("Cannot infer type of field '"
          + fieldName + "' within ROW type: " + operandType);
    } else {
      return field.getType();
    }
  case ANY:
  case DYNAMIC_STAR:
    return typeFactory.createTypeWithNullability(
        typeFactory.createSqlType(SqlTypeName.ANY), true);
  default:
    throw new AssertionError();
  }
}
 
Example 8
Source File: SqlJsonValueFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns the optional explicit returning type specification. **/
private static Optional<RelDataType> explicitTypeSpec(SqlOperatorBinding opBinding) {
  if (opBinding.getOperandCount() > 2
      && opBinding.isOperandLiteral(2, false)
      && opBinding.getOperandLiteralValue(2, Object.class)
        instanceof SqlJsonValueReturning) {
    return Optional.of(opBinding.getOperandType(3));
  }
  return Optional.empty();
}