Author: prasadm
Date: Thu Dec 12 20:45:55 2013
New Revision: 1550521
URL: http://svn.apache.org/r1550521
Log:
HIVE-4395: Support TFetchOrientation.FIRST for HiveServer2 FetchResults (Prasad
Mujumdar reviewed by Thejas Nair)
Modified:
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Context.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetColumnsOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetFunctionsOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetSchemasOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTablesOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/Operation.java
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
Modified:
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
URL:
http://svn.apache.org/viewvc/hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
(original)
+++
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
Thu Dec 12 20:45:55 2013
@@ -48,6 +48,8 @@ import java.util.regex.Pattern;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.ql.processors.DfsProcessor;
+import org.apache.hadoop.hive.ql.processors.SetProcessor;
import org.apache.hive.common.util.HiveVersionInfo;
import org.apache.hive.jdbc.Utils.JdbcConnectionParams;
import org.apache.hive.service.cli.operation.ClassicTableTypeMapping;
@@ -1811,4 +1813,119 @@ public class TestJdbcDriver2 {
Connection conn = driver.connect("jdbc:derby://localhost:10000/default",
new Properties());
assertNull(conn);
}
+
+ /**
+ * Test the cursor repositioning to start of resultset
+ * @throws Exception
+ */
+ public void testFetchFirstQuery() throws Exception {
+ execFetchFirst("select c4 from " + dataTypeTableName + " order by c1",
"c4", false);
+ execFetchFirst("select c4 from " + dataTypeTableName + " order by c1",
"c4", true);
+ }
+
+ /**
+ * Test the cursor repositioning to start of resultset from non-mr query
+ * @throws Exception
+ */
+ public void testFetchFirstNonMR() throws Exception {
+ execFetchFirst("select * from " + dataTypeTableName, "c4", false);
+ }
+
+ /**
+ * Test for cursor repositioning to start of resultset for non-sql commands
+ * @throws Exception
+ */
+ public void testFetchFirstSetCmds() throws Exception {
+ execFetchFirst("set -v", SetProcessor.SET_COLUMN_NAME, false);
+ }
+
+ /**
+ * Test for cursor repositioning to start of resultset for non-sql commands
+ * @throws Exception
+ */
+ public void testFetchFirstDfsCmds() throws Exception {
+ String wareHouseDir =
conf.get(HiveConf.ConfVars.METASTOREWAREHOUSE.varname);
+ execFetchFirst("dfs -ls " + wareHouseDir, DfsProcessor.DFS_RESULT_HEADER,
false);
+ }
+
+
+ /**
+ * Negative Test for cursor repositioning to start of resultset
+ * Verify unsupported JDBC resultset attributes
+ * @throws Exception
+ */
+ public void testUnsupportedFetchTypes() throws Exception {
+ try {
+ con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
+ ResultSet.CONCUR_READ_ONLY);
+ fail("createStatement with TYPE_SCROLL_SENSITIVE should fail");
+ } catch(SQLException e) {
+ assertEquals("HYC00", e.getSQLState().trim());
+ }
+
+ try {
+ con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_UPDATABLE);
+ fail("createStatement with CONCUR_UPDATABLE should fail");
+ } catch(SQLException e) {
+ assertEquals("HYC00", e.getSQLState().trim());
+ }
+ }
+
+ /**
+ * Negative Test for cursor repositioning to start of resultset
+ * Verify unsupported JDBC resultset methods
+ * @throws Exception
+ */
+ public void testFetchFirstError() throws Exception {
+ Statement stmt = con.createStatement();
+ ResultSet res = stmt.executeQuery("select * from " + tableName);
+ try {
+ res.beforeFirst();
+ fail("beforeFirst() should fail for normal resultset");
+ } catch (SQLException e) {
+ assertEquals("Method not supported for TYPE_FORWARD_ONLY resultset",
e.getMessage());
+ }
+ }
+
+ /**
+ * Read the results locally. Then reset the read position to start and read
the
+ * rows again verify that we get the same results next time.
+ * @param sqlStmt - SQL statement to execute
+ * @param colName - columns name to read
+ * @param oneRowOnly - read and compare only one row from the resultset
+ * @throws Exception
+ */
+ private void execFetchFirst(String sqlStmt, String colName, boolean
oneRowOnly)
+ throws Exception {
+ Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_READ_ONLY);
+ ResultSet res = stmt.executeQuery(sqlStmt);
+
+ List<String> results = new ArrayList<String> ();
+ assertTrue(res.isBeforeFirst());
+ int rowNum = 0;
+ while (res.next()) {
+ results.add(res.getString(colName));
+ assertEquals(++rowNum, res.getRow());
+ assertFalse(res.isBeforeFirst());
+ if (oneRowOnly) {
+ break;
+ }
+ }
+ // reposition at the begining
+ res.beforeFirst();
+ assertTrue(res.isBeforeFirst());
+ rowNum = 0;
+ while (res.next()) {
+ // compare the results fetched last time
+ assertEquals(results.get(rowNum++), res.getString(colName));
+ assertEquals(rowNum, res.getRow());
+ assertFalse(res.isBeforeFirst());
+ if (oneRowOnly) {
+ break;
+ }
+ }
+ }
+
}
Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
URL:
http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java Thu Dec
12 20:45:55 2013
@@ -27,6 +27,7 @@ import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.NClob;
import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
@@ -452,8 +453,16 @@ public class HiveConnection implements j
public Statement createStatement(int resultSetType, int resultSetConcurrency)
throws SQLException {
- // TODO Auto-generated method stub
- throw new SQLException("Method not supported");
+ if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
+ throw new SQLException("Statement with resultset concurrency " +
+ resultSetConcurrency + " is not supported", "HYC00"); // Optional
feature not implemented
+ }
+ if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) {
+ throw new SQLException("Statement with resultset type " + resultSetType +
+ " is not supported", "HYC00"); // Optional feature not implemented
+ }
+ return new HiveStatement(this, client, sessHandle,
+ resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE);
}
/*
Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java
URL:
http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java
(original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java Thu
Dec 12 20:45:55 2013
@@ -20,6 +20,7 @@ package org.apache.hive.jdbc;
import static
org.apache.hive.service.cli.thrift.TCLIServiceConstants.TYPE_NAMES;
+import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.sql.SQLException;
@@ -66,6 +67,8 @@ public class HiveQueryResultSet extends
private Iterator<TRow> fetchedRowsItr;
private boolean isClosed = false;
private boolean emptyResultSet = false;
+ private boolean isScrollable = false;
+ private boolean fetchFirst = false;
public static class Builder {
@@ -86,6 +89,7 @@ public class HiveQueryResultSet extends
private List<JdbcColumnAttributes> colAttributes;
private int fetchSize = 50;
private boolean emptyResultSet = false;
+ private boolean isScrollable = false;
public Builder(Statement statement) {
this.statement = statement;
@@ -143,6 +147,11 @@ public class HiveQueryResultSet extends
return this;
}
+ public Builder setScrollable(boolean setScrollable) {
+ this.isScrollable = setScrollable;
+ return this;
+ }
+
public HiveQueryResultSet build() throws SQLException {
return new HiveQueryResultSet(this);
}
@@ -168,6 +177,7 @@ public class HiveQueryResultSet extends
} else {
this.maxRows = builder.maxRows;
}
+ this.isScrollable = builder.isScrollable;
}
/**
@@ -286,9 +296,18 @@ public class HiveQueryResultSet extends
}
try {
+ TFetchOrientation orientation = TFetchOrientation.FETCH_NEXT;
+ if (fetchFirst) {
+ // If we are asked to start from begining, clear the current fetched
resultset
+ orientation = TFetchOrientation.FETCH_FIRST;
+ fetchedRows = null;
+ fetchedRowsItr = null;
+ fetchFirst = false;
+ }
+
if (fetchedRows == null || !fetchedRowsItr.hasNext()) {
TFetchResultsReq fetchReq = new TFetchResultsReq(stmtHandle,
- TFetchOrientation.FETCH_NEXT, fetchSize);
+ orientation, fetchSize);
TFetchResultsResp fetchResp = client.FetchResults(fetchReq);
Utils.verifySuccessWithInfo(fetchResp.getStatus());
fetchedRows = fetchResp.getResults().getRows();
@@ -334,6 +353,18 @@ public class HiveQueryResultSet extends
}
@Override
+ public int getType() throws SQLException {
+ if (isClosed) {
+ throw new SQLException("Resultset is closed");
+ }
+ if (isScrollable) {
+ return ResultSet.TYPE_SCROLL_INSENSITIVE;
+ } else {
+ return ResultSet.TYPE_FORWARD_ONLY;
+ }
+ }
+
+ @Override
public int getFetchSize() throws SQLException {
if (isClosed) {
throw new SQLException("Resultset is closed");
@@ -350,4 +381,36 @@ public class HiveQueryResultSet extends
//JDK 1.7
throw new SQLException("Method not supported");
}
+
+ /**
+ * Moves the cursor before the first row of the resultset.
+ *
+ * @see java.sql.ResultSet#next()
+ * @throws SQLException
+ * if a database access error occurs.
+ */
+ @Override
+ public void beforeFirst() throws SQLException {
+ if (isClosed) {
+ throw new SQLException("Resultset is closed");
+ }
+ if (!isScrollable) {
+ throw new SQLException("Method not supported for TYPE_FORWARD_ONLY
resultset");
+ }
+ fetchFirst = true;
+ rowsFetched = 0;
+ }
+
+ @Override
+ public boolean isBeforeFirst() throws SQLException {
+ if (isClosed) {
+ throw new SQLException("Resultset is closed");
+ }
+ return (rowsFetched == 0);
+ }
+
+ @Override
+ public int getRow() throws SQLException {
+ return rowsFetched;
+ }
}
Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
URL:
http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java Thu Dec 12
20:45:55 2013
@@ -48,6 +48,7 @@ public class HiveStatement implements ja
private final TSessionHandle sessHandle;
Map<String,String> sessConf = new HashMap<String,String>();
private int fetchSize = 50;
+ private boolean isScrollableResultset = false;
/**
* We need to keep a reference to the result set to support the following:
* <code>
@@ -79,9 +80,15 @@ public class HiveStatement implements ja
*/
public HiveStatement(HiveConnection connection, TCLIService.Iface client,
TSessionHandle sessHandle) {
+ this(connection, client, sessHandle, false);
+ }
+
+ public HiveStatement(HiveConnection connection, TCLIService.Iface client,
+ TSessionHandle sessHandle, boolean isScrollableResultset) {
this.connection = connection;
this.client = client;
this.sessHandle = sessHandle;
+ this.isScrollableResultset = isScrollableResultset;
}
/*
@@ -249,6 +256,7 @@ public class HiveStatement implements ja
}
resultSet = new
HiveQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle)
.setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize)
+ .setScrollable(isScrollableResultset)
.build();
return true;
}
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Context.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Context.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Context.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Context.java Thu Dec 12
20:45:55 2013
@@ -481,6 +481,13 @@ public class Context {
return null;
}
+ public void resetStream() {
+ if (initialized) {
+ resDirFilesNum = 0;
+ initialized = false;
+ }
+ }
+
/**
* Little abbreviation for StringUtils.
*/
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java Thu Dec 12
20:45:55 2013
@@ -1551,6 +1551,20 @@ public class Driver implements CommandPr
return true;
}
+ public void resetFetch() throws IOException {
+ if (plan != null && plan.getFetchTask() != null) {
+ try {
+ plan.getFetchTask().clearFetch();
+ } catch (Exception e) {
+ throw new IOException("Error closing the current fetch task", e);
+ }
+ plan.getFetchTask().initialize(conf, plan, null);
+ } else {
+ ctx.resetStream();
+ resStream = null;
+ }
+ }
+
public int getTryCount() {
return tryCount;
}
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java Thu
Dec 12 20:45:55 2013
@@ -78,6 +78,7 @@ public class FetchTask extends Task<Fetc
sink = work.getSink();
fetch = new FetchOperator(work, job, source, getVirtualColumns(source));
source.initialize(conf, new
ObjectInspector[]{fetch.getOutputObjectInspector()});
+ totalRows = 0;
} catch (Exception e) {
// Bail out ungracefully - we should never hit
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
(original)
+++
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
Thu Dec 12 20:45:55 2013
@@ -24,6 +24,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FsShell;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Schema;
import org.apache.hadoop.hive.ql.parse.VariableSubstitution;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
@@ -36,11 +38,19 @@ public class DfsProcessor implements Com
public static final Log LOG =
LogFactory.getLog(DfsProcessor.class.getName());
public static final LogHelper console = new LogHelper(LOG);
+ public static final String DFS_RESULT_HEADER = "DFS Output";
private final FsShell dfs;
+ private final Schema dfsSchema;
public DfsProcessor(Configuration conf) {
+ this(conf, false);
+ }
+
+ public DfsProcessor(Configuration conf, boolean addSchema) {
dfs = new FsShell(conf);
+ dfsSchema = new Schema();
+ dfsSchema.addToFieldSchemas(new FieldSchema(DFS_RESULT_HEADER, "string",
""));
}
public void init() {
@@ -66,7 +76,7 @@ public class DfsProcessor implements Com
}
System.setOut(oldOut);
- return new CommandProcessorResponse(ret);
+ return new CommandProcessorResponse(ret, null, null, dfsSchema);
} catch (Exception e) {
console.printError("Exception raised from DFSShell.run "
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java
Thu Dec 12 20:45:55 2013
@@ -18,6 +18,8 @@
package org.apache.hive.service.cli.operation;
+import java.util.EnumSet;
+
import org.apache.hive.service.cli.FetchOrientation;
import org.apache.hive.service.cli.HiveSQLException;
import org.apache.hive.service.cli.OperationState;
@@ -63,6 +65,10 @@ public class GetCatalogsOperation extend
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ rowSet.setStartOffset(0);
+ }
return rowSet.extractSubset((int)maxRows);
}
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetColumnsOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetColumnsOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetColumnsOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetColumnsOperation.java
Thu Dec 12 20:45:55 2013
@@ -20,6 +20,7 @@ package org.apache.hive.service.cli.oper
import java.sql.DatabaseMetaData;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.List;
import java.util.regex.Pattern;
@@ -192,6 +193,10 @@ public class GetColumnsOperation extends
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ rowSet.setStartOffset(0);
+ }
return rowSet.extractSubset((int)maxRows);
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetFunctionsOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetFunctionsOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetFunctionsOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetFunctionsOperation.java
Thu Dec 12 20:45:55 2013
@@ -19,6 +19,7 @@
package org.apache.hive.service.cli.operation;
import java.sql.DatabaseMetaData;
+import java.util.EnumSet;
import java.util.Set;
import org.apache.hadoop.hive.ql.exec.FunctionInfo;
@@ -115,6 +116,10 @@ public class GetFunctionsOperation exten
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ rowSet.setStartOffset(0);
+ }
return rowSet.extractSubset((int)maxRows);
}
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetSchemasOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetSchemasOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetSchemasOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetSchemasOperation.java
Thu Dec 12 20:45:55 2013
@@ -18,6 +18,8 @@
package org.apache.hive.service.cli.operation;
+import java.util.EnumSet;
+
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hive.service.cli.FetchOrientation;
import org.apache.hive.service.cli.HiveSQLException;
@@ -84,6 +86,10 @@ public class GetSchemasOperation extends
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ rowSet.setStartOffset(0);
+ }
return rowSet.extractSubset((int)maxRows);
}
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java
Thu Dec 12 20:45:55 2013
@@ -18,6 +18,7 @@
package org.apache.hive.service.cli.operation;
+import java.util.EnumSet;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hive.service.cli.FetchOrientation;
@@ -82,6 +83,10 @@ public class GetTableTypesOperation exte
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ rowSet.setStartOffset(0);
+ }
return rowSet.extractSubset((int)maxRows);
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTablesOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTablesOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTablesOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTablesOperation.java
Thu Dec 12 20:45:55 2013
@@ -19,6 +19,7 @@
package org.apache.hive.service.cli.operation;
import java.util.ArrayList;
+import java.util.EnumSet;
import java.util.List;
import org.apache.hadoop.hive.conf.HiveConf;
@@ -117,6 +118,10 @@ public class GetTablesOperation extends
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ rowSet.setStartOffset(0);
+ }
return rowSet.extractSubset((int)maxRows);
}
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
Thu Dec 12 20:45:55 2013
@@ -18,6 +18,8 @@
package org.apache.hive.service.cli.operation;
+import java.util.EnumSet;
+
import org.apache.hive.service.cli.FetchOrientation;
import org.apache.hive.service.cli.HiveSQLException;
import org.apache.hive.service.cli.OperationState;
@@ -130,6 +132,10 @@ public class GetTypeInfoOperation extend
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ rowSet.setStartOffset(0);
+ }
return rowSet.extractSubset((int)maxRows);
}
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
Thu Dec 12 20:45:55 2013
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@@ -152,6 +153,10 @@ public class HiveCommandOperation extend
*/
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
+ validateDefaultFetchOrientation(orientation);
+ if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+ resetResultReader();
+ }
List<String> rows = readResults((int) maxRows);
RowSet rowSet = new RowSet();
@@ -178,7 +183,6 @@ public class HiveCommandOperation extend
throw new HiveSQLException(e);
}
}
-
List<String> results = new ArrayList<String>();
for (int i = 0; i < nLines || nLines <= 0; ++i) {
@@ -199,11 +203,15 @@ public class HiveCommandOperation extend
}
private void cleanTmpFile() {
+ resetResultReader();
+ SessionState sessionState = getParentSession().getSessionState();
+ File tmp = sessionState.getTmpOutputFile();
+ tmp.delete();
+ }
+
+ private void resetResultReader() {
if (resultReader != null) {
- SessionState sessionState = getParentSession().getSessionState();
- File tmp = sessionState.getTmpOutputFile();
IOUtils.cleanup(LOG, resultReader);
- tmp.delete();
resultReader = null;
}
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/Operation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/Operation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/Operation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/Operation.java
Thu Dec 12 20:45:55 2013
@@ -17,6 +17,8 @@
*/
package org.apache.hive.service.cli.operation;
+import java.util.EnumSet;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.conf.HiveConf;
@@ -40,6 +42,9 @@ public abstract class Operation {
public static final long DEFAULT_FETCH_MAX_ROWS = 100;
protected boolean hasResultSet;
+ protected static final EnumSet<FetchOrientation>
DEFAULT_FETCH_ORIENTATION_SET =
+ EnumSet.of(FetchOrientation.FETCH_NEXT,FetchOrientation.FETCH_FIRST);
+
protected Operation(HiveSession parentSession, OperationType opType) {
super();
this.parentSession = parentSession;
@@ -124,4 +129,28 @@ public abstract class Operation {
public RowSet getNextRowSet() throws HiveSQLException {
return getNextRowSet(FetchOrientation.FETCH_NEXT, DEFAULT_FETCH_MAX_ROWS);
}
+
+ /**
+ * Verify if the given fetch orientation is part of the default orientation
types.
+ * @param orientation
+ * @throws HiveSQLException
+ */
+ protected void validateDefaultFetchOrientation(FetchOrientation orientation)
+ throws HiveSQLException {
+ validateFetchOrientation(orientation, DEFAULT_FETCH_ORIENTATION_SET);
+ }
+
+ /**
+ * Verify if the given fetch orientation is part of the supported
orientation types.
+ * @param orientation
+ * @param supportedOrientations
+ * @throws HiveSQLException
+ */
+ protected void validateFetchOrientation(FetchOrientation orientation,
+ EnumSet<FetchOrientation> supportedOrientations) throws HiveSQLException
{
+ if (!supportedOrientations.contains(orientation)) {
+ throw new HiveSQLException("The fetch type " + orientation.toString() +
+ " is not supported for this resultset", "HY106");
+ }
+ }
}
Modified:
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
URL:
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java?rev=1550521&r1=1550520&r2=1550521&view=diff
==============================================================================
---
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
(original)
+++
hive/trunk/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
Thu Dec 12 20:45:55 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -68,6 +69,7 @@ public class SQLOperation extends Execut
private SerDe serde = null;
private final boolean runAsync;
private Future<?> backgroundHandle;
+ private boolean fetchStarted = false;
public SQLOperation(HiveSession parentSession, String statement, Map<String,
String> confOverlay, boolean runInBackground) {
@@ -228,10 +230,18 @@ public class SQLOperation extends Execut
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows)
throws HiveSQLException {
assertState(OperationState.FINISHED);
+ validateDefaultFetchOrientation(orientation);
ArrayList<String> rows = new ArrayList<String>();
driver.setMaxRows((int)maxRows);
try {
+ /* if client is requesting fetch-from-start and its not the first time
reading from this operation
+ * then reset the fetch position to beginging
+ */
+ if (orientation.equals(FetchOrientation.FETCH_FIRST) && fetchStarted) {
+ driver.resetFetch();
+ }
+ fetchStarted = true;
driver.getResults(rows);
getSerDe();