HyukjinKwon commented on a change in pull request #25228: 
[SPARK-28472][SQL][TEST][test-hadoop3.2] Add test for thriftserver protocol 
versions
URL: https://github.com/apache/spark/pull/25228#discussion_r306093552
 
 

 ##########
 File path: 
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkThriftServerProtocolVersionsSuite.scala
 ##########
 @@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.sql.hive.thriftserver
+
+import java.nio.charset.StandardCharsets
+import java.sql.{Date, Timestamp}
+import java.util.Properties
+
+import org.apache.hive.jdbc.{HiveConnection, HiveQueryResultSet}
+import org.apache.hive.service.auth.PlainSaslHelper
+import org.apache.thrift.protocol.TBinaryProtocol
+import org.apache.thrift.transport.TSocket
+
+class SparkThriftServerProtocolVersionsSuite extends HiveThriftServer2Test {
+
+  override def mode: ServerMode.Value = ServerMode.binary
+
+  def testWithProtocolVersion(
+      version: ThriftserverShimUtils.TProtocolVersion,
+      sql: String)(f: HiveQueryResultSet => Unit): Unit = {
+    val rawTransport = new TSocket("localhost", serverPort)
+    val connection = new HiveConnection(s"jdbc:hive2://localhost:$serverPort", 
new Properties)
+    val user = System.getProperty("user.name")
+    val transport = PlainSaslHelper.getPlainTransport(user, "anonymous", 
rawTransport)
+    val client = new ThriftserverShimUtils.Client(new 
TBinaryProtocol(transport))
+    transport.open()
+    var rs: HiveQueryResultSet = null
+    try {
+      val clientProtocol = new ThriftserverShimUtils.TOpenSessionReq(version)
+      val openResp = client.OpenSession(clientProtocol)
+      val sessHandle = openResp.getSessionHandle
+      val execReq = new ThriftserverShimUtils.TExecuteStatementReq(sessHandle, 
sql)
+      val execResp = client.ExecuteStatement(execReq)
+      val stmtHandle = execResp.getOperationHandle
+
+      // Set the HiveConnection protocol to our testing protocol version.
+      // RowSetFactory uses this protocol version to construct different 
RowSet.
+      val protocol = connection.getClass.getDeclaredField("protocol")
+      protocol.setAccessible(true)
+      protocol.set(connection, version)
+
+      rs = new HiveQueryResultSet.Builder(connection)
+        .setClient(client)
+        .setSessionHandle(sessHandle)
+        
.setStmtHandle(stmtHandle).setMaxRows(Int.MaxValue).setFetchSize(Int.MaxValue)
+        .build()
+      f(rs)
+    } finally {
+      rs.close()
+      connection.close()
+      transport.close()
+      rawTransport.close()
+    }
+  }
+
+  ThriftserverShimUtils.testedProtocalVersions.foreach { version =>
+    test(s"$version get byte value") {
+      testWithProtocolVersion(version, "SELECT cast(1 as byte)") { rs =>
+        assert(rs.next())
+        assert(rs.getByte(1) === 1.toByte)
+      }
+    }
+
+    test(s"$version get short value") {
+      testWithProtocolVersion(version, "SELECT cast(1 as short)") { rs =>
+        assert(rs.next())
+        assert(rs.getShort(1) === 1.toShort)
+      }
+    }
+
+    test(s"$version get int value") {
+      testWithProtocolVersion(version, "SELECT 1") { rs =>
+        assert(rs.next())
+        assert(rs.getInt(1) === 1)
+      }
+    }
+
+    test(s"$version get bigint value") {
+      testWithProtocolVersion(version, "SELECT cast(1 as bigint)") { rs =>
+        assert(rs.next())
+        assert(rs.getLong(1) === 1L)
+      }
+    }
+
+    test(s"$version get float value") {
+      testWithProtocolVersion(version, "SELECT cast(1.2 as float)") { rs =>
+        assert(rs.next())
+        assert(rs.getFloat(1) === 1.2F)
+      }
+    }
+
+    test(s"$version get double value") {
+      testWithProtocolVersion(version, "SELECT cast(1.2 as double)") { rs =>
+        assert(rs.next())
+        assert(rs.getDouble(1) === 1.2D)
+      }
+    }
+
+    // TODO: active this test case after SPARK-28463 and SPARK-26969
+    // test(s"$version get decimal value") {
 
 Review comment:
   @wangyum, we can use `ignore`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to