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

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

commit eac7ccc26b1090494bd9520ab3171eec984496cf
Author: Arjun Gupta <saimzn4...@gmail.com>
AuthorDate: Tue Jun 25 15:21:19 2019 +0530

    DRILL-7174: Expose complex to Json control in the Drill C++ Client
    
    closes #1814
---
 contrib/native/client/example/querySubmitter.cpp   | 14 ++++--
 .../client/src/clientlib/drillClientImpl.cpp       | 18 +++++++
 .../client/src/clientlib/drillClientImpl.hpp       |  1 +
 contrib/native/client/src/include/drill/common.hpp |  1 +
 contrib/native/client/src/test/CMakeLists.txt      |  2 +
 contrib/native/client/src/test/DrillClientTest.cpp | 55 ++++++++++++++++++++++
 6 files changed, 86 insertions(+), 5 deletions(-)

diff --git a/contrib/native/client/example/querySubmitter.cpp 
b/contrib/native/client/example/querySubmitter.cpp
index a84d1db..1ca7668 100644
--- a/contrib/native/client/example/querySubmitter.cpp
+++ b/contrib/native/client/example/querySubmitter.cpp
@@ -23,13 +23,13 @@
 #include <boost/algorithm/string/join.hpp>
 #include "drill/drillc.hpp"
 
-int nOptions=25;
+int nOptions=27;
 
 struct Option{
     char name[32];
     char desc[128];
     bool required;
-}qsOptions[]= {
+} qsOptions[] = {
     {"plan", "Plan files separated by semicolons", false},
     {"query", "Query strings, separated by semicolons", false},
     {"type", "Query type [physical|logical|sql|server]", true},
@@ -54,9 +54,9 @@ struct Option{
     {"certFilePath", "Path to SSL certificate file", false},
     {"disableHostnameVerification", "disable host name verification", false},
     {"disableCertVerification", "disable certificate verification", false},
-    {"useSystemTrustStore", "[Windows only]. Use the system truststore.", 
false },
-    {"CustomSSLCtxOptions", "The custom SSL CTX Options", false}
-
+    {"useSystemTrustStore", "[Windows only]. Use the system truststore.", 
false},
+    {"CustomSSLCtxOptions", "The custom SSL CTX Options", false},
+    {"supportComplexTypes", "Toggle for supporting complex types", false}
 };
 
 std::map<std::string, std::string> qsOptionValues;
@@ -317,6 +317,7 @@ int main(int argc, char* argv[]) {
         std::string 
disableCertVerification=qsOptionValues["disableCertVerification"];
         std::string useSystemTrustStore = 
qsOptionValues["useSystemTrustStore"];
         std::string customSSLOptions = qsOptionValues["CustomSSLCtxOptions"];
+        std::string supportComplexTypes = 
qsOptionValues["supportComplexTypes"];
 
         Drill::QueryType type;
 
@@ -422,6 +423,9 @@ int main(int argc, char* argv[]) {
                 props.setProperty(USERPROP_CUSTOM_SSLCTXOPTIONS, 
customSSLOptions);
             }
         }
+        if (supportComplexTypes.length() > 0){
+            props.setProperty(USERPROP_SUPPORT_COMPLEX_TYPES, 
supportComplexTypes);
+        }
 
         if(client.connect(connectStr.c_str(), &props)!=Drill::CONN_SUCCESS){
             std::cerr<< "Failed to connect with error: "<< client.getError() 
<< " (Using:"<<connectStr<<")"<<std::endl;
diff --git a/contrib/native/client/src/clientlib/drillClientImpl.cpp 
b/contrib/native/client/src/clientlib/drillClientImpl.cpp
index fe2cb3a..24f9037 100644
--- a/contrib/native/client/src/clientlib/drillClientImpl.cpp
+++ b/contrib/native/client/src/clientlib/drillClientImpl.cpp
@@ -537,6 +537,23 @@ bool DrillClientImpl::clientNeedsAuthentication(const 
DrillUserProperties* userP
     return needsAuthentication;
 }
 
+/*
+* Check's if client has explicitly expressed interest in supporting complex 
types. It looks for USERPROP_SUPPORT_COMPLEX_TYPES
+* connection string property. If set to true then returns true else returns 
false
+*/
+bool DrillClientImpl::handleComplexTypes(const DrillUserProperties* 
userProperties) {
+    bool support_complex_types = false;
+    // check if userProperties is null
+    if (!userProperties) {
+        return support_complex_types;
+    }
+
+    std::string val;
+    support_complex_types = 
userProperties->isPropSet(USERPROP_SUPPORT_COMPLEX_TYPES) &&
+        boost::iequals(userProperties->getProp(USERPROP_SUPPORT_COMPLEX_TYPES, 
val), "true");
+    return support_complex_types;
+}
+
 connectionStatus_t DrillClientImpl::validateHandshake(DrillUserProperties* 
properties){
 
     DRILL_MT_LOG(DRILL_LOG(LOG_TRACE) << "validateHandShake\n";)
@@ -547,6 +564,7 @@ connectionStatus_t 
DrillClientImpl::validateHandshake(DrillUserProperties* prope
     u2b.set_support_listening(true);
     u2b.set_support_timeout(DrillClientConfig::getHeartbeatFrequency() > 0);
     u2b.set_sasl_support(exec::user::SASL_PRIVACY);
+    u2b.set_support_complex_types(handleComplexTypes(properties));
 
     // Adding version info
     exec::user::RpcEndpointInfos* infos = u2b.mutable_client_infos();
diff --git a/contrib/native/client/src/clientlib/drillClientImpl.hpp 
b/contrib/native/client/src/clientlib/drillClientImpl.hpp
index d6531b2..08f35d3 100644
--- a/contrib/native/client/src/clientlib/drillClientImpl.hpp
+++ b/contrib/native/client/src/clientlib/drillClientImpl.hpp
@@ -473,6 +473,7 @@ class DrillClientImpl : public DrillClientImplBase{
 
         static bool clientNeedsAuthentication(const DrillUserProperties* 
userProperties);
 
+        bool handleComplexTypes(const DrillUserProperties* userProperties);
 
     private:
         friend class meta::DrillMetadata;
diff --git a/contrib/native/client/src/include/drill/common.hpp 
b/contrib/native/client/src/include/drill/common.hpp
index 1324601..9f57446 100644
--- a/contrib/native/client/src/include/drill/common.hpp
+++ b/contrib/native/client/src/include/drill/common.hpp
@@ -186,6 +186,7 @@ typedef enum{
 #define USERPROP_SERVICE_NAME "service_name"
 #define USERPROP_SERVICE_HOST "service_host"
 #define USERPROP_SASL_ENCRYPT "sasl_encrypt"
+#define USERPROP_SUPPORT_COMPLEX_TYPES "support_complex_types"
 
 // Bitflags to describe user properties
 // Used in DrillUserProperties::USER_PROPERTIES
diff --git a/contrib/native/client/src/test/CMakeLists.txt 
b/contrib/native/client/src/test/CMakeLists.txt
index 523734b..1fcc1f7 100644
--- a/contrib/native/client/src/test/CMakeLists.txt
+++ b/contrib/native/client/src/test/CMakeLists.txt
@@ -20,6 +20,7 @@
 set (TESTS_SRC_FILES
     ${CMAKE_CURRENT_SOURCE_DIR}/CollectionsTest.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/UtilsTest.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/DrillClientTest.cpp
     )
 
 find_package(CppUnit REQUIRED)
@@ -29,6 +30,7 @@ include_directories(${CPPUNIT_INCLUDE_DIR})
 include_directories(${Boost_INCLUDE_DIRS})
 include_directories(${PROTOBUF_INCLUDE_DIR})
 include_directories(${Zookeeper_INCLUDE_DIRS})
+include_directories(${OPENSSL_INCLUDE_DIR})
 
 link_directories(/usr/local/lib)
 add_executable(unit-tests ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp 
${TESTS_SRC_FILES} )
diff --git a/contrib/native/client/src/test/DrillClientTest.cpp 
b/contrib/native/client/src/test/DrillClientTest.cpp
new file mode 100644
index 0000000..cebba0b
--- /dev/null
+++ b/contrib/native/client/src/test/DrillClientTest.cpp
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "drill/userProperties.hpp"
+#include "drillClientImpl.hpp"
+
+
+class DrillClientTest : public CppUnit::TestFixture {
+public:
+    DrillClientTest() {}
+
+    CPPUNIT_TEST_SUITE(DrillClientTest);
+    CPPUNIT_TEST(testHandleComplexTypes);
+    CPPUNIT_TEST_SUITE_END();
+
+    void testHandleComplexTypes() {
+        Drill::DrillClientImpl DCI;
+        Drill::DrillUserProperties properties1, properties2, properties3;
+        bool supportComplexTypes;
+
+        // Check when property is set to true
+        properties1.setProperty(USERPROP_SUPPORT_COMPLEX_TYPES, "true");
+        supportComplexTypes = DCI.handleComplexTypes(&properties1);
+        CPPUNIT_ASSERT(supportComplexTypes == true);
+
+        // Check when property is set to false
+        properties2.setProperty(USERPROP_SUPPORT_COMPLEX_TYPES, "false");
+        supportComplexTypes = DCI.handleComplexTypes(&properties2);
+        CPPUNIT_ASSERT(supportComplexTypes == false);
+
+        // Check the default value
+        supportComplexTypes = DCI.handleComplexTypes(&properties3);
+        CPPUNIT_ASSERT(supportComplexTypes == false);
+    }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DrillClientTest);
+

Reply via email to