Java Code Examples for org.apache.calcite.sql.type.SqlTypeName#ROW

The following examples show how to use org.apache.calcite.sql.type.SqlTypeName#ROW . 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 boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final SqlNode left = callBinding.operand(0);
  final SqlNode right = callBinding.operand(1);
  final RelDataType type =
      callBinding.getValidator().deriveType(callBinding.getScope(), left);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return false;
  } else if (type.getSqlIdentifier().isStar()) {
    return false;
  }
  final RelDataType operandType = callBinding.getOperandType(0);
  final SqlSingleOperandTypeChecker checker = getChecker(operandType);
  return checker.checkSingleOperandType(callBinding, right, 0,
      throwOnFailure);
}
 
Example 2
Source File: SqlTumbleTableFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  // There should only be three operands, and number of operands are checked before
  // this call.
  final SqlNode operand0 = callBinding.operand(0);
  final SqlValidator validator = callBinding.getValidator();
  final RelDataType type = validator.getValidatedNodeType(operand0);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final SqlNode operand1 = callBinding.operand(1);
  if (operand1.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand1).getOperandList());
  final RelDataType type2 = validator.getValidatedNodeType(callBinding.operand(2));
  if (!SqlTypeUtil.isInterval(type2)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  return true;
}
 
Example 3
Source File: SqlHopTableFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final SqlNode operand0 = callBinding.operand(0);
  final SqlValidator validator = callBinding.getValidator();
  final RelDataType type = validator.getValidatedNodeType(operand0);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final SqlNode operand1 = callBinding.operand(1);
  if (operand1.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand1).getOperandList());
  final RelDataType type2 = validator.getValidatedNodeType(callBinding.operand(2));
  if (!SqlTypeUtil.isInterval(type2)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final RelDataType type3 = validator.getValidatedNodeType(callBinding.operand(3));
  if (!SqlTypeUtil.isInterval(type3)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  return true;
}
 
Example 4
Source File: SqlSessionTableFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final SqlNode operand0 = callBinding.operand(0);
  final SqlValidator validator = callBinding.getValidator();
  final RelDataType type = validator.getValidatedNodeType(operand0);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  final SqlNode operand1 = callBinding.operand(1);
  if (operand1.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand1).getOperandList());
  final SqlNode operand2 = callBinding.operand(2);
  if (operand2.getKind() != SqlKind.DESCRIPTOR) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  validateColumnNames(validator, type.getFieldNames(), ((SqlCall) operand2).getOperandList());
  final RelDataType type3 = validator.getValidatedNodeType(callBinding.operand(3));
  if (!SqlTypeUtil.isInterval(type3)) {
    return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
  }
  return true;
}
 
Example 5
Source File: SqlDotOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  final SqlNode left = callBinding.operand(0);
  final SqlNode right = callBinding.operand(1);
  final RelDataType type =
      callBinding.getValidator().deriveType(callBinding.getScope(), left);
  if (type.getSqlTypeName() != SqlTypeName.ROW) {
    return false;
  } else if (type.getSqlIdentifier().isStar()) {
    return false;
  }
  final RelDataType operandType = callBinding.getOperandType(0);
  final SqlSingleOperandTypeChecker checker = getChecker(operandType);
  // Actually operand0 always comes from parsing the SqlIdentifier, so there
  // is no need to make implicit type coercion.
  return checker.checkSingleOperandType(callBinding, right, 0,
      throwOnFailure);
}
 
Example 6
Source File: SamzaSqlValidator.java    From samza with Apache License 2.0 5 votes vote down vote up
private boolean compareFieldTypes(RelDataType outputFieldType, SqlFieldSchema sqlFieldSchema,
    RelDataType selectQueryFieldType, RelSchemaProvider outputRelSchemaProvider) {

  SqlTypeName outputSqlType = outputFieldType.getSqlTypeName();
  SqlTypeName projectSqlType = selectQueryFieldType.getSqlTypeName();

  if (projectSqlType == SqlTypeName.ANY || outputSqlType == SqlTypeName.ANY) {
    return true;
  } else if (outputSqlType != SqlTypeName.ROW && outputSqlType == projectSqlType) {
    return true;
  }

  switch (outputSqlType) {
    case CHAR:
      return projectSqlType == SqlTypeName.VARCHAR;
    case VARCHAR:
      return projectSqlType == SqlTypeName.CHAR;
    case BIGINT:
      return projectSqlType == SqlTypeName.INTEGER;
    case INTEGER:
      return projectSqlType == SqlTypeName.BIGINT;
    case FLOAT:
      return projectSqlType == SqlTypeName.DOUBLE;
    case DOUBLE:
      return projectSqlType == SqlTypeName.FLOAT;
    case ROW:
      try {
        validateOutputRecords(sqlFieldSchema.getRowSchema(), (RelRecordType) outputFieldType,
            (RelRecordType) selectQueryFieldType, outputRelSchemaProvider);
      } catch (SamzaSqlValidatorException e) {
        LOG.error("A field in select query does not match with the output schema.", e);
        return false;
      }
      return true;
    default:
      return false;
  }
}
 
Example 7
Source File: DynamicRecordTypeImpl.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override public SqlTypeName getSqlTypeName() {
  return SqlTypeName.ROW;
}
 
Example 8
Source File: RelRecordType.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override public SqlTypeName getSqlTypeName() {
  return SqlTypeName.ROW;
}
 
Example 9
Source File: DynamicRecordTypeImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public SqlTypeName getSqlTypeName() {
  return SqlTypeName.ROW;
}
 
Example 10
Source File: RelRecordType.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public SqlTypeName getSqlTypeName() {
  return SqlTypeName.ROW;
}