diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java index 4eaff10..3710e31 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -1604,14 +1604,14 @@ public void testResultSetMetaData() throws SQLException { ResultSet res = stmt.executeQuery( "select c1, c2, c3, c4, c5 as a, c6, c7, c8, c9, c10, c11, c12, " + - "c1*2, sentences(null, null, null) as b, c17, c18, c20, c21, c22, c23 from " + dataTypeTableName + + "c1*2, sentences(null, null, null) as b, c17, c18, c20, c21, c22, c23, null as null_val from " + dataTypeTableName + " limit 1"); ResultSetMetaData meta = res.getMetaData(); ResultSet colRS = con.getMetaData().getColumns(null, null, dataTypeTableName.toLowerCase(), null); - assertEquals(20, meta.getColumnCount()); + assertEquals(21, meta.getColumnCount()); assertTrue(colRS.next()); @@ -1875,6 +1875,14 @@ public void testResultSetMetaData() throws SQLException { assertEquals(15, meta.getPrecision(19)); assertEquals(0, meta.getScale(19)); + assertEquals("c22", colRS.getString("COLUMN_NAME")); + assertEquals(Types.CHAR, colRS.getInt("DATA_TYPE")); + assertEquals("char", colRS.getString("TYPE_NAME").toLowerCase()); + assertEquals(meta.getPrecision(19), colRS.getInt("COLUMN_SIZE")); + assertEquals(meta.getScale(19), colRS.getInt("DECIMAL_DIGITS")); + + assertTrue(colRS.next()); + assertEquals("c23", meta.getColumnName(20)); assertEquals(Types.BINARY, meta.getColumnType(20)); assertEquals("binary", meta.getColumnTypeName(20)); @@ -1882,11 +1890,14 @@ public void testResultSetMetaData() throws SQLException { assertEquals(Integer.MAX_VALUE, meta.getPrecision(20)); assertEquals(0, meta.getScale(20)); - assertEquals("c22", colRS.getString("COLUMN_NAME")); - assertEquals(Types.CHAR, colRS.getInt("DATA_TYPE")); - assertEquals("char", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(19), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(19), colRS.getInt("DECIMAL_DIGITS")); + assertTrue(colRS.next()); + + assertEquals("null_val", meta.getColumnName(21)); + assertEquals(Types.NULL, meta.getColumnType(21)); + assertEquals("void", meta.getColumnTypeName(21)); + assertEquals(4, meta.getColumnDisplaySize(21)); + assertEquals(0, meta.getPrecision(21)); + assertEquals(0, meta.getScale(21)); for (int i = 1; i <= meta.getColumnCount(); i++) { assertFalse(meta.isAutoIncrement(i)); diff --git a/jdbc/src/java/org/apache/hive/jdbc/JdbcColumn.java b/jdbc/src/java/org/apache/hive/jdbc/JdbcColumn.java index 691fd0e..b5b1486 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/JdbcColumn.java +++ b/jdbc/src/java/org/apache/hive/jdbc/JdbcColumn.java @@ -156,6 +156,8 @@ static Type typeStringToHiveType(String type) throws SQLException { return Type.ARRAY_TYPE; } else if ("struct".equalsIgnoreCase(type)) { return Type.STRUCT_TYPE; + } else if ("void".equalsIgnoreCase(type) || "null".equalsIgnoreCase(type)) { + return Type.NULL_TYPE; } throw new SQLException("Unrecognized column type: " + type); } @@ -165,11 +167,7 @@ public static int hiveTypeToSqlType(Type hiveType) throws SQLException { } public static int hiveTypeToSqlType(String type) throws SQLException { - if ("void".equalsIgnoreCase(type) || "null".equalsIgnoreCase(type)) { - return Types.NULL; - } else { - return hiveTypeToSqlType(typeStringToHiveType(type)); - } + return hiveTypeToSqlType(typeStringToHiveType(type)); } static String getColumnTypeName(String type) throws SQLException { @@ -225,6 +223,8 @@ static int columnDisplaySize(Type hiveType, JdbcColumnAttributes columnAttribute // according to hiveTypeToSqlType possible options are: int columnType = hiveTypeToSqlType(hiveType); switch(columnType) { + case Types.NULL: + return 4; // "NULL" case Types.BOOLEAN: return columnPrecision(hiveType, columnAttributes); case Types.CHAR: @@ -266,6 +266,8 @@ static int columnPrecision(Type hiveType, JdbcColumnAttributes columnAttributes) int columnType = hiveTypeToSqlType(hiveType); // according to hiveTypeToSqlType possible options are: switch(columnType) { + case Types.NULL: + return 0; case Types.BOOLEAN: return 1; case Types.CHAR: @@ -320,6 +322,7 @@ static int columnScale(Type hiveType, JdbcColumnAttributes columnAttributes) int columnType = hiveTypeToSqlType(hiveType); // according to hiveTypeToSqlType possible options are: switch(columnType) { + case Types.NULL: case Types.BOOLEAN: case Types.CHAR: case Types.VARCHAR: