diff --git beeline/src/java/org/apache/hive/beeline/BeeLine.java beeline/src/java/org/apache/hive/beeline/BeeLine.java index dc79712054..9d5593b26d 100644 --- beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -175,6 +175,7 @@ private static final String HIVE_CONF_PREFIX = "--hiveconf"; private static final String PROP_FILE_PREFIX = "--property-file"; public static final String PASSWD_MASK = "[passwd stripped]"; + public int fetchSize = -1; private final Map formats = map(new Object[] { "vertical", new VerticalOutputFormat(this), @@ -434,6 +435,11 @@ static Manifest getManifest() throws IOException { return null; } + public void setFetchSize(int fetchRows) { + if (fetchRows > 0) { + this.fetchSize = fetchRows; + } + } String getManifestAttribute(String name) { try { @@ -2341,12 +2347,16 @@ int print(ResultSet rs) throws SQLException { Statement createStatement() throws SQLException { Statement stmnt = getDatabaseConnection().getConnection().createStatement(); + if (getOpts().timeout > -1) { stmnt.setQueryTimeout(getOpts().timeout); } if (signalHandler != null) { signalHandler.setStatement(stmnt); } + if (fetchSize > -1) { + stmnt.setFetchSize(fetchSize); + } return stmnt; } diff --git beeline/src/java/org/apache/hive/beeline/Commands.java beeline/src/java/org/apache/hive/beeline/Commands.java index 8f47323700..4666a13c2b 100644 --- beeline/src/java/org/apache/hive/beeline/Commands.java +++ beeline/src/java/org/apache/hive/beeline/Commands.java @@ -1051,6 +1051,14 @@ private boolean executeInternal(String sql, boolean call) { true, beeLine.getErrorStream()); } } + // anytime this property is set, reset the local value so it can be set on new Statement + if (sql.toLowerCase().startsWith("set hive.server2.thrift.resultset.default.fetch.size=")) { + try { + beeLine.setFetchSize(Integer.parseInt((sql.split("=")[1]))); + } catch (NumberFormatException nfe) { + // ignore + } + } } finally { if (logThread != null) { if (!logThread.isInterrupted()) { diff --git jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java index cb0b0d1c92..9c3de4d75b 100644 --- jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -835,9 +835,6 @@ private void openSession() throws SQLException { } // switch the database openConf.put("use:database", connParams.getDbName()); - // set the fetchSize - openConf.put("set:hiveconf:hive.server2.thrift.resultset.default.fetch.size", - Integer.toString(fetchSize)); if (wmPool != null) { openConf.put("set:hivevar:wmpool", wmPool); }