diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index d62e527..5254a33 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -4157,6 +4157,7 @@ private static String getSQLStdAuthDefaultWhiteListPattern() { * sql standard authorization enabled */ static final String [] sqlStdAuthSafeVarNameRegexes = new String [] { + "fetchSize", "hive\\.auto\\..*", "hive\\.cbo\\..*", "hive\\.convert\\..*", diff --git jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java index d6cf744..ea40cad 100644 --- jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -637,6 +637,8 @@ private void openSession() throws SQLException { } // switch the database openConf.put("use:database", connParams.getDbName()); + // set the fetchSize + openConf.put("set:fetchSize", Integer.toString(fetchSize)); // set the session configuration Map sessVars = connParams.getSessionVars(); diff --git serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftJDBCBinarySerDe.java serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftJDBCBinarySerDe.java index 84ed6ba..2566dfe 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftJDBCBinarySerDe.java +++ serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftJDBCBinarySerDe.java @@ -71,7 +71,8 @@ @Override public void initialize(Configuration conf, Properties tbl) throws SerDeException { // Get column names - MAX_BUFFERED_ROWS = HiveConf.getIntVar(conf, HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_MAX_FETCH_SIZE); + MAX_BUFFERED_ROWS = + HiveConf.getIntVar(conf, HiveConf.ConfVars.HIVE_SERVER2_RESULTSET_DEFAULT_FETCH_SIZE); String columnNameProperty = tbl.getProperty(serdeConstants.LIST_COLUMNS); String columnTypeProperty = tbl.getProperty(serdeConstants.LIST_COLUMN_TYPES); final String columnNameDelimiter = tbl.containsKey(serdeConstants.COLUMN_NAME_DELIMITER) ? tbl diff --git service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java index 2938338..ea7459a 100644 --- service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java +++ service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java @@ -309,6 +309,19 @@ public TOpenSessionResp OpenSession(TOpenSessionReq req) throws TException { LOG.info("Client protocol version: " + req.getClient_protocol()); TOpenSessionResp resp = new TOpenSessionResp(); try { + Map openConf = req.getConfiguration(); + + // Set fetch size in hive conf + int maxFetchSize = + hiveConf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_MAX_FETCH_SIZE); + String confFetchSize = openConf != null ? openConf.get("set:fetchSize") : null; + if (confFetchSize != null && !confFetchSize.isEmpty()) { + int fetchSize = Integer.parseInt(confFetchSize); + hiveConf.setIntVar( + HiveConf.ConfVars.HIVE_SERVER2_RESULTSET_DEFAULT_FETCH_SIZE, + fetchSize > maxFetchSize ? maxFetchSize : fetchSize); + } + SessionHandle sessionHandle = getSessionHandle(req, resp); resp.setSessionHandle(sessionHandle.toTSessionHandle()); // TODO: set real configuration map diff --git service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java index abb1ecf..4293d6b 100644 --- service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java +++ service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java @@ -133,6 +133,23 @@ public void testOpenSession() throws Exception { } @Test + public void testFetchSize() throws Exception { + Map configuration = new HashMap(); + configuration.put("set:fetchSize", "50"); + // Open a new client session + SessionHandle sessHandle = client.openSession(USERNAME, + PASSWORD, configuration); + // Session handle should not be null + assertNotNull("Session handle should not be null", sessHandle); + // Fetch Size should be set correctly on the server + assertEquals(50, + hiveServer2.getHiveConf() + .getIntVar(HiveConf.ConfVars.HIVE_SERVER2_RESULTSET_DEFAULT_FETCH_SIZE)); + // Close client session + client.closeSession(sessHandle); + } + + @Test public void testGetFunctions() throws Exception { SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap());