You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2021/04/22 05:34:18 UTC

[impala] 01/02: IMPALA-10655: Add ImpalaServer interface to Initialize TQueryCtx for external frontends

This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit dfc1b549687bf78226af8701bd67325b88c4ff69
Author: Kurt Deschler <kd...@cloudera.com>
AuthorDate: Tue Apr 6 22:12:30 2021 -0500

    IMPALA-10655: Add ImpalaServer interface to Initialize TQueryCtx for external frontends
    
    This patch adds a new interface that returns an initialized TQueryCtx
    for use in requests submitted by external frontends. This is necessary
    to ensure that the query context in an externally generated TExecRequest
    has appropriate coordinator metadata.
    
    Testing: External frontend regression tests
    
    Change-Id: I59cebcf087e703a4ab49fb44f6f5ba1044f26546
    Reviewed-by: Aman Sinha <am...@cloudera.com>
    Reviewed-on: http://gerrit.cloudera.org:8080/17312
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/rpc/hs2-http-test.cc         |  3 ++-
 be/src/service/impala-hs2-server.cc | 12 ++++++++++++
 be/src/service/impala-server.h      |  3 +++
 common/thrift/ImpalaService.thrift  | 11 +++++++++++
 tests/hs2/test_hs2.py               |  6 ++++++
 5 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/be/src/rpc/hs2-http-test.cc b/be/src/rpc/hs2-http-test.cc
index 5dde309..c6f3051 100644
--- a/be/src/rpc/hs2-http-test.cc
+++ b/be/src/rpc/hs2-http-test.cc
@@ -50,7 +50,8 @@ class TestHS2Service : public ImpalaHiveServer2ServiceIf {
       TExecuteStatementResp& _return, const TExecuteStatementReq& req) {}
   virtual void ExecutePlannedStatement(
       TExecuteStatementResp& _return, const TExecutePlannedStatementReq& req) {}
-  virtual void GetBackendConfig(TGetBackendConfigResp& _return,
+  virtual void InitQueryContext(TInitQueryContextResp& return_val) {}
+  virtual void GetBackendConfig(TGetBackendConfigResp& return_val,
       const TGetBackendConfigReq& req) {}
   virtual void GetExecutorMembership(
       TGetExecutorMembershipResp& _return, const TGetExecutorMembershipReq& req) {}
diff --git a/be/src/service/impala-hs2-server.cc b/be/src/service/impala-hs2-server.cc
index ef3d0a1..84aee0b 100644
--- a/be/src/service/impala-hs2-server.cc
+++ b/be/src/service/impala-hs2-server.cc
@@ -569,6 +569,18 @@ void ImpalaServer::ExecutePlannedStatement(
   ExecuteStatementCommon(return_val, request.statementReq, &request.plan);
 }
 
+void ImpalaServer::InitQueryContext(
+      TInitQueryContextResp& return_val) {
+  VLOG_QUERY << "InitQueryContext(()";
+  const ThriftServer::ConnectionContext* connection_context =
+      ThriftServer::GetThreadConnectionContext();
+  if (connection_context->server_name != EXTERNAL_FRONTEND_SERVER_NAME) {
+    HS2_RETURN_ERROR(return_val, "Unsupported operation",
+        SQLSTATE_OPTIONAL_FEATURE_NOT_IMPLEMENTED);
+  }
+  PrepareQueryContext(&return_val.query_ctx);
+}
+
 
 void ImpalaServer::GetTypeInfo(TGetTypeInfoResp& return_val,
     const TGetTypeInfoReq& request) {
diff --git a/be/src/service/impala-server.h b/be/src/service/impala-server.h
index 4b74d4b..70ab832 100644
--- a/be/src/service/impala-server.h
+++ b/be/src/service/impala-server.h
@@ -348,6 +348,9 @@ class ImpalaServer : public ImpalaServiceIf,
   virtual void PingImpalaHS2Service(TPingImpalaHS2ServiceResp& return_val,
       const TPingImpalaHS2ServiceReq& req);
 
+  // Initialize a query context for external frontend
+  virtual void InitQueryContext(TInitQueryContextResp& return_val);
+
   // Execute the provided Thrift statement/plan
   virtual void ExecutePlannedStatement(
       apache::hive::service::cli::thrift::TExecuteStatementResp& return_val,
diff --git a/common/thrift/ImpalaService.thrift b/common/thrift/ImpalaService.thrift
index c8c10e3..e998c46 100644
--- a/common/thrift/ImpalaService.thrift
+++ b/common/thrift/ImpalaService.thrift
@@ -26,6 +26,7 @@ include "TCLIService.thrift"
 include "RuntimeProfile.thrift"
 include "Frontend.thrift"
 include "BackendGflags.thrift"
+include "Query.thrift"
 
 // ImpalaService accepts query execution options through beeswax.Query.configuration in
 // key:value form. For example, the list of strings could be:
@@ -850,6 +851,12 @@ struct TGetExecutorMembershipResp {
   2: required Frontend.TUpdateExecutorMembershipRequest executor_membership
 }
 
+struct TInitQueryContextResp {
+  1: required TCLIService.TStatus status
+
+  2: required Query.TQueryCtx query_ctx
+}
+
 service ImpalaHiveServer2Service extends TCLIService.TCLIService {
   // Returns the exec summary for the given query. The exec summary is only valid for
   // queries that execute with Impala's backend, i.e. QUERY, DML and COMPUTE_STATS
@@ -866,6 +873,10 @@ service ImpalaHiveServer2Service extends TCLIService.TCLIService {
 
   // Same as HS2 CloseOperation but can return additional information.
   TCloseImpalaOperationResp CloseImpalaOperation(1:TCloseImpalaOperationReq req);
+
+  // Returns an initialized TQueryCtx. Only supported for the "external fe" service.
+  TInitQueryContextResp InitQueryContext();
+
   // Execute statement with supplied ExecRequest
   TCLIService.TExecuteStatementResp ExecutePlannedStatement(
       1:TExecutePlannedStatementReq req);
diff --git a/tests/hs2/test_hs2.py b/tests/hs2/test_hs2.py
index 4bdf449..6b15bb3 100644
--- a/tests/hs2/test_hs2.py
+++ b/tests/hs2/test_hs2.py
@@ -749,6 +749,12 @@ class TestHS2(HS2TestSuite):
         TCLIService.TStatusCode.ERROR_STATUS, "Unsupported operation")
 
   @needs_session()
+  def test_init_query_context(self):
+    init_query_context_resp = self.hs2_client.InitQueryContext()
+    TestHS2.check_response(init_query_context_resp,
+        TCLIService.TStatusCode.ERROR_STATUS, "Unsupported operation")
+
+  @needs_session()
   def test_get_profile(self):
     statement = "SELECT COUNT(2) FROM functional.alltypes"
     execute_statement_resp = self.execute_statement(statement)