DRILL-1137: C++ Client. Support setting default schema in the connection phase.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/323084b0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/323084b0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/323084b0 Branch: refs/heads/master Commit: 323084b0b9ff53d9f0737748dc920ad9ca4611d0 Parents: 4418864 Author: Xiao Meng <[email protected]> Authored: Fri Jul 11 16:26:16 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Mon Aug 11 21:32:22 2014 -0700 ---------------------------------------------------------------------- .../native/client/example/querySubmitter.cpp | 4 ++- .../native/client/src/clientlib/drillClient.cpp | 4 +-- .../client/src/clientlib/drillClientImpl.cpp | 13 +++++++- .../client/src/clientlib/drillClientImpl.hpp | 4 +-- .../client/src/include/drill/drillClient.hpp | 31 ++++++++++++++++++-- 5 files changed, 48 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/323084b0/contrib/native/client/example/querySubmitter.cpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/example/querySubmitter.cpp b/contrib/native/client/example/querySubmitter.cpp index 9d24e68..8e80658 100644 --- a/contrib/native/client/example/querySubmitter.cpp +++ b/contrib/native/client/example/querySubmitter.cpp @@ -104,6 +104,7 @@ struct Option{ {"query", "Query strings, separated by semicolons", false}, {"type", "Query type [physical|logical|sql]", true}, {"connectStr", "Connect string", true}, + {"schema", "Default schema", false}, {"api", "API type [sync|async]", true}, {"logLevel", "Logging level [trace|debug|info|warn|error|fatal]", false} }; @@ -236,6 +237,7 @@ int main(int argc, char* argv[]) { std::vector<std::string*> queries; std::string connectStr=qsOptionValues["connectStr"]; + std::string schema=qsOptionValues["schema"]; std::string queryList=qsOptionValues["query"]; std::string planList=qsOptionValues["plan"]; std::string api=qsOptionValues["api"]; @@ -279,7 +281,7 @@ int main(int argc, char* argv[]) { // To log to stderr Drill::DrillClient::initLogging(NULL, l); - if(client.connect(connectStr.c_str())!=Drill::CONN_SUCCESS){ + if(client.connect(connectStr.c_str(), schema.c_str())!=Drill::CONN_SUCCESS){ std::cerr<< "Failed to connect with error: "<< client.getError() << " (Using:"<<connectStr<<")"<<std::endl; return -1; } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/323084b0/contrib/native/client/src/clientlib/drillClient.cpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/src/clientlib/drillClient.cpp b/contrib/native/client/src/clientlib/drillClient.cpp index 10480b4..a7489bc 100644 --- a/contrib/native/client/src/clientlib/drillClient.cpp +++ b/contrib/native/client/src/clientlib/drillClient.cpp @@ -256,12 +256,12 @@ DrillClient::~DrillClient(){ delete this->m_pImpl; } -connectionStatus_t DrillClient::connect(const char* connectStr ){ +connectionStatus_t DrillClient::connect(const char* connectStr, const char* defaultSchema){ connectionStatus_t ret=CONN_SUCCESS; ret=this->m_pImpl->connect(connectStr); if(ret==CONN_SUCCESS) - ret=this->m_pImpl->validateHandShake()?CONN_SUCCESS:CONN_HANDSHAKE_FAILED; + ret=this->m_pImpl->validateHandShake(defaultSchema)?CONN_SUCCESS:CONN_HANDSHAKE_FAILED; return ret; } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/323084b0/contrib/native/client/src/clientlib/drillClientImpl.cpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/src/clientlib/drillClientImpl.cpp b/contrib/native/client/src/clientlib/drillClientImpl.cpp index 6a29d88..54dcdd0 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.cpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.cpp @@ -237,11 +237,22 @@ void DrillClientImpl::handleHShakeReadTimeout(const boost::system::error_code & return; } -bool DrillClientImpl::validateHandShake(){ +bool DrillClientImpl::validateHandShake(const char* defaultSchema){ + + DRILL_LOG(LOG_TRACE) << "validateHandShake\n"; + exec::user::UserToBitHandshake u2b; u2b.set_channel(exec::shared::USER); u2b.set_rpc_version(DRILL_RPC_VERSION); u2b.set_support_listening(true); + + if ( defaultSchema != NULL ){ + DRILL_LOG(LOG_TRACE) << "defaultSchema = " << defaultSchema << "\n"; + exec::user::UserProperties* userProperties = u2b.mutable_properties(); + exec::user::Property* connSchema = userProperties->add_properties(); + connSchema->set_key("schema"); + connSchema->set_value(defaultSchema); + } { boost::lock_guard<boost::mutex> lock(this->m_dcMutex); uint64_t coordId = this->getNextCoordinationId(); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/323084b0/contrib/native/client/src/clientlib/drillClientImpl.hpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/src/clientlib/drillClientImpl.hpp b/contrib/native/client/src/clientlib/drillClientImpl.hpp index 2bf7b5c..e40b214 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.hpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.hpp @@ -159,7 +159,7 @@ class DrillClientQueryResult{ exec::shared::QueryId* m_pQueryId; - //Schema change listener + // Schema change listener pfnSchemaListener m_pSchemaListener; // Results callback pfnQueryResultsListener m_pResultsListener; @@ -219,7 +219,7 @@ class DrillClientImpl{ DrillClientError* getError(){ return m_pError;} DrillClientQueryResult* SubmitQuery(::exec::shared::QueryType t, const std::string& plan, pfnQueryResultsListener listener, void* listenerCtx); void waitForResults(); - bool validateHandShake(); + bool validateHandShake(const char* defaultSchema); private: friend class DrillClientQueryResult; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/323084b0/contrib/native/client/src/include/drill/drillClient.hpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/src/include/drill/drillClient.hpp b/contrib/native/client/src/include/drill/drillClient.hpp index 6d59afb..d03f88d 100644 --- a/contrib/native/client/src/include/drill/drillClient.hpp +++ b/contrib/native/client/src/include/drill/drillClient.hpp @@ -185,8 +185,35 @@ class DECLSPEC_DRILL_CLIENT DrillClient{ // change the logging level static void initLogging(const char* path, logLevel_t l); - /* connects the client to a Drillbit UserServer. */ - connectionStatus_t connect(const char* connectStr); + /** + * Connect the client to a Drillbit using connection string and default schema. + * + * The connection string format can be found in comments of + * [DRILL-780](https://issues.apache.org/jira/browse/DRILL-780) + * + * To connect via zookeeper, use the format: + * "zk=zk1:port[,zk2:p2,...][/<path_to_drill_root>/<cluster_id>]". + * + * e.g. + * ``` + * zk=localhost:2181 + * zk=localhost:2181/drill/drillbits1 + * zk=localhost:2181,zk2:2181/drill/drillbits1 + * ``` + * + * To connect directly to a drillbit, use the format "local=host:port". + * + * e.g. + * ``` + * local=127.0.0.1:31010 + * ``` + * + * @param[in] connectStr: connection string + * @param[in] defaultSchema: default schema (set to NULL and ignore it + * if not specified) + * @return connection status + */ + connectionStatus_t connect(const char* connectStr, const char* defaultSchema=NULL); /* test whether the client is active */ bool isActive();
