This is an automated email from the ASF dual-hosted git repository. michaelsmith pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/impala.git
commit d12c05d5da36fb124869e360fc29392dfd03a064 Author: Xiang Yang <[email protected]> AuthorDate: Mon Mar 13 11:36:32 2023 +0000 IMPALA-11992: Support setting query options in Hive JDBC's connection URL Hive JDBC support setting hive configurations in Connection URL's query part, thus we can map impala's query options to hive configurations to support setting query options on the hive JDBC client side. But hive JDBC will add a "set:hiveconf:" prefix to the configuration key when request OpenSession() thrift API, we should remove the configuration key prefix in OpenSession() so that we can set valid query options. Testing: - update the 'TestHS2::test_open_session_query_options' EE test. - add a FE test 'testSetQueryOptionsInConnectionURL' to JdbcTest. Change-Id: Ie184a0c2404f36a3ee28296336f6545615a5c6ca Reviewed-on: http://gerrit.cloudera.org:8080/19612 Reviewed-by: Impala Public Jenkins <[email protected]> Tested-by: Impala Public Jenkins <[email protected]> --- be/src/service/impala-hs2-server.cc | 13 +++++++++-- .../java/org/apache/impala/service/JdbcTest.java | 25 ++++++++++++++++++++++ .../apache/impala/testutil/ImpalaJdbcClient.java | 2 +- tests/hs2/test_hs2.py | 6 ++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/be/src/service/impala-hs2-server.cc b/be/src/service/impala-hs2-server.cc index e0164e862..e2c01ac2e 100644 --- a/be/src/service/impala-hs2-server.cc +++ b/be/src/service/impala-hs2-server.cc @@ -103,6 +103,10 @@ namespace impala { const string IMPALA_RESULT_CACHING_OPT = "impala.resultset.cache.size"; +const string SET_HIVECONF_PREFIX = "set:hiveconf:"; + +const int SET_HIVECONF_PREFIX_LEN = SET_HIVECONF_PREFIX.length(); + void ImpalaServer::ExecuteMetadataOp(const THandleIdentifier& session_handle, TMetadataOpRequest* request, TOperationHandle* handle, thrift::TStatus* status) { TUniqueId session_id; @@ -361,11 +365,16 @@ void ImpalaServer::OpenSession(TOpenSessionResp& return_val, } else if (iequals(v.first, "use:database")) { state->database = v.second; } else { + string key = v.first, value = v.second; + // Hive JDBC will add a prefix to the configuration, see IMPALA-11992 + if (key.rfind(SET_HIVECONF_PREFIX, 0) != string::npos) { + key = key.substr(SET_HIVECONF_PREFIX_LEN); + } // Normal configuration key. Use it to set session default query options. // Ignore failure (failures will be logged in SetQueryOption()). - Status status = SetQueryOption(v.first, v.second, &state->set_query_options, + Status status = SetQueryOption(key, value, &state->set_query_options, &state->set_query_options_mask); - if (status.ok() && iequals(v.first, "idle_session_timeout")) { + if (status.ok() && iequals(key, "idle_session_timeout")) { state->session_timeout = state->set_query_options.idle_session_timeout; VLOG_QUERY << "OpenSession(): session: " << PrintId(session_id) << " idle_session_timeout=" diff --git a/fe/src/test/java/org/apache/impala/service/JdbcTest.java b/fe/src/test/java/org/apache/impala/service/JdbcTest.java index 344ce1edc..43086caec 100644 --- a/fe/src/test/java/org/apache/impala/service/JdbcTest.java +++ b/fe/src/test/java/org/apache/impala/service/JdbcTest.java @@ -27,6 +27,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Types; import java.util.ArrayList; import java.util.Arrays; @@ -693,4 +694,28 @@ public class JdbcTest extends JdbcTestBase { assertNull("Connection is not null", connection); } } + + /** + * test the query options in connection URL take effect. + */ + @Test + public void testSetQueryOptionsInConnectionURL() throws Exception { + String divideZeroSQL = "SELECT CAST(1 AS DECIMAL)/0"; + String connStr = ImpalaJdbcClient.getNoAuthConnectionStr(connectionType_); + connStr += "?DECIMAL_V2=false"; + try (Connection connection = createConnection(connStr)) { + Statement stmt = connection.createStatement(); + try (ResultSet rs = stmt.executeQuery(divideZeroSQL);) { + // DECIMAL_V2=false, no exception is expected to be thrown + rs.next(); + } + stmt.execute("SET DECIMAL_V2=true"); + try (ResultSet rs = stmt.executeQuery(divideZeroSQL);) { + // DECIMAL_V2=true, an exception is expected to be thrown + rs.next(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("UDF ERROR: Cannot divide decimal by zero")); + } + } + } } diff --git a/fe/src/test/java/org/apache/impala/testutil/ImpalaJdbcClient.java b/fe/src/test/java/org/apache/impala/testutil/ImpalaJdbcClient.java index 6f4ffe2a1..6a29d68f2 100644 --- a/fe/src/test/java/org/apache/impala/testutil/ImpalaJdbcClient.java +++ b/fe/src/test/java/org/apache/impala/testutil/ImpalaJdbcClient.java @@ -41,7 +41,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; /** - * Basic tool for executing queries and and displaying results using Impala + * Basic tool for executing queries and displaying results using Impala * over JDBC. */ public class ImpalaJdbcClient { diff --git a/tests/hs2/test_hs2.py b/tests/hs2/test_hs2.py index 70191f032..270c6d0da 100644 --- a/tests/hs2/test_hs2.py +++ b/tests/hs2/test_hs2.py @@ -78,6 +78,12 @@ class TestHS2(HS2TestSuite): TestHS2.check_response(session) for k, v in configuration.items(): assert session.configuration[k] == v + # simulate hive jdbc's action, see IMPALA-11992 + hiveconfs = dict([("set:hiveconf:" + k, v) for k, v in configuration.items()]) + with ScopedSession(self.hs2_client, configuration=hiveconfs) as sessions: + TestHS2.check_response(sessions) + for k, v in configuration.items(): + assert sessions.configuration[k] == v def get_session_options(self, setCmd): """Returns dictionary of query options."""
