@Test public void testGetColumnType() throws SQLException { metadata = new IoTDBResultMetadata(null, null, null); boolean flag = false; try { metadata.getColumnType(1); } catch (Exception e) { flag = true; } assertEquals(flag, true); List<String> columnInfoList = new ArrayList<>(); metadata = new IoTDBResultMetadata(columnInfoList, null, null); flag = false; try { metadata.getColumnType(1); } catch (Exception e) { flag = true; } assertEquals(flag, true); String[] columns = {"timestamp", "root.a.b.boolean", "root.a.b.int32", "root.a.b.int64", "root.a.b.float", "root.a.b.double", "root.a.b.text"}; String[] typesString = {"BOOLEAN", "INT32", "INT64", "FLOAT", "DOUBLE", "TEXT"}; int[] types = {Types.BOOLEAN, Types.INTEGER, Types.BIGINT, Types.FLOAT, Types.DOUBLE, Types.VARCHAR}; metadata = new IoTDBResultMetadata(Arrays.asList(columns), null, Arrays.asList(typesString)); flag = false; try { metadata.getColumnType(columns.length + 1); } catch (Exception e) { flag = true; } assertEquals(flag, true); flag = false; try { metadata.getColumnType(0); } catch (Exception e) { flag = true; } assertEquals(flag, true); assertEquals(metadata.getColumnType(1), Types.TIMESTAMP); for (int i = 1; i <= types.length; i++) { assertEquals(metadata.getColumnType(i + 1), types[i - 1]); } }
@Override public int getColumnType(int column) throws SQLException { if (columnInfoList == null || columnInfoList.size() == 0) { throw new SQLException("No column exists"); } if (column > columnInfoList.size()) { throw new SQLException(String.format("column %d does not exist", column)); } if (column <= 0) { throw new SQLException(String.format("column index should start from 1", column)); } if (column == 1) { return Types.TIMESTAMP; } String columnType = columnTypeList.get(column - 2); switch (columnType.toUpperCase()) { case "BOOLEAN": return Types.BOOLEAN; case "INT32": return Types.INTEGER; case "INT64": return Types.BIGINT; case "FLOAT": return Types.FLOAT; case "DOUBLE": return Types.DOUBLE; case "TEXT": return Types.VARCHAR; default: break; } return 0; }
IoTDBResultMetadata implements ResultSetMetaData { @Override public int getColumnType(int column) throws SQLException { if (columnInfoList == null || columnInfoList.size() == 0) { throw new SQLException("No column exists"); } if (column > columnInfoList.size()) { throw new SQLException(String.format("column %d does not exist", column)); } if (column <= 0) { throw new SQLException(String.format("column index should start from 1", column)); } if (column == 1) { return Types.TIMESTAMP; } String columnType = columnTypeList.get(column - 2); switch (columnType.toUpperCase()) { case "BOOLEAN": return Types.BOOLEAN; case "INT32": return Types.INTEGER; case "INT64": return Types.BIGINT; case "FLOAT": return Types.FLOAT; case "DOUBLE": return Types.DOUBLE; case "TEXT": return Types.VARCHAR; default: break; } return 0; } }
IoTDBResultMetadata implements ResultSetMetaData { @Override public int getColumnType(int column) throws SQLException { if (columnInfoList == null || columnInfoList.size() == 0) { throw new SQLException("No column exists"); } if (column > columnInfoList.size()) { throw new SQLException(String.format("column %d does not exist", column)); } if (column <= 0) { throw new SQLException(String.format("column index should start from 1", column)); } if (column == 1) { return Types.TIMESTAMP; } String columnType = columnTypeList.get(column - 2); switch (columnType.toUpperCase()) { case "BOOLEAN": return Types.BOOLEAN; case "INT32": return Types.INTEGER; case "INT64": return Types.BIGINT; case "FLOAT": return Types.FLOAT; case "DOUBLE": return Types.DOUBLE; case "TEXT": return Types.VARCHAR; default: break; } return 0; } IoTDBResultMetadata(List<String> columnInfoList, String operationType,
      List<String> columnTypeList); }
IoTDBResultMetadata implements ResultSetMetaData { @Override public int getColumnType(int column) throws SQLException { if (columnInfoList == null || columnInfoList.size() == 0) { throw new SQLException("No column exists"); } if (column > columnInfoList.size()) { throw new SQLException(String.format("column %d does not exist", column)); } if (column <= 0) { throw new SQLException(String.format("column index should start from 1", column)); } if (column == 1) { return Types.TIMESTAMP; } String columnType = columnTypeList.get(column - 2); switch (columnType.toUpperCase()) { case "BOOLEAN": return Types.BOOLEAN; case "INT32": return Types.INTEGER; case "INT64": return Types.BIGINT; case "FLOAT": return Types.FLOAT; case "DOUBLE": return Types.DOUBLE; case "TEXT": return Types.VARCHAR; default: break; } return 0; } IoTDBResultMetadata(List<String> columnInfoList, String operationType,
      List<String> columnTypeList); @Override boolean isWrapperFor(Class<?> arg0); @Override T unwrap(Class<T> arg0); @Override String getCatalogName(int arg0); @Override String getColumnClassName(int arg0); @Override int getColumnCount(); @Override int getColumnDisplaySize(int arg0); @Override String getColumnLabel(int column); @Override String getColumnName(int column); @Override int getColumnType(int column); @Override String getColumnTypeName(int arg0); @Override int getPrecision(int arg0); @Override int getScale(int arg0); @Override String getSchemaName(int arg0); @Override String getTableName(int arg0); @Override boolean isAutoIncrement(int arg0); @Override boolean isCaseSensitive(int arg0); @Override boolean isCurrency(int arg0); @Override boolean isDefinitelyWritable(int arg0); @Override int isNullable(int arg0); @Override boolean isReadOnly(int arg0); @Override boolean isSearchable(int arg0); @Override boolean isSigned(int arg0); @Override boolean isWritable(int arg0); }
IoTDBResultMetadata implements ResultSetMetaData { @Override public int getColumnType(int column) throws SQLException { if (columnInfoList == null || columnInfoList.size() == 0) { throw new SQLException("No column exists"); } if (column > columnInfoList.size()) { throw new SQLException(String.format("column %d does not exist", column)); } if (column <= 0) { throw new SQLException(String.format("column index should start from 1", column)); } if (column == 1) { return Types.TIMESTAMP; } String columnType = columnTypeList.get(column - 2); switch (columnType.toUpperCase()) { case "BOOLEAN": return Types.BOOLEAN; case "INT32": return Types.INTEGER; case "INT64": return Types.BIGINT; case "FLOAT": return Types.FLOAT; case "DOUBLE": return Types.DOUBLE; case "TEXT": return Types.VARCHAR; default: break; } return 0; } IoTDBResultMetadata(List<String> columnInfoList, String operationType,
      List<String> columnTypeList); @Override boolean isWrapperFor(Class<?> arg0); @Override T unwrap(Class<T> arg0); @Override String getCatalogName(int arg0); @Override String getColumnClassName(int arg0); @Override int getColumnCount(); @Override int getColumnDisplaySize(int arg0); @Override String getColumnLabel(int column); @Override String getColumnName(int column); @Override int getColumnType(int column); @Override String getColumnTypeName(int arg0); @Override int getPrecision(int arg0); @Override int getScale(int arg0); @Override String getSchemaName(int arg0); @Override String getTableName(int arg0); @Override boolean isAutoIncrement(int arg0); @Override boolean isCaseSensitive(int arg0); @Override boolean isCurrency(int arg0); @Override boolean isDefinitelyWritable(int arg0); @Override int isNullable(int arg0); @Override boolean isReadOnly(int arg0); @Override boolean isSearchable(int arg0); @Override boolean isSigned(int arg0); @Override boolean isWritable(int arg0);  }