Exemple #1
0
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   assert opBinding.getOperandCount() == 1;
   final RelDataType multisetType = opBinding.getOperandType(0);
   RelDataType componentType = multisetType.getComponentType();
   assert componentType != null : "expected a multiset type: " + multisetType;
   final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
   final RelDataType type =
       typeFactory.builder().add(SqlUtil.deriveAliasFromOrdinal(0), componentType).build();
   return typeFactory.createMultisetType(type, -1);
 }
Exemple #2
0
  RelProtoDataType getRelDataType(
      DatabaseMetaData metaData, String catalogName, String schemaName, String tableName)
      throws SQLException {
    final ResultSet resultSet = metaData.getColumns(catalogName, schemaName, tableName, null);

    // Temporary type factory, just for the duration of this method. Allowable
    // because we're creating a proto-type, not a type; before being used, the
    // proto-type will be copied into a real type factory.
    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl();
    final RelDataTypeFactory.FieldInfoBuilder fieldInfo = typeFactory.builder();
    while (resultSet.next()) {
      final String columnName = resultSet.getString(4);
      final int dataType = resultSet.getInt(5);
      final String typeString = resultSet.getString(6);
      final int size = resultSet.getInt(7);
      final int scale = resultSet.getInt(9);
      RelDataType sqlType = sqlType(typeFactory, dataType, size, scale, typeString);
      boolean nullable = resultSet.getBoolean(11);
      fieldInfo.add(columnName, sqlType).nullable(nullable);
    }
    resultSet.close();
    return RelDataTypeImpl.proto(fieldInfo.build());
  }