diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java b/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java index f4983b6..b081edb 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java @@ -147,7 +147,6 @@ public ResultSet getCatalogs() throws SQLException { return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(catalogResp.getOperationHandle()) .build(); } @@ -273,7 +272,6 @@ public ResultSet getColumns(String catalog, String schemaPattern, // build the resultset from response return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(colResp.getOperationHandle()) .build(); } @@ -324,7 +322,6 @@ public ResultSet getCrossReference(String primaryCatalog, return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(getFKResp.getOperationHandle()) .build(); } @@ -405,7 +402,6 @@ public ResultSet getFunctions(String catalogName, String schemaPattern, String f return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(funcResp.getOperationHandle()) .build(); } @@ -578,7 +574,6 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(getPKResp.getOperationHandle()) .build(); } @@ -667,7 +662,6 @@ public ResultSet getSchemas(String catalog, String schemaPattern) return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(schemaResp.getOperationHandle()) .build(); } @@ -711,7 +705,6 @@ public ResultSet getTableTypes() throws SQLException { return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(tableTypeResp.getOperationHandle()) .build(); } @@ -742,7 +735,6 @@ public ResultSet getTables(String catalog, String schemaPattern, return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(getTableResp.getOperationHandle()) .build(); } @@ -800,7 +792,6 @@ public ResultSet getTypeInfo() throws SQLException { Utils.verifySuccess(getTypeInfoResp.getStatus()); return new HiveQueryResultSet.Builder(connection) .setClient(client) - .setSessionHandle(sessHandle) .setStmtHandle(getTypeInfoResp.getOperationHandle()) .build(); } diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java b/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java index 78025c5..8563cee 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java @@ -27,9 +27,9 @@ import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.concurrent.locks.ReentrantLock; import org.apache.hadoop.hive.common.type.HiveDecimal; import org.apache.hive.service.cli.RowSet; @@ -50,7 +50,6 @@ import org.apache.hive.service.rpc.thrift.TPrimitiveTypeEntry; import org.apache.hive.service.rpc.thrift.TProtocolVersion; import org.apache.hive.service.rpc.thrift.TRowSet; -import org.apache.hive.service.rpc.thrift.TSessionHandle; import org.apache.hive.service.rpc.thrift.TTableSchema; import org.apache.hive.service.rpc.thrift.TTypeQualifierValue; import org.apache.hive.service.rpc.thrift.TTypeQualifiers; @@ -67,7 +66,6 @@ private TCLIService.Iface client; private TOperationHandle stmtHandle; - private TSessionHandle sessHandle; private int maxRows; private int fetchSize; private int rowsFetched = 0; @@ -88,7 +86,6 @@ private final Statement statement; private TCLIService.Iface client = null; private TOperationHandle stmtHandle = null; - private TSessionHandle sessHandle = null; /** * Sets the limit for the maximum number of rows that any ResultSet object produced by this @@ -103,7 +100,6 @@ private int fetchSize = 50; private boolean emptyResultSet = false; private boolean isScrollable = false; - private ReentrantLock transportLock = null; public Builder(Statement statement) throws SQLException { this.statement = statement; @@ -125,11 +121,6 @@ public Builder setStmtHandle(TOperationHandle stmtHandle) { return this; } - public Builder setSessionHandle(TSessionHandle sessHandle) { - this.sessHandle = sessHandle; - return this; - } - public Builder setMaxRows(int maxRows) { this.maxRows = maxRows; return this; @@ -138,21 +129,15 @@ public Builder setMaxRows(int maxRows) { public Builder setSchema(List colNames, List colTypes) { // no column attributes provided - create list of null attributes. List colAttributes = - new ArrayList(); - for (int idx = 0; idx < colTypes.size(); ++idx) { - colAttributes.add(null); - } + Collections.nCopies(colTypes.size(), null); return setSchema(colNames, colTypes, colAttributes); } public Builder setSchema(List colNames, List colTypes, List colAttributes) { - this.colNames = new ArrayList(); - this.colNames.addAll(colNames); - this.colTypes = new ArrayList(); - this.colTypes.addAll(colTypes); - this.colAttributes = new ArrayList(); - this.colAttributes.addAll(colAttributes); + this.colNames = new ArrayList<>(colNames); + this.colTypes = new ArrayList<>(colTypes); + this.colAttributes = new ArrayList<>(colAttributes); this.retrieveSchema = false; return this; } @@ -172,11 +157,6 @@ public Builder setScrollable(boolean setScrollable) { return this; } - public Builder setTransportLock(ReentrantLock transportLock) { - this.transportLock = transportLock; - return this; - } - public HiveQueryResultSet build() throws SQLException { return new HiveQueryResultSet(this); } @@ -190,7 +170,6 @@ protected HiveQueryResultSet(Builder builder) throws SQLException { this.statement = builder.statement; this.client = builder.client; this.stmtHandle = builder.stmtHandle; - this.sessHandle = builder.sessHandle; this.fetchSize = builder.fetchSize; columnNames = new ArrayList(); normalizedColumnNames = new ArrayList(); @@ -202,10 +181,9 @@ protected HiveQueryResultSet(Builder builder) throws SQLException { this.setSchema(builder.colNames, builder.colTypes, builder.colAttributes); } this.emptyResultSet = builder.emptyResultSet; + this.maxRows = builder.maxRows; if (builder.emptyResultSet) { this.maxRows = 0; - } else { - this.maxRows = builder.maxRows; } this.isScrollable = builder.isScrollable; this.protocol = builder.getProtocolVersion(); @@ -255,9 +233,6 @@ private void retrieveSchema() throws SQLException { metadataResp = client.GetResultSetMetadata(metadataReq); Utils.verifySuccess(metadataResp.getStatus()); - StringBuilder namesSb = new StringBuilder(); - StringBuilder typesSb = new StringBuilder(); - TTableSchema schema = metadataResp.getSchema(); if (schema == null || !schema.isSetColumns()) { // TODO: should probably throw an exception here. @@ -265,17 +240,12 @@ private void retrieveSchema() throws SQLException { } setSchema(new TableSchema(schema)); - List columns = schema.getColumns(); - for (int pos = 0; pos < schema.getColumnsSize(); pos++) { - if (pos != 0) { - namesSb.append(","); - typesSb.append(","); - } - String columnName = columns.get(pos).getColumnName(); + for (final TColumnDesc column : schema.getColumns()) { + String columnName = column.getColumnName(); columnNames.add(columnName); normalizedColumnNames.add(columnName.toLowerCase()); TPrimitiveTypeEntry primitiveTypeEntry = - columns.get(pos).getTypeDesc().getTypes().get(0).getPrimitiveEntry(); + column.getTypeDesc().getTypes().get(0).getPrimitiveEntry(); String columnTypeName = TYPE_NAMES.get(primitiveTypeEntry.getType()); columnTypes.add(columnTypeName); columnAttributes.add(getColumnAttributes(primitiveTypeEntry)); @@ -283,7 +253,6 @@ private void retrieveSchema() throws SQLException { } catch (SQLException eS) { throw eS; // rethrow the SQLException as is } catch (Exception ex) { - ex.printStackTrace(); throw new SQLException("Could not create ResultSet: " + ex.getMessage(), ex); } } @@ -299,9 +268,7 @@ private void setSchema(List colNames, List colTypes, columnTypes.addAll(colTypes); columnAttributes.addAll(colAttributes); - for (String colName : colNames) { - normalizedColumnNames.add(colName.toLowerCase()); - } + colNames.forEach(i -> normalizedColumnNames.add(i.toLowerCase())); } @Override @@ -317,7 +284,6 @@ public void close() throws SQLException { // Need reset during re-open when needed client = null; stmtHandle = null; - sessHandle = null; isClosed = true; operationStatus = null; } @@ -383,17 +349,15 @@ public boolean next() throws SQLException { fetchedRowsItr = fetchedRows.iterator(); } - if (fetchedRowsItr.hasNext()) { - row = fetchedRowsItr.next(); - } else { + if (!fetchedRowsItr.hasNext()) { return false; } + row = fetchedRowsItr.next(); rowsFetched++; } catch (SQLException eS) { throw eS; } catch (Exception ex) { - ex.printStackTrace(); throw new SQLException("Error retrieving next row", ex); } // NOTE: fetchOne doesn't throw new SQLFeatureNotSupportedException("Method not supported"). @@ -423,9 +387,8 @@ public int getType() throws SQLException { } if (isScrollable) { return ResultSet.TYPE_SCROLL_INSENSITIVE; - } else { - return ResultSet.TYPE_FORWARD_ONLY; } + return ResultSet.TYPE_FORWARD_ONLY; } @Override diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index 89ff514..a9a312c 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -269,7 +269,7 @@ public boolean execute(String sql) throws SQLException { if (!status.isHasResultSet() && !stmtHandle.isHasResultSet()) { return false; } - resultSet = new HiveQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle) + resultSet = new HiveQueryResultSet.Builder(this).setClient(client) .setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize) .setScrollable(isScrollableResultset) .build(); @@ -298,9 +298,10 @@ public boolean executeAsync(String sql) throws SQLException { return false; } resultSet = - new HiveQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle) - .setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize) - .setScrollable(isScrollableResultset).build(); + new HiveQueryResultSet.Builder(this).setClient(client) + .setStmtHandle(stmtHandle).setMaxRows(maxRows) + .setFetchSize(fetchSize).setScrollable(isScrollableResultset) + .build(); return true; }