Index: jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java =================================================================== --- jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java (revision 978817) +++ jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java (working copy) @@ -18,6 +18,10 @@ package org.apache.hadoop.hive.jdbc; +import junit.framework.TestCase; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.conf.HiveConf; + import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; @@ -27,12 +31,12 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; -import junit.framework.TestCase; - -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hive.conf.HiveConf; - /** * TestJdbcDriver. * @@ -40,7 +44,11 @@ public class TestJdbcDriver extends TestCase { private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver"; private static String tableName = "testHiveDriverTable"; + private static String tableComment = "Simple table"; + private static String viewName = "testHiveDriverView"; + private static String viewComment = "Simple view"; private static String partitionedTableName = "testHiveDriverPartitionedTable"; + private static String partitionedTableComment = "Partitioned table"; private final HiveConf conf; private final Path dataFilePath; private Connection con; @@ -75,11 +83,12 @@ try { stmt.executeQuery("drop table " + tableName); } catch (Exception ex) { + fail(ex.toString()); } // create table ResultSet res = stmt.executeQuery("create table " + tableName - + " (key int, value string)"); + + " (key int comment 'the key', value string) comment '"+tableComment+"'"); assertFalse(res.next()); // load data @@ -93,10 +102,12 @@ try { stmt.executeQuery("drop table " + partitionedTableName); } catch (Exception ex) { + fail(ex.toString()); } res = stmt.executeQuery("create table " + partitionedTableName - + " (key int, value string) partitioned by (dt STRING)"); + + " (key int, value string) comment '"+partitionedTableComment + +"' partitioned by (dt STRING)"); assertFalse(res.next()); // load data @@ -105,6 +116,17 @@ + " PARTITION (dt='20090619')"); assertFalse(res.next()); + // drop view. ignore error. + try { + stmt.executeQuery("drop view " + viewName); + } catch (Exception ex) { + fail(ex.toString()); + } + + // create view + res = stmt.executeQuery("create view " + viewName + " comment '"+viewComment + +"' as select * from "+ tableName); + assertFalse(res.next()); } protected void tearDown() throws Exception { @@ -177,9 +199,9 @@ while (moreRow) { try { i++; - res.getInt(1); - res.getString(1); - res.getString(2); + assertEquals(res.getInt(1), res.getInt("key")); + assertEquals(res.getString(1), res.getString("key")); + assertEquals(res.getString(2), res.getString("value")); assertFalse("Last result value was not null", res.wasNull()); assertNull("No warnings should be found on ResultSet", res .getWarnings()); @@ -287,6 +309,167 @@ + " not found in SHOW TABLES result set", testTableExists); } + public void testMetaDataGetTables() throws SQLException { + Map tests = new HashMap(); + tests.put("test%", new Object[]{"testhivedriverpartitionedtable" + , "testhivedrivertable" + , "testhivedriverview"}); + tests.put("%drivertable", new Object[]{"testhivedrivertable"}); + tests.put("testhivedrivertable", new Object[]{"testhivedrivertable"}); + tests.put("test_ivedri_ertable", new Object[]{"testhivedrivertable"}); + tests.put("%", new Object[]{"testhivedriverpartitionedtable" + , "testhivedrivertable" + , "testhivedriverview"}); + tests.put("", new Object[]{}); + tests.put(null, new Object[]{"testhivedriverpartitionedtable" + , "testhivedrivertable" + , "testhivedriverview"}); + + for (String checkPattern: tests.keySet()) { + ResultSet rs = (ResultSet)con.getMetaData().getTables("default", null, checkPattern, null); + int cnt = 0; + while (rs.next()) { + String resultTableName = rs.getString("TABLE_NAME"); + assertEquals("Get by index different from get by name", rs.getString(3), resultTableName); + assertEquals(resultTableName, tests.get(checkPattern)[cnt]); + String resultTableComment = rs.getString("REMARKS"); + assertTrue(resultTableComment.length()>0); + String tableType = rs.getString("TABLE_TYPE"); + if (resultTableName.endsWith("view")) { + assertEquals(tableType, "VIEW"); + } + cnt++; + } + rs.close(); + assertEquals(tests.get(checkPattern).length, cnt); + } + + // only ask for the views. + ResultSet rs = (ResultSet)con.getMetaData().getTables("default", null, null + , new String[]{"VIEW"}); + int cnt=0; + while (rs.next()) { + cnt++; + } + rs.close(); + assertEquals(1, cnt); + } + + public void testMetaDataGetCatalogs() throws SQLException { + ResultSet rs = (ResultSet)con.getMetaData().getCatalogs(); + int cnt = 0; + while (rs.next()) { + String catalogname = rs.getString("TABLE_CAT"); + assertEquals("Get by index different from get by name", rs.getString(1), catalogname); + switch(cnt) { + case 0: + assertEquals("default", catalogname); + break; + default: + fail("More then one catalog found."); + break; + } + cnt++; + } + rs.close(); + assertEquals("Incorrect schema count", 1, cnt); + } + + public void testMetaDataGetTableTypes() throws SQLException { + ResultSet rs = (ResultSet)con.getMetaData().getTableTypes(); + Set tabletypes = new HashSet(); + tabletypes.add("TABLE"); + tabletypes.add("EXTERNAL TABLE"); + tabletypes.add("VIEW"); + + int cnt = 0; + while (rs.next()) { + String tabletype = rs.getString("TABLE_TYPE"); + assertEquals("Get by index different from get by name", rs.getString(1), tabletype); + tabletypes.remove(tabletype); + cnt++; + } + rs.close(); + assertEquals("Incorrect tabletype count.", 0, tabletypes.size()); + assertTrue("Found less tabletypes then we test for.", cnt >= tabletypes.size()); + } + + public void testMetaDataGetColumns() throws SQLException { + Map tests = new HashMap(); + tests.put(new String[]{"testhivedrivertable", null}, 2); + tests.put(new String[]{null, null}, 6); + tests.put(new String[]{"test%", null}, 6); + tests.put(new String[]{"%drivertable", null}, 2); + tests.put(new String[]{"%drivertable%", "key"}, 1); + tests.put(new String[]{"%drivertable%", "ke_"}, 1); + tests.put(new String[]{"%drivertable%", "ke%"}, 1); + + for (String[] checkPattern: tests.keySet()) { + ResultSet rs = (ResultSet)con.getMetaData().getColumns(null, null + , checkPattern[0], checkPattern[1]); + int cnt = 0; + while (rs.next()) { + String columnname = rs.getString("COLUMN_NAME"); + int ordinalPos = rs.getInt("ORDINAL_POSITION"); + switch(cnt) { + case 0: + assertEquals("key", columnname); + assertEquals(ordinalPos, 1); + break; + case 1: + assertEquals("value", columnname); + assertEquals(ordinalPos, 2); + break; + default: + break; + } + cnt++; + } + rs.close(); + assertEquals(tests.get(checkPattern).intValue(), cnt); + } + } + + public void testConversionsBaseResultSet() throws SQLException { + ResultSet rs = new HiveMetaDataResultSet(Arrays.asList("key") + , Arrays.asList("long") + , Arrays.asList(1234, "1234", "abc")) { + private int cnt=1; + public boolean next() throws SQLException { + if (cnt= 5 ? -1 : 0; int expectedScale = i >= 5 ? -1 : 0; - assertEquals("Unexpected precision", expectedPrecision, meta - .getPrecision(i)); + assertEquals("Unexpected precision", expectedPrecision, meta.getPrecision(i)); assertEquals("Unexpected scale", expectedScale, meta.getScale(i)); } } Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveCallableStatement.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveCallableStatement.java (revision 978817) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveCallableStatement.java (working copy) @@ -1378,7 +1378,7 @@ public ResultSet executeQuery() throws SQLException { // TODO Auto-generated method stub - return new HiveResultSet(null); + return new HiveQueryResultSet(null); } /* Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java (revision 0) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java (revision 0) @@ -0,0 +1,935 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.jdbc; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.List; +import java.util.Map; + +/** + * Data independed base class which implements the common part of + * all hive resultsets. + */ +public abstract class HiveBaseResultSet implements ResultSet{ + protected SQLWarning warningChain = null; + protected boolean wasNull = false; + protected List row; + protected List columnNames; + protected List columnTypes; + + public boolean absolute(int row) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void afterLast() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void beforeFirst() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void cancelRowUpdates() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void deleteRow() throws SQLException { + throw new SQLException("Method not supported"); + } + + public int findColumn(String columnName) throws SQLException { + int columnIndex = columnNames.indexOf(columnName); + if (columnIndex==-1) { + throw new SQLException(); + } else { + return ++columnIndex; + } + } + + public boolean first() throws SQLException { + throw new SQLException("Method not supported"); + } + + public Array getArray(int i) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Array getArray(String colName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public InputStream getAsciiStream(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public InputStream getAsciiStream(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public BigDecimal getBigDecimal(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + throw new SQLException("Method not supported"); + } + + public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { + throw new SQLException("Method not supported"); + } + + public InputStream getBinaryStream(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public InputStream getBinaryStream(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Blob getBlob(int i) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Blob getBlob(String colName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean getBoolean(int columnIndex) throws SQLException { + Object obj = getObject(columnIndex); + if (Number.class.isInstance(obj)) { + return ((Number) obj).intValue() != 0; + } + throw new SQLException("Cannot convert column " + columnIndex + " to boolean"); + } + + public boolean getBoolean(String columnName) throws SQLException { + return getBoolean(findColumn(columnName)); + } + + public byte getByte(int columnIndex) throws SQLException { + Object obj = getObject(columnIndex); + if (Number.class.isInstance(obj)) { + return ((Number) obj).byteValue(); + } + throw new SQLException("Cannot convert column " + columnIndex + " to byte"); + } + + public byte getByte(String columnName) throws SQLException { + return getByte(findColumn(columnName)); + } + + public byte[] getBytes(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public byte[] getBytes(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Reader getCharacterStream(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Reader getCharacterStream(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Clob getClob(int i) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Clob getClob(String colName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public int getConcurrency() throws SQLException { + return ResultSet.CONCUR_READ_ONLY; + } + + public String getCursorName() throws SQLException { + throw new SQLException("Method not supported"); + } + + public Date getDate(int columnIndex) throws SQLException { + Object obj = getObject(columnIndex); + if (obj == null) { + return null; + } + + try { + return Date.valueOf((String) obj); + } catch (Exception e) { + throw new SQLException("Cannot convert column " + columnIndex + + " to date: " + e.toString()); + } + } + + public Date getDate(String columnName) throws SQLException { + return getDate(findColumn(columnName)); + } + + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Date getDate(String columnName, Calendar cal) throws SQLException { + throw new SQLException("Method not supported"); + } + + public double getDouble(int columnIndex) throws SQLException { + try { + Object obj = getObject(columnIndex); + if (Number.class.isInstance(obj)) { + return ((Number) obj).doubleValue(); + } else if (obj == null) { + return 0; + } else if (String.class.isInstance(obj)) { + return Double.valueOf((String)obj); + } + throw new Exception("Illegal conversion"); + } catch (Exception e) { + throw new SQLException("Cannot convert column " + columnIndex + + " to double: " + e.toString()); + } + } + + public double getDouble(String columnName) throws SQLException { + return getDouble(findColumn(columnName)); + } + + public int getFetchDirection() throws SQLException { + return ResultSet.FETCH_FORWARD; + } + + public int getFetchSize() throws SQLException { + throw new SQLException("Method not supported"); + } + + public float getFloat(int columnIndex) throws SQLException { + try { + Object obj = getObject(columnIndex); + if (Number.class.isInstance(obj)) { + return ((Number) obj).floatValue(); + } else if (obj == null) { + return 0; + } else if (String.class.isInstance(obj)) { + return Float.valueOf((String)obj); + } + throw new Exception("Illegal conversion"); + } catch (Exception e) { + throw new SQLException("Cannot convert column " + columnIndex + + " to float: " + e.toString()); + } + } + + public float getFloat(String columnName) throws SQLException { + return getFloat(findColumn(columnName)); + } + + public int getHoldability() throws SQLException { + throw new SQLException("Method not supported"); + } + + public int getInt(int columnIndex) throws SQLException { + try { + Object obj = getObject(columnIndex); + if (Number.class.isInstance(obj)) { + return ((Number) obj).intValue(); + } else if (obj == null) { + return 0; + } else if (String.class.isInstance(obj)) { + return Integer.valueOf((String)obj); + } + throw new Exception("Illegal conversion"); + } catch (Exception e) { + throw new SQLException("Cannot convert column " + columnIndex + " to integer" + e.toString()); + } + } + + public int getInt(String columnName) throws SQLException { + return getInt(findColumn(columnName)); + } + + public long getLong(int columnIndex) throws SQLException { + try { + Object obj = getObject(columnIndex); + if (Number.class.isInstance(obj)) { + return ((Number) obj).longValue(); + } else if (obj == null) { + return 0; + } else if (String.class.isInstance(obj)) { + return Long.valueOf((String)obj); + } + throw new Exception("Illegal conversion"); + } catch (Exception e) { + throw new SQLException("Cannot convert column " + columnIndex + " to long: " + e.toString()); + } + } + + public long getLong(String columnName) throws SQLException { + return getLong(findColumn(columnName)); + } + + public ResultSetMetaData getMetaData() throws SQLException { + return new HiveResultSetMetaData(columnNames, columnTypes); + } + + public Reader getNCharacterStream(int arg0) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Reader getNCharacterStream(String arg0) throws SQLException { + throw new SQLException("Method not supported"); + } + + public NClob getNClob(int arg0) throws SQLException { + throw new SQLException("Method not supported"); + } + + public NClob getNClob(String columnLabel) throws SQLException { + throw new SQLException("Method not supported"); + } + + public String getNString(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public String getNString(String columnLabel) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Object getObject(int columnIndex) throws SQLException { + if (row == null) { + throw new SQLException("No row found."); + } + + if (columnIndex > row.size()) { + throw new SQLException("Invalid columnIndex: " + columnIndex); + } + + try { + wasNull = false; + if (row.get(columnIndex - 1) == null) { + wasNull = true; + } + + return row.get(columnIndex - 1); + } catch (Exception e) { + throw new SQLException(e.toString()); + } + } + + public Object getObject(String columnName) throws SQLException { + return getObject(findColumn(columnName)); + } + + public Object getObject(int i, Map> map) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Object getObject(String colName, Map> map) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Ref getRef(int i) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Ref getRef(String colName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public int getRow() throws SQLException { + throw new SQLException("Method not supported"); + } + + public RowId getRowId(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public RowId getRowId(String columnLabel) throws SQLException { + throw new SQLException("Method not supported"); + } + + public SQLXML getSQLXML(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public SQLXML getSQLXML(String columnLabel) throws SQLException { + throw new SQLException("Method not supported"); + } + + public short getShort(int columnIndex) throws SQLException { + try { + Object obj = getObject(columnIndex); + if (Number.class.isInstance(obj)) { + return ((Number) obj).shortValue(); + } else if (obj == null) { + return 0; + } else if (String.class.isInstance(obj)) { + return Short.valueOf((String)obj); + } + throw new Exception("Illegal conversion"); + } catch (Exception e) { + throw new SQLException("Cannot convert column " + columnIndex + + " to short: " + e.toString()); + } + } + + public short getShort(String columnName) throws SQLException { + return getShort(findColumn(columnName)); + } + + public Statement getStatement() throws SQLException { + throw new SQLException("Method not supported"); + } + + /** + * @param columnIndex - the first column is 1, the second is 2, ... + * @see java.sql.ResultSet#getString(int) + */ + + public String getString(int columnIndex) throws SQLException { + // Column index starts from 1, not 0. + Object obj = getObject(columnIndex); + if (obj == null) { + return null; + } + + return obj.toString(); + } + + public String getString(String columnName) throws SQLException { + return getString(findColumn(columnName)); + } + + public Time getTime(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Time getTime(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Time getTime(String columnName, Calendar cal) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Timestamp getTimestamp(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Timestamp getTimestamp(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException("Method not supported"); + } + + public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { + throw new SQLException("Method not supported"); + } + + public int getType() throws SQLException { + return ResultSet.TYPE_FORWARD_ONLY; + } + + public URL getURL(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public URL getURL(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public InputStream getUnicodeStream(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void insertRow() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean isAfterLast() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean isBeforeFirst() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean isClosed() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean isFirst() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean isLast() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean last() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void moveToCurrentRow() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void moveToInsertRow() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean previous() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void refreshRow() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean relative(int rows) throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean rowDeleted() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean rowInserted() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean rowUpdated() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void setFetchDirection(int direction) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void setFetchSize(int rows) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateArray(int columnIndex, Array x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateArray(String columnName, Array x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateAsciiStream(int columnIndex, InputStream x, int length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateAsciiStream(String columnName, InputStream x, int length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateAsciiStream(int columnIndex, InputStream x, long length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateAsciiStream(String columnLabel, InputStream x, long length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBinaryStream(int columnIndex, InputStream x, int length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBinaryStream(String columnName, InputStream x, int length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBinaryStream(int columnIndex, InputStream x, long length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBinaryStream(String columnLabel, InputStream x, long length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBlob(int columnIndex, Blob x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBlob(String columnName, Blob x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBlob(int columnIndex, InputStream inputStream, long length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBlob(String columnLabel, InputStream inputStream, + long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBoolean(String columnName, boolean x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateByte(int columnIndex, byte x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateByte(String columnName, byte x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateBytes(String columnName, byte[] x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateCharacterStream(int columnIndex, Reader x, int length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateCharacterStream(String columnName, Reader reader, int length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateCharacterStream(int columnIndex, Reader x, long length) + throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateCharacterStream(String columnLabel, Reader reader, + long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateClob(int columnIndex, Clob x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateClob(String columnName, Clob x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateClob(int columnIndex, Reader reader) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateClob(String columnLabel, Reader reader) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateDate(int columnIndex, Date x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateDate(String columnName, Date x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateDouble(int columnIndex, double x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateDouble(String columnName, double x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateFloat(int columnIndex, float x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateFloat(String columnName, float x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateInt(int columnIndex, int x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateInt(String columnName, int x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateLong(int columnIndex, long x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateLong(String columnName, long x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNCharacterStream(String columnLabel, Reader reader, + long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNClob(int columnIndex, NClob clob) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNClob(String columnLabel, NClob clob) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNClob(String columnLabel, Reader reader) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNString(int columnIndex, String string) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNString(String columnLabel, String string) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNull(int columnIndex) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateNull(String columnName) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateObject(int columnIndex, Object x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateObject(String columnName, Object x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateObject(int columnIndex, Object x, int scale) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateObject(String columnName, Object x, int scale) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateRef(int columnIndex, Ref x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateRef(String columnName, Ref x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateRow() throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateRowId(int columnIndex, RowId x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateRowId(String columnLabel, RowId x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateShort(int columnIndex, short x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateShort(String columnName, short x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateString(int columnIndex, String x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateString(String columnName, String x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateTime(int columnIndex, Time x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateTime(String columnName, Time x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public void updateTimestamp(String columnName, Timestamp x) throws SQLException { + throw new SQLException("Method not supported"); + } + + public SQLWarning getWarnings() throws SQLException { + return warningChain; + } + + public void clearWarnings() throws SQLException { + warningChain = null; + } + + public void close() throws SQLException { + throw new SQLException("Method not supported"); + } + + public boolean wasNull() throws SQLException { + return wasNull; + } + + public boolean isWrapperFor(Class iface) throws SQLException { + throw new SQLException("Method not supported"); + } + + public T unwrap(Class iface) throws SQLException { + throw new SQLException("Method not supported"); + } +} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java (revision 978817) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java (working copy) @@ -48,9 +48,9 @@ * */ public class HivePreparedStatement implements PreparedStatement { - String sql; - JdbcSessionState session; - HiveInterface client; + private String sql; + private JdbcSessionState session; + private HiveInterface client; /** * @@ -107,7 +107,7 @@ } catch (Exception ex) { throw new SQLException(ex.toString()); } - return new HiveResultSet(client); + return new HiveQueryResultSet(client); } /* @@ -263,7 +263,8 @@ * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long) */ - public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { + public void setBlob(int parameterIndex, InputStream inputStream, long length) + throws SQLException { // TODO Auto-generated method stub throw new SQLException("Method not supported"); } Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSet.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSet.java (revision 978817) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSet.java (working copy) @@ -1,2331 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.NClob; -import java.sql.Ref; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Statement; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hive.metastore.api.FieldSchema; -import org.apache.hadoop.hive.metastore.api.Schema; -import org.apache.hadoop.hive.serde.Constants; -import org.apache.hadoop.hive.serde2.dynamic_type.DynamicSerDe; -import org.apache.hadoop.hive.service.HiveInterface; -import org.apache.hadoop.io.BytesWritable; - -/** - * HiveResultSet. - * - */ -public class HiveResultSet implements java.sql.ResultSet { - HiveInterface client; - ArrayList row; - DynamicSerDe ds; - List columnNames; - List columnTypes; - - SQLWarning warningChain = null; - boolean wasNull = false; - int maxRows = 0; - int rowsFetched = 0; - - /** - * - */ - @SuppressWarnings("unchecked") - public HiveResultSet(HiveInterface client, int maxRows) throws SQLException { - this.client = client; - row = new ArrayList(); - this.maxRows = maxRows; - initDynamicSerde(); - } - - @SuppressWarnings("unchecked") - public HiveResultSet(HiveInterface client) throws SQLException { - this(client, 0); - } - - /** - * Instantiate the dynamic serde used to deserialize the result row. - */ - public void initDynamicSerde() throws SQLException { - try { - Schema fullSchema = client.getThriftSchema(); - List schema = fullSchema.getFieldSchemas(); - columnNames = new ArrayList(); - columnTypes = new ArrayList(); - - String serDDL; - - if ((schema != null) && (!schema.isEmpty())) { - serDDL = new String("struct result { "); - for (int pos = 0; pos < schema.size(); pos++) { - if (pos != 0) { - serDDL = serDDL.concat(","); - } - columnTypes.add(schema.get(pos).getType()); - columnNames.add(schema.get(pos).getName()); - serDDL = serDDL.concat(schema.get(pos).getType()); - serDDL = serDDL.concat(" "); - serDDL = serDDL.concat(schema.get(pos).getName()); - } - serDDL = serDDL.concat("}"); - } else { - serDDL = new String("struct result { string empty }"); - } - - ds = new DynamicSerDe(); - Properties dsp = new Properties(); - dsp.setProperty(Constants.SERIALIZATION_FORMAT, - org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol.class - .getName()); - dsp.setProperty( - org.apache.hadoop.hive.metastore.api.Constants.META_TABLE_NAME, - "result"); - dsp.setProperty(Constants.SERIALIZATION_DDL, serDDL); - dsp.setProperty(Constants.SERIALIZATION_LIB, ds.getClass().toString()); - dsp.setProperty(Constants.FIELD_DELIM, "9"); - ds.initialize(new Configuration(), dsp); - } catch (Exception ex) { - ex.printStackTrace(); - throw new SQLException("Could not create ResultSet: " + ex.getMessage()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#absolute(int) - */ - - public boolean absolute(int row) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#afterLast() - */ - - public void afterLast() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#beforeFirst() - */ - - public void beforeFirst() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#cancelRowUpdates() - */ - - public void cancelRowUpdates() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#clearWarnings() - */ - - public void clearWarnings() throws SQLException { - warningChain = null; - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#close() - */ - - public void close() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#deleteRow() - */ - - public void deleteRow() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#findColumn(java.lang.String) - */ - - public int findColumn(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#first() - */ - - public boolean first() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getArray(int) - */ - - public Array getArray(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getArray(java.lang.String) - */ - - public Array getArray(String colName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getAsciiStream(int) - */ - - public InputStream getAsciiStream(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getAsciiStream(java.lang.String) - */ - - public InputStream getAsciiStream(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBigDecimal(int) - */ - - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBigDecimal(java.lang.String) - */ - - public BigDecimal getBigDecimal(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBigDecimal(int, int) - */ - - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBigDecimal(java.lang.String, int) - */ - - public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBinaryStream(int) - */ - - public InputStream getBinaryStream(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBinaryStream(java.lang.String) - */ - - public InputStream getBinaryStream(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBlob(int) - */ - - public Blob getBlob(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBlob(java.lang.String) - */ - - public Blob getBlob(String colName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBoolean(int) - */ - - public boolean getBoolean(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).intValue() != 0; - } - throw new SQLException("Cannot convert column " + columnIndex - + " to boolean"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBoolean(java.lang.String) - */ - - public boolean getBoolean(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getByte(int) - */ - - public byte getByte(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).byteValue(); - } - throw new SQLException("Cannot convert column " + columnIndex + " to byte"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getByte(java.lang.String) - */ - - public byte getByte(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBytes(int) - */ - - public byte[] getBytes(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBytes(java.lang.String) - */ - - public byte[] getBytes(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getCharacterStream(int) - */ - - public Reader getCharacterStream(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getCharacterStream(java.lang.String) - */ - - public Reader getCharacterStream(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getClob(int) - */ - - public Clob getClob(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getClob(java.lang.String) - */ - - public Clob getClob(String colName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getConcurrency() - */ - - public int getConcurrency() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getCursorName() - */ - - public String getCursorName() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getDate(int) - */ - - public Date getDate(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (obj == null) { - return null; - } - - try { - return Date.valueOf((String) obj); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to date: " + e.toString()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getDate(java.lang.String) - */ - - public Date getDate(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getDate(int, java.util.Calendar) - */ - - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getDate(java.lang.String, java.util.Calendar) - */ - - public Date getDate(String columnName, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getDouble(int) - */ - - public double getDouble(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).doubleValue(); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to double: " + e.toString()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getDouble(java.lang.String) - */ - - public double getDouble(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getFetchDirection() - */ - - public int getFetchDirection() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getFetchSize() - */ - - public int getFetchSize() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getFloat(int) - */ - - public float getFloat(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).floatValue(); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to float: " + e.toString()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getFloat(java.lang.String) - */ - - public float getFloat(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getHoldability() - */ - - public int getHoldability() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getInt(int) - */ - - public int getInt(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).intValue(); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to integer" + e.toString()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getInt(java.lang.String) - */ - - public int getInt(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getLong(int) - */ - - public long getLong(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).longValue(); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to long: " + e.toString()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getLong(java.lang.String) - */ - - public long getLong(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getMetaData() - */ - - public ResultSetMetaData getMetaData() throws SQLException { - return new HiveResultSetMetaData(columnNames, columnTypes); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getNCharacterStream(int) - */ - - public Reader getNCharacterStream(int arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getNCharacterStream(java.lang.String) - */ - - public Reader getNCharacterStream(String arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getNClob(int) - */ - - public NClob getNClob(int arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getNClob(java.lang.String) - */ - - public NClob getNClob(String columnLabel) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getNString(int) - */ - - public String getNString(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getNString(java.lang.String) - */ - - public String getNString(String columnLabel) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getObject(int) - */ - - public Object getObject(int columnIndex) throws SQLException { - if (row == null) { - throw new SQLException("No row found."); - } - - if (columnIndex > row.size()) { - throw new SQLException("Invalid columnIndex: " + columnIndex); - } - - try { - wasNull = false; - if (row.get(columnIndex - 1) == null) { - wasNull = true; - } - - return row.get(columnIndex - 1); - } catch (Exception e) { - throw new SQLException(e.toString()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getObject(java.lang.String) - */ - - public Object getObject(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getObject(int, java.util.Map) - */ - - public Object getObject(int i, Map> map) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getObject(java.lang.String, java.util.Map) - */ - - public Object getObject(String colName, Map> map) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getRef(int) - */ - - public Ref getRef(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getRef(java.lang.String) - */ - - public Ref getRef(String colName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getRow() - */ - - public int getRow() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getRowId(int) - */ - - public RowId getRowId(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getRowId(java.lang.String) - */ - - public RowId getRowId(String columnLabel) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getSQLXML(int) - */ - - public SQLXML getSQLXML(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getSQLXML(java.lang.String) - */ - - public SQLXML getSQLXML(String columnLabel) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getShort(int) - */ - - public short getShort(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).shortValue(); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to short: " + e.toString()); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getShort(java.lang.String) - */ - - public short getShort(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getStatement() - */ - - public Statement getStatement() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /** - * @param columnIndex - * - the first column is 1, the second is 2, ... - * @see java.sql.ResultSet#getString(int) - */ - - public String getString(int columnIndex) throws SQLException { - // Column index starts from 1, not 0. - Object obj = getObject(columnIndex); - if (obj == null) { - return null; - } - - return obj.toString(); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getString(java.lang.String) - */ - - public String getString(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTime(int) - */ - - public Time getTime(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTime(java.lang.String) - */ - - public Time getTime(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTime(int, java.util.Calendar) - */ - - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTime(java.lang.String, java.util.Calendar) - */ - - public Time getTime(String columnName, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTimestamp(int) - */ - - public Timestamp getTimestamp(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTimestamp(java.lang.String) - */ - - public Timestamp getTimestamp(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTimestamp(int, java.util.Calendar) - */ - - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getTimestamp(java.lang.String, java.util.Calendar) - */ - - public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getType() - */ - - public int getType() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getURL(int) - */ - - public URL getURL(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getURL(java.lang.String) - */ - - public URL getURL(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getUnicodeStream(int) - */ - - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getUnicodeStream(java.lang.String) - */ - - public InputStream getUnicodeStream(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getWarnings() - */ - - public SQLWarning getWarnings() throws SQLException { - return warningChain; - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#insertRow() - */ - - public void insertRow() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#isAfterLast() - */ - - public boolean isAfterLast() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#isBeforeFirst() - */ - - public boolean isBeforeFirst() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#isClosed() - */ - - public boolean isClosed() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#isFirst() - */ - - public boolean isFirst() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#isLast() - */ - - public boolean isLast() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#last() - */ - - public boolean last() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#moveToCurrentRow() - */ - - public void moveToCurrentRow() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#moveToInsertRow() - */ - - public void moveToInsertRow() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /** - * Moves the cursor down one row from its current position. - * - * @see java.sql.ResultSet#next() - * @throws SQLException - * if a database access error occurs. - */ - - public boolean next() throws SQLException { - if (maxRows > 0 && rowsFetched >= maxRows) { - return false; - } - - String rowStr = ""; - try { - rowStr = (String) client.fetchOne(); - rowsFetched++; - if (!rowStr.equals("")) { - Object o = ds.deserialize(new BytesWritable(rowStr.getBytes())); - row = (ArrayList) o; - } - } catch (Exception ex) { - ex.printStackTrace(); - throw new SQLException("Error retrieving next row"); - } - // NOTE: fetchOne dosn't throw new SQLException("Method not supported"). - return !rowStr.equals(""); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#previous() - */ - - public boolean previous() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#refreshRow() - */ - - public void refreshRow() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#relative(int) - */ - - public boolean relative(int rows) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#rowDeleted() - */ - - public boolean rowDeleted() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#rowInserted() - */ - - public boolean rowInserted() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#rowUpdated() - */ - - public boolean rowUpdated() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#setFetchDirection(int) - */ - - public void setFetchDirection(int direction) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#setFetchSize(int) - */ - - public void setFetchSize(int rows) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateArray(int, java.sql.Array) - */ - - public void updateArray(int columnIndex, Array x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateArray(java.lang.String, java.sql.Array) - */ - - public void updateArray(String columnName, Array x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateAsciiStream(int, java.io.InputStream) - */ - - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateAsciiStream(java.lang.String, - * java.io.InputStream) - */ - - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateAsciiStream(int, java.io.InputStream, int) - */ - - public void updateAsciiStream(int columnIndex, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateAsciiStream(java.lang.String, - * java.io.InputStream, int) - */ - - public void updateAsciiStream(String columnName, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateAsciiStream(int, java.io.InputStream, long) - */ - - public void updateAsciiStream(int columnIndex, InputStream x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateAsciiStream(java.lang.String, - * java.io.InputStream, long) - */ - - public void updateAsciiStream(String columnLabel, InputStream x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBigDecimal(int, java.math.BigDecimal) - */ - - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBigDecimal(java.lang.String, - * java.math.BigDecimal) - */ - - public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBinaryStream(int, java.io.InputStream) - */ - - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBinaryStream(java.lang.String, - * java.io.InputStream) - */ - - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBinaryStream(int, java.io.InputStream, int) - */ - - public void updateBinaryStream(int columnIndex, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBinaryStream(java.lang.String, - * java.io.InputStream, int) - */ - - public void updateBinaryStream(String columnName, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBinaryStream(int, java.io.InputStream, long) - */ - - public void updateBinaryStream(int columnIndex, InputStream x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBinaryStream(java.lang.String, - * java.io.InputStream, long) - */ - - public void updateBinaryStream(String columnLabel, InputStream x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBlob(int, java.sql.Blob) - */ - - public void updateBlob(int columnIndex, Blob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBlob(java.lang.String, java.sql.Blob) - */ - - public void updateBlob(String columnName, Blob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBlob(int, java.io.InputStream) - */ - - public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBlob(java.lang.String, java.io.InputStream) - */ - - public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBlob(int, java.io.InputStream, long) - */ - - public void updateBlob(int columnIndex, InputStream inputStream, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBlob(java.lang.String, java.io.InputStream, - * long) - */ - - public void updateBlob(String columnLabel, InputStream inputStream, - long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBoolean(int, boolean) - */ - - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBoolean(java.lang.String, boolean) - */ - - public void updateBoolean(String columnName, boolean x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateByte(int, byte) - */ - - public void updateByte(int columnIndex, byte x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateByte(java.lang.String, byte) - */ - - public void updateByte(String columnName, byte x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBytes(int, byte[]) - */ - - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateBytes(java.lang.String, byte[]) - */ - - public void updateBytes(String columnName, byte[] x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateCharacterStream(int, java.io.Reader) - */ - - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateCharacterStream(java.lang.String, - * java.io.Reader) - */ - - public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateCharacterStream(int, java.io.Reader, int) - */ - - public void updateCharacterStream(int columnIndex, Reader x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateCharacterStream(java.lang.String, - * java.io.Reader, int) - */ - - public void updateCharacterStream(String columnName, Reader reader, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateCharacterStream(int, java.io.Reader, long) - */ - - public void updateCharacterStream(int columnIndex, Reader x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateCharacterStream(java.lang.String, - * java.io.Reader, long) - */ - - public void updateCharacterStream(String columnLabel, Reader reader, - long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateClob(int, java.sql.Clob) - */ - - public void updateClob(int columnIndex, Clob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateClob(java.lang.String, java.sql.Clob) - */ - - public void updateClob(String columnName, Clob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateClob(int, java.io.Reader) - */ - - public void updateClob(int columnIndex, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateClob(java.lang.String, java.io.Reader) - */ - - public void updateClob(String columnLabel, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateClob(int, java.io.Reader, long) - */ - - public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateClob(java.lang.String, java.io.Reader, long) - */ - - public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateDate(int, java.sql.Date) - */ - - public void updateDate(int columnIndex, Date x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateDate(java.lang.String, java.sql.Date) - */ - - public void updateDate(String columnName, Date x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateDouble(int, double) - */ - - public void updateDouble(int columnIndex, double x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateDouble(java.lang.String, double) - */ - - public void updateDouble(String columnName, double x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateFloat(int, float) - */ - - public void updateFloat(int columnIndex, float x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateFloat(java.lang.String, float) - */ - - public void updateFloat(String columnName, float x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateInt(int, int) - */ - - public void updateInt(int columnIndex, int x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateInt(java.lang.String, int) - */ - - public void updateInt(String columnName, int x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateLong(int, long) - */ - - public void updateLong(int columnIndex, long x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateLong(java.lang.String, long) - */ - - public void updateLong(String columnName, long x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNCharacterStream(int, java.io.Reader) - */ - - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNCharacterStream(java.lang.String, - * java.io.Reader) - */ - - public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNCharacterStream(int, java.io.Reader, long) - */ - - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNCharacterStream(java.lang.String, - * java.io.Reader, long) - */ - - public void updateNCharacterStream(String columnLabel, Reader reader, - long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNClob(int, java.sql.NClob) - */ - - public void updateNClob(int columnIndex, NClob clob) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNClob(java.lang.String, java.sql.NClob) - */ - - public void updateNClob(String columnLabel, NClob clob) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNClob(int, java.io.Reader) - */ - - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNClob(java.lang.String, java.io.Reader) - */ - - public void updateNClob(String columnLabel, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNClob(int, java.io.Reader, long) - */ - - public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNClob(java.lang.String, java.io.Reader, long) - */ - - public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNString(int, java.lang.String) - */ - - public void updateNString(int columnIndex, String string) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNString(java.lang.String, java.lang.String) - */ - - public void updateNString(String columnLabel, String string) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNull(int) - */ - - public void updateNull(int columnIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateNull(java.lang.String) - */ - - public void updateNull(String columnName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateObject(int, java.lang.Object) - */ - - public void updateObject(int columnIndex, Object x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object) - */ - - public void updateObject(String columnName, Object x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateObject(int, java.lang.Object, int) - */ - - public void updateObject(int columnIndex, Object x, int scale) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object, - * int) - */ - - public void updateObject(String columnName, Object x, int scale) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateRef(int, java.sql.Ref) - */ - - public void updateRef(int columnIndex, Ref x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateRef(java.lang.String, java.sql.Ref) - */ - - public void updateRef(String columnName, Ref x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateRow() - */ - - public void updateRow() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateRowId(int, java.sql.RowId) - */ - - public void updateRowId(int columnIndex, RowId x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateRowId(java.lang.String, java.sql.RowId) - */ - - public void updateRowId(String columnLabel, RowId x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateSQLXML(int, java.sql.SQLXML) - */ - - public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateSQLXML(java.lang.String, java.sql.SQLXML) - */ - - public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateShort(int, short) - */ - - public void updateShort(int columnIndex, short x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateShort(java.lang.String, short) - */ - - public void updateShort(String columnName, short x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateString(int, java.lang.String) - */ - - public void updateString(int columnIndex, String x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateString(java.lang.String, java.lang.String) - */ - - public void updateString(String columnName, String x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateTime(int, java.sql.Time) - */ - - public void updateTime(int columnIndex, Time x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateTime(java.lang.String, java.sql.Time) - */ - - public void updateTime(String columnName, Time x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateTimestamp(int, java.sql.Timestamp) - */ - - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#updateTimestamp(java.lang.String, - * java.sql.Timestamp) - */ - - public void updateTimestamp(String columnName, Timestamp x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#wasNull() - */ - - public boolean wasNull() throws SQLException { - return wasNull; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - - public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#unwrap(java.lang.Class) - */ - - public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java (revision 978817) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java (working copy) @@ -30,8 +30,8 @@ * */ public class HiveResultSetMetaData implements java.sql.ResultSetMetaData { - List columnNames; - List columnTypes; + private List columnNames; + private List columnTypes; public HiveResultSetMetaData(List columnNames, List columnTypes) { @@ -39,46 +39,19 @@ this.columnTypes = columnTypes; } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getCatalogName(int) - */ - public String getCatalogName(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getColumnClassName(int) - */ - public String getColumnClassName(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getColumnCount() - */ - public int getColumnCount() throws SQLException { return columnNames.size(); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getColumnDisplaySize(int) - */ - public int getColumnDisplaySize(int column) throws SQLException { - // taking a stab at appropriate values switch (getColumnType(column)) { case Types.VARCHAR: @@ -96,33 +69,14 @@ } } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getColumnLabel(int) - */ - public String getColumnLabel(int column) throws SQLException { - // TODO Auto-generated method stub return columnNames.get(column - 1); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getColumnName(int) - */ - public String getColumnName(int column) throws SQLException { return columnNames.get(column - 1); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getColumnType(int) - */ - public int getColumnType(int column) throws SQLException { if (columnTypes == null) { throw new SQLException( @@ -137,29 +91,34 @@ String type = columnTypes.get(column - 1); // we need to convert the thrift type to the SQL type - // TODO: this would be better handled in an enum - if ("string".equals(type)) { + return hiveTypeToSqlType(type); + } + + /** + * Convert hive types to sql types. + * @param type + * @return Integer java.sql.Types values + * @throws SQLException + */ + public static Integer hiveTypeToSqlType(String type) throws SQLException { + if ("string".equalsIgnoreCase(type)) { return Types.VARCHAR; - } else if ("bool".equals(type)) { + } else if ("bool".equalsIgnoreCase(type) || "boolean".equalsIgnoreCase(type)) { return Types.BOOLEAN; - } else if ("double".equals(type)) { + } else if ("float".equalsIgnoreCase(type)) { + return Types.FLOAT; + } else if ("double".equalsIgnoreCase(type)) { return Types.DOUBLE; - } else if ("byte".equals(type)) { + } else if ("byte".equalsIgnoreCase(type) || "tinyint".equalsIgnoreCase(type)) { return Types.TINYINT; - } else if ("i32".equals(type)) { + } else if ("i32".equalsIgnoreCase(type) || "int".equalsIgnoreCase(type)) { return Types.INTEGER; - } else if ("i64".equals(type)) { + } else if ("i64".equalsIgnoreCase(type) || "bigint".equalsIgnoreCase(type)) { return Types.BIGINT; } - - throw new SQLException("Inrecognized column type: " + type); + throw new SQLException("Unrecognized column type: " + type); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getColumnTypeName(int) - */ public String getColumnTypeName(int column) throws SQLException { if (columnTypes == null) { @@ -174,29 +133,23 @@ // we need to convert the thrift type to the SQL type name // TODO: this would be better handled in an enum String type = columnTypes.get(column - 1); - if ("string".equals(type)) { + if ("string".equalsIgnoreCase(type)) { return Constants.STRING_TYPE_NAME; - } else if ("double".equals(type)) { + } else if ("double".equalsIgnoreCase(type)) { return Constants.DOUBLE_TYPE_NAME; - } else if ("bool".equals(type)) { + } else if ("bool".equalsIgnoreCase(type)) { return Constants.BOOLEAN_TYPE_NAME; - } else if ("byte".equals(type)) { + } else if ("byte".equalsIgnoreCase(type)) { return Constants.TINYINT_TYPE_NAME; - } else if ("i32".equals(type)) { + } else if ("i32".equalsIgnoreCase(type)) { return Constants.INT_TYPE_NAME; - } else if ("i64".equals(type)) { + } else if ("i64".equalsIgnoreCase(type)) { return Constants.BIGINT_TYPE_NAME; } throw new SQLException("Inrecognized column type: " + type); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getPrecision(int) - */ - public int getPrecision(int column) throws SQLException { if (Types.DOUBLE == getColumnType(column)) { return -1; // Do we have a precision limit? @@ -205,12 +158,6 @@ return 0; } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getScale(int) - */ - public int getScale(int column) throws SQLException { if (Types.DOUBLE == getColumnType(column)) { return -1; // Do we have a scale limit? @@ -219,146 +166,58 @@ return 0; } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getSchemaName(int) - */ - public String getSchemaName(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#getTableName(int) - */ - public String getTableName(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isAutoIncrement(int) - */ - public boolean isAutoIncrement(int column) throws SQLException { // Hive doesn't have an auto-increment concept return false; } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isCaseSensitive(int) - */ - public boolean isCaseSensitive(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isCurrency(int) - */ - public boolean isCurrency(int column) throws SQLException { // Hive doesn't support a currency type return false; } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isDefinitelyWritable(int) - */ - public boolean isDefinitelyWritable(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isNullable(int) - */ - public int isNullable(int column) throws SQLException { // Hive doesn't have the concept of not-null return ResultSetMetaData.columnNullable; } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isReadOnly(int) - */ - public boolean isReadOnly(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isSearchable(int) - */ - public boolean isSearchable(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isSigned(int) - */ - public boolean isSigned(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.ResultSetMetaData#isWritable(int) - */ - public boolean isWritable(int column) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#unwrap(java.lang.Class) - */ - public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveMetaDataResultSet.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveMetaDataResultSet.java (revision 0) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveMetaDataResultSet.java (revision 0) @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.jdbc; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public abstract class HiveMetaDataResultSet extends HiveBaseResultSet { + protected final List data; + + @SuppressWarnings("unchecked") + public HiveMetaDataResultSet(final List columnNames + , final List columnTypes + , final List data) throws SQLException { + this.data = new ArrayList(data); + this.columnNames = new ArrayList(columnNames); + this.columnTypes = new ArrayList(columnTypes); + } + + @Override + public void close() throws SQLException { + } + +} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcTable.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcTable.java (revision 0) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcTable.java (revision 0) @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.jdbc; + +import java.sql.SQLException; + +/** + * Table metadata. + */ +public class JdbcTable { + private String tableCatalog; + private String tableName; + private String type; + private String comment; + + public JdbcTable(String tableCatalog, String tableName, String type, String comment) { + this.tableCatalog = tableCatalog; + this.tableName = tableName; + this.type = type; + this.comment = comment; + } + + public String getTableCatalog() { + return tableCatalog; + } + + public String getTableName() { + return tableName; + } + + public String getType() { + return type; + } + + public String getSqlTableType() throws SQLException { + return HiveDatabaseMetaData.toJdbcTableType(type); + } + + public String getComment() { + return comment; + } +} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java (revision 978817) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java (working copy) @@ -18,10 +18,23 @@ package org.apache.hadoop.hive.jdbc; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hadoop.hive.service.HiveClient; +import org.apache.hadoop.hive.service.HiveInterface; +import org.apache.hadoop.hive.service.HiveServer; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.transport.TSocket; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; + import java.sql.Array; import java.sql.Blob; import java.sql.CallableStatement; import java.sql.Clob; +import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.NClob; import java.sql.PreparedStatement; @@ -35,29 +48,17 @@ import java.util.Map; import java.util.Properties; -import org.apache.hadoop.hive.conf.HiveConf; -import org.apache.hadoop.hive.metastore.api.MetaException; -import org.apache.hadoop.hive.ql.session.SessionState; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.hadoop.hive.service.HiveInterface; -import org.apache.hadoop.hive.service.HiveServer; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; -import org.apache.thrift.transport.TTransportException; - /** * HiveConnection. * */ public class HiveConnection implements java.sql.Connection { - JdbcSessionState session; - + private final JdbcSessionState session; private TTransport transport; private HiveInterface client; - boolean isClosed = true; - SQLWarning warningChain = null; + private boolean isClosed = true; + private SQLWarning warningChain = null; + private String uri; private static final String URI_PREFIX = "jdbc:hive://"; @@ -65,12 +66,12 @@ * TODO: - parse uri (use java.net.URI?). */ public HiveConnection(String uri, Properties info) throws SQLException { + this.uri = uri; session = new JdbcSessionState(new HiveConf(SessionState.class)); session.in = null; session.out = null; session.err = null; SessionState.start(session); - String originalUri = uri; if (!uri.startsWith(URI_PREFIX)) { throw new SQLException("Invalid URL: " + uri, "08S01"); @@ -105,7 +106,7 @@ transport.open(); } catch (TTransportException e) { throw new SQLException("Could not establish connecton to " - + originalUri + ": " + e.getMessage(), "08S01"); + + uri + ": " + e.getMessage(), "08S01"); } } isClosed = false; @@ -272,8 +273,7 @@ */ public String getCatalog() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return ""; } /* @@ -316,7 +316,7 @@ */ public DatabaseMetaData getMetaData() throws SQLException { - return new HiveDatabaseMetaData(); + return new HiveDatabaseMetaData(client); } /* @@ -326,8 +326,7 @@ */ public int getTransactionIsolation() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return Connection.TRANSACTION_NONE; } /* @@ -368,8 +367,7 @@ */ public boolean isReadOnly() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } /* Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java (revision 0) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java (revision 0) @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.jdbc; + +import java.sql.SQLException; + +/** + * Column metadata. + */ +public class JdbcColumn { + private String columnName; + private String tableName; + private String tableCatalog; + private String type; + private String comment; + private int ordinalPos; + + JdbcColumn(String columnName, String tableName, String tableCatalog + , String type, String comment, int ordinalPos) { + this.columnName = columnName; + this.tableName = tableName; + this.tableCatalog = tableCatalog; + this.type = type; + this.comment = comment; + this.ordinalPos = ordinalPos; + } + + public String getColumnName() { + return columnName; + } + + public String getTableName() { + return tableName; + } + + public String getTableCatalog() { + return tableCatalog; + } + + public String getType() { + return type; + } + + public Integer getSqlType() throws SQLException { + return HiveResultSetMetaData.hiveTypeToSqlType(type); + } + + public Integer getColumnSize() { + if (type.equalsIgnoreCase("string")) { + return Integer.MAX_VALUE; + } else if (type.equalsIgnoreCase("tinyint")) { + return 3; + } else if (type.equalsIgnoreCase("smallint")) { + return 5; + } else if (type.equalsIgnoreCase("int")) { + return 10; + } else if (type.equalsIgnoreCase("bigint")) { + return 19; + } else if (type.equalsIgnoreCase("float")) { + return 12; + } else if (type.equalsIgnoreCase("double")) { + return 22; + } else { // anything else including boolean is null + return null; + } + } + + public Integer getNumPrecRadix() { + if (type.equalsIgnoreCase("tinyint")) { + return 10; + } else if (type.equalsIgnoreCase("smallint")) { + return 10; + } else if (type.equalsIgnoreCase("int")) { + return 10; + } else if (type.equalsIgnoreCase("bigint")) { + return 10; + } else if (type.equalsIgnoreCase("float")) { + return 2; + } else if (type.equalsIgnoreCase("double")) { + return 2; + } else { // anything else including boolean and string is null + return null; + } + } + + public Integer getDecimalDigits() { + if (type.equalsIgnoreCase("tinyint")) { + return 0; + } else if (type.equalsIgnoreCase("smallint")) { + return 0; + } else if (type.equalsIgnoreCase("int")) { + return 0; + } else if (type.equalsIgnoreCase("bigint")) { + return 0; + } else { // anything else including float and double is null + return null; + } + } + + public String getComment() { + return comment; + } + + public int getOrdinalPos() { + return ordinalPos; + } +} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java (revision 978817) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java (working copy) @@ -31,8 +31,8 @@ * */ public class HiveStatement implements java.sql.Statement { - JdbcSessionState session; - HiveInterface client; + private JdbcSessionState session; + private HiveInterface client; /** * We need to keep a reference to the result set to support the following: * @@ -40,22 +40,22 @@ * statement.getResultSet(); * . */ - ResultSet resultSet = null; + private ResultSet resultSet = null; /** * The maximum number of rows this statement should return (0 => all rows). */ - int maxRows = 0; + private int maxRows = 0; /** * Add SQLWarnings to the warningChain if needed. */ - SQLWarning warningChain = null; + private SQLWarning warningChain = null; /** * Keep state so we can fail certain calls made after close(). */ - boolean isClosed = false; + private boolean isClosed = false; /** * @@ -72,7 +72,6 @@ */ public void addBatch(String sql) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -83,7 +82,6 @@ */ public void cancel() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -94,7 +92,6 @@ */ public void clearBatch() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -115,7 +112,6 @@ */ public void close() throws SQLException { - // TODO: how to properly shut down the client? client = null; resultSet = null; isClosed = true; @@ -142,7 +138,6 @@ */ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -153,7 +148,6 @@ */ public boolean execute(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -164,7 +158,6 @@ */ public boolean execute(String sql, String[] columnNames) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -175,7 +168,6 @@ */ public int[] executeBatch() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -198,7 +190,7 @@ } catch (Exception ex) { throw new SQLException(ex.toString(), "08S01"); } - resultSet = new HiveResultSet(client, maxRows); + resultSet = new HiveQueryResultSet(client, maxRows); return resultSet; } @@ -224,7 +216,6 @@ */ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -235,7 +226,6 @@ */ public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -246,7 +236,6 @@ */ public int executeUpdate(String sql, String[] columnNames) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -257,7 +246,6 @@ */ public Connection getConnection() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -268,7 +256,6 @@ */ public int getFetchDirection() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -279,7 +266,6 @@ */ public int getFetchSize() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -290,7 +276,6 @@ */ public ResultSet getGeneratedKeys() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -301,7 +286,6 @@ */ public int getMaxFieldSize() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -322,7 +306,6 @@ */ public boolean getMoreResults() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -333,7 +316,6 @@ */ public boolean getMoreResults(int current) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -344,7 +326,6 @@ */ public int getQueryTimeout() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -365,7 +346,6 @@ */ public int getResultSetConcurrency() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -376,7 +356,6 @@ */ public int getResultSetHoldability() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -387,7 +366,6 @@ */ public int getResultSetType() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -428,7 +406,6 @@ */ public boolean isPoolable() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -439,7 +416,6 @@ */ public void setCursorName(String name) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -450,7 +426,6 @@ */ public void setEscapeProcessing(boolean enable) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -461,7 +436,6 @@ */ public void setFetchDirection(int direction) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -472,7 +446,6 @@ */ public void setFetchSize(int rows) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -483,7 +456,6 @@ */ public void setMaxFieldSize(int max) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -507,7 +479,6 @@ */ public void setPoolable(boolean poolable) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -518,7 +489,6 @@ */ public void setQueryTimeout(int seconds) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -529,7 +499,6 @@ */ public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -540,7 +509,6 @@ */ public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java (revision 978817) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java (working copy) @@ -18,6 +18,11 @@ package org.apache.hadoop.hive.jdbc; +import org.apache.hadoop.hive.metastore.TableType; +import org.apache.hadoop.hive.metastore.api.FieldSchema; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.service.HiveInterface; + import java.io.IOException; import java.net.URL; import java.sql.Connection; @@ -25,6 +30,11 @@ import java.sql.ResultSet; import java.sql.RowIdLifetime; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.jar.Attributes; import java.util.jar.Manifest; @@ -34,1959 +44,996 @@ */ public class HiveDatabaseMetaData implements java.sql.DatabaseMetaData { + private HiveInterface client; + private static final String CATALOG_SEPARATOR = "."; + /** * */ - public HiveDatabaseMetaData() { - // TODO Auto-generated constructor stub + public HiveDatabaseMetaData(HiveInterface client) { + this.client = client; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#allProceduresAreCallable() - */ - public boolean allProceduresAreCallable() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#allTablesAreSelectable() - */ - public boolean allTablesAreSelectable() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return true; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#autoCommitFailureClosesAllResultSets() - */ - public boolean autoCommitFailureClosesAllResultSets() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit() - */ - public boolean dataDefinitionCausesTransactionCommit() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#dataDefinitionIgnoredInTransactions() - */ - public boolean dataDefinitionIgnoredInTransactions() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#deletesAreDetected(int) - */ - public boolean deletesAreDetected(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#doesMaxRowSizeIncludeBlobs() - */ - public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getAttributes(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String) - */ - public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getBestRowIdentifier(java.lang.String, - * java.lang.String, java.lang.String, int, boolean) - */ - public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getCatalogSeparator() - */ - public String getCatalogSeparator() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return CATALOG_SEPARATOR; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getCatalogTerm() - */ - public String getCatalogTerm() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return "database"; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getCatalogs() - */ - public ResultSet getCatalogs() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + try { + // TODO a client call to get the schema's after HIVE-675 is implemented + final List catalogs = new ArrayList(); + catalogs.add("default"); + return new HiveMetaDataResultSet(Arrays.asList("TABLE_CAT") + , Arrays.asList("STRING") + , catalogs) { + private int cnt = 0; + + public boolean next() throws SQLException { + if (cnt a = new ArrayList(1); + a.add(data.get(cnt)); // TABLE_CAT String => table catalog (may be null) + row = a; + cnt++; + return true; + } else { + return false; + } + } + }; + } catch (Exception e) { + throw new SQLException(e); + } } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getClientInfoProperties() - */ - public ResultSet getClientInfoProperties() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getColumnPrivileges(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String) - */ - public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getColumns(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String) - */ + private String convertPattern(final String pattern) { + if (pattern==null) { + return ".*"; + } else { + return pattern.replace("%", ".*").replace("_", "."); + } + } - public ResultSet getColumns(String catalog, String schemaPattern, - String tableNamePattern, String columnNamePattern) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + public ResultSet getColumns(String catalog, final String schemaPattern + , final String tableNamePattern + , final String columnNamePattern) throws SQLException { + List columns = new ArrayList(); + try { + if (catalog==null) { + catalog = "default"; + } + + String regtableNamePattern = convertPattern(tableNamePattern); + String regcolumnNamePattern = convertPattern(columnNamePattern); + + List tables = client.get_tables(catalog, "*"); + for (String table: tables) { + if (table.matches(regtableNamePattern)) { + List fields = client.get_fields(catalog, table); + int ordinalPos = 1; + for (FieldSchema field: fields) { + if (field.getName().matches(regcolumnNamePattern)) { + columns.add(new JdbcColumn(field.getName(), table, catalog + , field.getType(), field.getComment(), ordinalPos)); + ordinalPos++; + } + } + } + } + Collections.sort(columns, new GetColumnsComparator()); + + return new HiveMetaDataResultSet( + Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE" + , "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS" + , "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE" + , "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION" + , "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE" + , "SOURCE_DATA_TYPE") + , Arrays.asList("STRING", "STRING", "STRING", "STRING", "I32", "STRING" + , "I32", "I32", "I32", "I32", "I32", "STRING" + , "STRING", "I32", "I32", "I32", "I32" + , "STRING", "STRING", "STRING", "STRING", "I32") + , columns) { + + private int cnt = 0; + + public boolean next() throws SQLException { + if (cnt a = new ArrayList(20); + JdbcColumn column = data.get(cnt); + a.add(column.getTableCatalog()); // TABLE_CAT String => table catalog (may be null) + a.add(null); // TABLE_SCHEM String => table schema (may be null) + a.add(column.getTableName()); // TABLE_NAME String => table name + a.add(column.getColumnName()); // COLUMN_NAME String => column name + a.add(column.getSqlType()); // DATA_TYPE short => SQL type from java.sql.Types + a.add(column.getType()); // TYPE_NAME String => Data source dependent type name. + a.add(column.getColumnSize()); // COLUMN_SIZE int => column size. + a.add(null); // BUFFER_LENGTH is not used. + a.add(column.getDecimalDigits()); // DECIMAL_DIGITS int => number of fractional digits + a.add(column.getNumPrecRadix()); // NUM_PREC_RADIX int => typically either 10 or 2 + a.add(DatabaseMetaData.columnNullable); // NULLABLE int => is NULL allowed? + a.add(column.getComment()); // REMARKS String => comment describing column (may be null) + a.add(null); // COLUMN_DEF String => default value (may be null) + a.add(null); // SQL_DATA_TYPE int => unused + a.add(null); // SQL_DATETIME_SUB int => unused + a.add(null); // CHAR_OCTET_LENGTH int + a.add(column.getOrdinalPos()); // ORDINAL_POSITION int + a.add("YES"); // IS_NULLABLE String + a.add(null); // SCOPE_CATLOG String + a.add(null); // SCOPE_SCHEMA String + a.add(null); // SCOPE_TABLE String + a.add(null); // SOURCE_DATA_TYPE short + row = a; + cnt++; + return true; + } else { + return false; + } + } + }; + } catch (Exception e) { + throw new SQLException(e); + } } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getConnection() + /** + * We sort the output of getColumns to guarantee jdbc compliance. + * First check by table name then by ordinal position */ + private class GetColumnsComparator implements Comparator { + public int compare(JdbcColumn o1, JdbcColumn o2) { + int compareName = o1.getTableName().compareTo(o2.getTableName()); + if (compareName==0) { + if (o1.getOrdinalPos() > o2.getOrdinalPos()) { + return 1; + } else if (o1.getOrdinalPos() < o2.getOrdinalPos()) { + return -1; + } + return 0; + } else { + return compareName; + } + } + } + public Connection getConnection() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getCrossReference(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String) - */ - public ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDatabaseMajorVersion() - */ - public int getDatabaseMajorVersion() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDatabaseMinorVersion() - */ - public int getDatabaseMinorVersion() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDatabaseProductName() - */ - public String getDatabaseProductName() throws SQLException { return "Hive"; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDatabaseProductVersion() - */ - public String getDatabaseProductVersion() throws SQLException { return "0"; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDefaultTransactionIsolation() - */ - public int getDefaultTransactionIsolation() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return Connection.TRANSACTION_NONE; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDriverMajorVersion() - */ - public int getDriverMajorVersion() { - // TODO Auto-generated method stub return 0; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDriverMinorVersion() - */ - public int getDriverMinorVersion() { - // TODO Auto-generated method stub return 0; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDriverName() - */ - public String getDriverName() throws SQLException { return fetchManifestAttribute(Attributes.Name.IMPLEMENTATION_TITLE); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getDriverVersion() - */ - public String getDriverVersion() throws SQLException { return fetchManifestAttribute(Attributes.Name.IMPLEMENTATION_VERSION); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getExportedKeys(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getExtraNameCharacters() - */ - public String getExtraNameCharacters() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getFunctionColumns(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String) - */ - public ResultSet getFunctionColumns(String arg0, String arg1, String arg2, String arg3) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getFunctions(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getFunctions(String arg0, String arg1, String arg2) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getIdentifierQuoteString() - */ - public String getIdentifierQuoteString() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getImportedKeys(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getIndexInfo(java.lang.String, - * java.lang.String, java.lang.String, boolean, boolean) - */ - public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getJDBCMajorVersion() - */ - public int getJDBCMajorVersion() throws SQLException { return 3; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getJDBCMinorVersion() - */ - public int getJDBCMinorVersion() throws SQLException { return 0; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxBinaryLiteralLength() - */ - public int getMaxBinaryLiteralLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxCatalogNameLength() - */ - public int getMaxCatalogNameLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxCharLiteralLength() - */ - public int getMaxCharLiteralLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxColumnNameLength() - */ - public int getMaxColumnNameLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxColumnsInGroupBy() - */ - public int getMaxColumnsInGroupBy() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxColumnsInIndex() - */ - public int getMaxColumnsInIndex() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxColumnsInOrderBy() - */ - public int getMaxColumnsInOrderBy() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxColumnsInSelect() - */ - public int getMaxColumnsInSelect() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxColumnsInTable() - */ - public int getMaxColumnsInTable() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxConnections() - */ - public int getMaxConnections() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxCursorNameLength() - */ - public int getMaxCursorNameLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxIndexLength() - */ - public int getMaxIndexLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxProcedureNameLength() - */ - public int getMaxProcedureNameLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxRowSize() - */ - public int getMaxRowSize() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxSchemaNameLength() - */ - public int getMaxSchemaNameLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxStatementLength() - */ - public int getMaxStatementLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxStatements() - */ - public int getMaxStatements() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxTableNameLength() - */ - public int getMaxTableNameLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxTablesInSelect() - */ - public int getMaxTablesInSelect() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getMaxUserNameLength() - */ - public int getMaxUserNameLength() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getNumericFunctions() - */ - public String getNumericFunctions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return ""; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getPrimaryKeys(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getProcedureColumns(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String) - */ - public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getProcedureTerm() - */ - public String getProcedureTerm() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getProcedures(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { - // TODO: return empty result set here return null; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getResultSetHoldability() - */ - public int getResultSetHoldability() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getRowIdLifetime() - */ - public RowIdLifetime getRowIdLifetime() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSQLKeywords() - */ - public String getSQLKeywords() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSQLStateType() - */ - public int getSQLStateType() throws SQLException { return DatabaseMetaData.sqlStateSQL99; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSchemaTerm() - */ - public String getSchemaTerm() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return ""; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSchemas() - */ - public ResultSet getSchemas() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return getSchemas(null, null); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSchemas(java.lang.String, - * java.lang.String) - */ - public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } + return new HiveMetaDataResultSet(Arrays.asList("TABLE_SCHEM", "TABLE_CATALOG") + , Arrays.asList("STRING", "STRING"), null) { - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSearchStringEscape() - */ + public boolean next() throws SQLException { + return false; + } + }; + } + public String getSearchStringEscape() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getStringFunctions() - */ - public String getStringFunctions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return ""; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSuperTables(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSuperTypes(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getSystemFunctions() - */ - public String getSystemFunctions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return ""; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getTablePrivileges(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getTableTypes() - */ - public ResultSet getTableTypes() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + final TableType[] tt = TableType.values(); + ResultSet result = new HiveMetaDataResultSet( + Arrays.asList("TABLE_TYPE") + , Arrays.asList("STRING"), new ArrayList(Arrays.asList(tt))) { + private int cnt = 0; + + public boolean next() throws SQLException { + if (cnt a = new ArrayList(1); + a.add(toJdbcTableType(data.get(cnt).name())); + row = a; + cnt++; + return true; + } else { + return false; + } + } + }; + return result; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getTables(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String[]) - */ - public ResultSet getTables(String catalog, String schemaPattern, - String tableNamePattern, String[] types) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + String tableNamePattern, String[] types) throws SQLException { + final List tablesstr; + final List resultTables = new ArrayList(); + final String resultCatalog; + if (catalog==null) { // On jdbc the default catalog is null but on hive it's "default" + resultCatalog = "default"; + } else { + resultCatalog = catalog; + } + + String regtableNamePattern = convertPattern(tableNamePattern); + try { + tablesstr = client.get_tables(resultCatalog, "*"); + for (String tablestr: tablesstr) { + if (tablestr.matches(regtableNamePattern)) { + Table tbl = client.get_table(resultCatalog, tablestr); + if (types == null) { + resultTables.add(new JdbcTable(resultCatalog, tbl.getTableName(), tbl.getTableType() + , tbl.getParameters().get("comment"))); + } else { + String tableType = toJdbcTableType(tbl.getTableType()); + for(String type : types) { + if (type.equalsIgnoreCase(tableType)) { + resultTables.add(new JdbcTable(resultCatalog, tbl.getTableName(), tbl.getTableType() + , tbl.getParameters().get("comment"))); + break; + } + } + } + } + } + Collections.sort(resultTables, new GetTablesComparator()); + } catch (Exception e) { + throw new SQLException(e); + } + ResultSet result = new HiveMetaDataResultSet( + Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS") + , Arrays.asList("STRING", "STRING", "STRING", "STRING", "STRING") + , resultTables) { + private int cnt = 0; + + public boolean next() throws SQLException { + if (cnt a = new ArrayList(5); + JdbcTable table = data.get(cnt); + a.add(table.getTableCatalog()); // TABLE_CAT String => table catalog (may be null) + a.add(null); // TABLE_SCHEM String => table schema (may be null) + a.add(table.getTableName()); // TABLE_NAME String => table name + try { + a.add(table.getSqlTableType()); // TABLE_TYPE String => "TABLE","VIEW" + } catch (Exception e) { + throw new SQLException(e); + } + a.add(table.getComment()); // REMARKS String => explanatory comment on the table + row = a; + cnt++; + return true; + } else { + return false; + } + } + + }; + return result; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getTimeDateFunctions() + /** + * We sort the output of getTables to guarantee jdbc compliance. + * First check by table type then by table name */ + private class GetTablesComparator implements Comparator { - public String getTimeDateFunctions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + public int compare(JdbcTable o1, JdbcTable o2) { + int compareType = o1.getType().compareTo(o2.getType()); + if (compareType==0) { + return o1.getTableName().compareTo(o2.getTableName()); + } else { + return compareType; + } + } } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getTypeInfo() + /** + * Translate hive table types into jdbc table types. + * @param hivetabletype + * @return */ + public static String toJdbcTableType(String hivetabletype) { + if (hivetabletype==null) { + return null; + } else if (hivetabletype.equals(TableType.MANAGED_TABLE.toString())) { + return "TABLE"; + } else if (hivetabletype.equals(TableType.VIRTUAL_VIEW.toString())) { + return "VIEW"; + } else if (hivetabletype.equals(TableType.EXTERNAL_TABLE.toString())) { + return "EXTERNAL TABLE"; + } else { + return hivetabletype; + } + } + public String getTimeDateFunctions() throws SQLException { + return ""; + } + public ResultSet getTypeInfo() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getUDTs(java.lang.String, java.lang.String, - * java.lang.String, int[]) - */ - public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getURL() - */ + return new HiveMetaDataResultSet( + Arrays.asList("TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "CLASS_NAME", "DATA_TYPE" + , "REMARKS", "BASE_TYPE") + , Arrays.asList("STRING", "STRING", "STRING", "STRING", "I32", "STRING", "I32") + , null) { + public boolean next() throws SQLException { + return false; + } + }; + } + public String getURL() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getUserName() - */ - public String getUserName() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#getVersionColumns(java.lang.String, - * java.lang.String, java.lang.String) - */ - public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#insertsAreDetected(int) - */ - public boolean insertsAreDetected(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#isCatalogAtStart() - */ - public boolean isCatalogAtStart() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#isReadOnly() - */ - public boolean isReadOnly() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#locatorsUpdateCopy() - */ - public boolean locatorsUpdateCopy() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#nullPlusNonNullIsNull() - */ - public boolean nullPlusNonNullIsNull() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#nullsAreSortedAtEnd() - */ - public boolean nullsAreSortedAtEnd() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#nullsAreSortedAtStart() - */ - public boolean nullsAreSortedAtStart() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#nullsAreSortedHigh() - */ - public boolean nullsAreSortedHigh() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#nullsAreSortedLow() - */ - public boolean nullsAreSortedLow() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#othersDeletesAreVisible(int) - */ - public boolean othersDeletesAreVisible(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#othersInsertsAreVisible(int) - */ - public boolean othersInsertsAreVisible(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#othersUpdatesAreVisible(int) - */ - public boolean othersUpdatesAreVisible(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#ownDeletesAreVisible(int) - */ - public boolean ownDeletesAreVisible(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#ownInsertsAreVisible(int) - */ - public boolean ownInsertsAreVisible(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#ownUpdatesAreVisible(int) - */ - public boolean ownUpdatesAreVisible(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#storesLowerCaseIdentifiers() - */ - public boolean storesLowerCaseIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#storesLowerCaseQuotedIdentifiers() - */ - public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#storesMixedCaseIdentifiers() - */ - public boolean storesMixedCaseIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#storesMixedCaseQuotedIdentifiers() - */ - public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#storesUpperCaseIdentifiers() - */ - public boolean storesUpperCaseIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#storesUpperCaseQuotedIdentifiers() - */ - public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsANSI92EntryLevelSQL() - */ - public boolean supportsANSI92EntryLevelSQL() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsANSI92FullSQL() - */ - public boolean supportsANSI92FullSQL() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsANSI92IntermediateSQL() - */ - public boolean supportsANSI92IntermediateSQL() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsAlterTableWithAddColumn() - */ - public boolean supportsAlterTableWithAddColumn() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return true; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsAlterTableWithDropColumn() - */ - public boolean supportsAlterTableWithDropColumn() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsBatchUpdates() - */ - public boolean supportsBatchUpdates() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsCatalogsInDataManipulation() - */ - public boolean supportsCatalogsInDataManipulation() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsCatalogsInIndexDefinitions() - */ - public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsCatalogsInPrivilegeDefinitions() - */ - public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsCatalogsInProcedureCalls() - */ - public boolean supportsCatalogsInProcedureCalls() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsCatalogsInTableDefinitions() - */ - public boolean supportsCatalogsInTableDefinitions() throws SQLException { return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsColumnAliasing() - */ - public boolean supportsColumnAliasing() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return true; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsConvert() - */ - public boolean supportsConvert() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsConvert(int, int) - */ - public boolean supportsConvert(int fromType, int toType) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsCoreSQLGrammar() - */ - public boolean supportsCoreSQLGrammar() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsCorrelatedSubqueries() - */ - public boolean supportsCorrelatedSubqueries() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see - * java.sql.DatabaseMetaData#supportsDataDefinitionAndDataManipulationTransactions - * () - */ - public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsDataManipulationTransactionsOnly() - */ - public boolean supportsDataManipulationTransactionsOnly() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsDifferentTableCorrelationNames() - */ - public boolean supportsDifferentTableCorrelationNames() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsExpressionsInOrderBy() - */ - public boolean supportsExpressionsInOrderBy() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsExtendedSQLGrammar() - */ - public boolean supportsExtendedSQLGrammar() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsFullOuterJoins() - */ - public boolean supportsFullOuterJoins() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys() - */ - public boolean supportsGetGeneratedKeys() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsGroupBy() - */ - public boolean supportsGroupBy() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return true; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsGroupByBeyondSelect() - */ - public boolean supportsGroupByBeyondSelect() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsGroupByUnrelated() - */ - public boolean supportsGroupByUnrelated() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsIntegrityEnhancementFacility() - */ - public boolean supportsIntegrityEnhancementFacility() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsLikeEscapeClause() - */ - public boolean supportsLikeEscapeClause() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsLimitedOuterJoins() - */ - public boolean supportsLimitedOuterJoins() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsMinimumSQLGrammar() - */ - public boolean supportsMinimumSQLGrammar() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsMixedCaseIdentifiers() - */ - public boolean supportsMixedCaseIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsMixedCaseQuotedIdentifiers() - */ - public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsMultipleOpenResults() - */ - public boolean supportsMultipleOpenResults() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsMultipleResultSets() - */ - public boolean supportsMultipleResultSets() throws SQLException { return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsMultipleTransactions() - */ - public boolean supportsMultipleTransactions() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsNamedParameters() - */ - public boolean supportsNamedParameters() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsNonNullableColumns() - */ - public boolean supportsNonNullableColumns() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsOpenCursorsAcrossCommit() - */ - public boolean supportsOpenCursorsAcrossCommit() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsOpenCursorsAcrossRollback() - */ - public boolean supportsOpenCursorsAcrossRollback() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsOpenStatementsAcrossCommit() - */ - public boolean supportsOpenStatementsAcrossCommit() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsOpenStatementsAcrossRollback() - */ - public boolean supportsOpenStatementsAcrossRollback() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsOrderByUnrelated() - */ - public boolean supportsOrderByUnrelated() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsOuterJoins() - */ - public boolean supportsOuterJoins() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return true; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsPositionedDelete() - */ - public boolean supportsPositionedDelete() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsPositionedUpdate() - */ - public boolean supportsPositionedUpdate() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsResultSetConcurrency(int, int) - */ - public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsResultSetHoldability(int) - */ - public boolean supportsResultSetHoldability(int holdability) throws SQLException { return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsResultSetType(int) - */ - public boolean supportsResultSetType(int type) throws SQLException { return true; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSavepoints() - */ - public boolean supportsSavepoints() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSchemasInDataManipulation() - */ - public boolean supportsSchemasInDataManipulation() throws SQLException { return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSchemasInIndexDefinitions() - */ - public boolean supportsSchemasInIndexDefinitions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSchemasInPrivilegeDefinitions() - */ - public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSchemasInProcedureCalls() - */ - public boolean supportsSchemasInProcedureCalls() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSchemasInTableDefinitions() - */ - public boolean supportsSchemasInTableDefinitions() throws SQLException { return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSelectForUpdate() - */ - public boolean supportsSelectForUpdate() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsStatementPooling() - */ - public boolean supportsStatementPooling() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsStoredFunctionsUsingCallSyntax() - */ - public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsStoredProcedures() - */ - public boolean supportsStoredProcedures() throws SQLException { return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSubqueriesInComparisons() - */ - public boolean supportsSubqueriesInComparisons() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSubqueriesInExists() - */ - public boolean supportsSubqueriesInExists() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSubqueriesInIns() - */ - public boolean supportsSubqueriesInIns() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsSubqueriesInQuantifieds() - */ - public boolean supportsSubqueriesInQuantifieds() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsTableCorrelationNames() - */ - public boolean supportsTableCorrelationNames() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsTransactionIsolationLevel(int) - */ - public boolean supportsTransactionIsolationLevel(int level) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsTransactions() - */ - public boolean supportsTransactions() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + return false; } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsUnion() - */ - public boolean supportsUnion() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#supportsUnionAll() - */ - public boolean supportsUnionAll() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#updatesAreDetected(int) - */ - public boolean updatesAreDetected(int type) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#usesLocalFilePerTable() - */ - public boolean usesLocalFilePerTable() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.DatabaseMetaData#usesLocalFiles() - */ - public boolean usesLocalFiles() throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#unwrap(java.lang.Class) - */ - public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub throw new SQLException("Method not supported"); } @@ -2032,7 +1079,7 @@ } public static void main(String[] args) throws SQLException { - HiveDatabaseMetaData meta = new HiveDatabaseMetaData(); + HiveDatabaseMetaData meta = new HiveDatabaseMetaData(null); System.out.println("DriverName: " + meta.getDriverName()); System.out.println("DriverVersion: " + meta.getDriverVersion()); } Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java (revision 0) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java (revision 0) @@ -0,0 +1,137 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.jdbc; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.api.FieldSchema; +import org.apache.hadoop.hive.metastore.api.Schema; +import org.apache.hadoop.hive.serde.Constants; +import org.apache.hadoop.hive.serde2.dynamic_type.DynamicSerDe; +import org.apache.hadoop.hive.service.HiveInterface; +import org.apache.hadoop.io.BytesWritable; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * HiveQueryResultSet. + * + */ +public class HiveQueryResultSet extends HiveBaseResultSet { + private HiveInterface client; + private DynamicSerDe ds; + + private int maxRows = 0; + private int rowsFetched = 0; + + @SuppressWarnings("unchecked") + public HiveQueryResultSet(HiveInterface client, int maxRows) throws SQLException { + this.client = client; + row = new ArrayList(); + this.maxRows = maxRows; + initDynamicSerde(); + } + + @SuppressWarnings("unchecked") + public HiveQueryResultSet(HiveInterface client) throws SQLException { + this(client, 0); + } + + /** + * Instantiate the dynamic serde used to deserialize the result row. + */ + private void initDynamicSerde() throws SQLException { + try { + Schema fullSchema = client.getThriftSchema(); + List schema = fullSchema.getFieldSchemas(); + columnNames = new ArrayList(); + columnTypes = new ArrayList(); + + String serDDL; + + if ((schema != null) && (!schema.isEmpty())) { + serDDL = new String("struct result { "); + for (int pos = 0; pos < schema.size(); pos++) { + if (pos != 0) { + serDDL = serDDL.concat(","); + } + columnTypes.add(schema.get(pos).getType()); + columnNames.add(schema.get(pos).getName()); + serDDL = serDDL.concat(schema.get(pos).getType()); + serDDL = serDDL.concat(" "); + serDDL = serDDL.concat(schema.get(pos).getName()); + } + serDDL = serDDL.concat("}"); + } else { + serDDL = new String("struct result { string empty }"); + } + + ds = new DynamicSerDe(); + Properties dsp = new Properties(); + dsp.setProperty(Constants.SERIALIZATION_FORMAT, + org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol.class + .getName()); + dsp.setProperty( + org.apache.hadoop.hive.metastore.api.Constants.META_TABLE_NAME, + "result"); + dsp.setProperty(Constants.SERIALIZATION_DDL, serDDL); + dsp.setProperty(Constants.SERIALIZATION_LIB, ds.getClass().toString()); + dsp.setProperty(Constants.FIELD_DELIM, "9"); + ds.initialize(new Configuration(), dsp); + } catch (Exception ex) { + ex.printStackTrace(); + throw new SQLException("Could not create ResultSet: " + ex.getMessage()); + } + } + + public void close() throws SQLException { + client = null; + } + + /** + * Moves the cursor down one row from its current position. + * + * @see java.sql.ResultSet#next() + * @throws SQLException + * if a database access error occurs. + */ + public boolean next() throws SQLException { + if (maxRows > 0 && rowsFetched >= maxRows) { + return false; + } + + String rowStr = ""; + try { + rowStr = (String) client.fetchOne(); + rowsFetched++; + if (!"".equals(rowStr)) { + Object o = ds.deserialize(new BytesWritable(rowStr.getBytes())); + row = (ArrayList) o; + } + } catch (Exception ex) { + ex.printStackTrace(); + throw new SQLException("Error retrieving next row"); + } + // NOTE: fetchOne dosn't throw new SQLException("Method not supported"). + return !"".equals(rowStr); + } + +}