[SPARK-31831][SQL][FOLLOWUP] Make the GetCatalogsOperationMock for HiveSessionImplSuite compile with the proper Hive version

### What changes were proposed in this pull request?
#29129 duplicated GetCatalogsOperationMock in the hive-version-specific subdirectories, otherwise profile hive-1.2 would not compile. We can prevent duplication of this class by shimming the required hive-version-specific types.

### Why are the changes needed?
This is a cleanup to avoid duplication of a mock class.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
This patch only changes tests.

Closes #29549 from alismess-db/get-catalogs-operation-mock-use-shim.

Authored-by: Ali Smesseim <ali.smesseim@databricks.com>
Signed-off-by: Yuming Wang <yumwang@ebay.com>
This commit is contained in:
Ali Smesseim 2020-09-02 20:23:57 +08:00 committed by Yuming Wang
parent 55ce49ed28
commit 3cde392b69
5 changed files with 18 additions and 63 deletions

View file

@ -152,18 +152,6 @@
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>v${hive.version.short}/src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

View file

@ -22,7 +22,8 @@ import java.util.UUID
import org.apache.hive.service.cli.OperationHandle
import org.apache.hive.service.cli.operation.GetCatalogsOperation
import org.apache.hive.service.cli.session.HiveSession
import org.apache.hive.service.cli.thrift.{THandleIdentifier, TOperationHandle, TOperationType}
import org.apache.spark.sql.hive.thriftserver.ThriftserverShimUtils.{THandleIdentifier, TOperationHandle, TOperationType}
class GetCatalogsOperationMock(parentSession: HiveSession)
extends GetCatalogsOperation(parentSession) {

View file

@ -28,6 +28,10 @@ import org.apache.hive.service.cli.thrift.TProtocolVersion._
*/
private[thriftserver] object ThriftserverShimUtils {
private[thriftserver] object TOperationType {
val GET_TYPE_INFO = org.apache.hive.service.cli.thrift.TOperationType.GET_TYPE_INFO
}
private[thriftserver] type TProtocolVersion = org.apache.hive.service.cli.thrift.TProtocolVersion
private[thriftserver] type Client = org.apache.hive.service.cli.thrift.TCLIService.Client
private[thriftserver] type TOpenSessionReq = org.apache.hive.service.cli.thrift.TOpenSessionReq
@ -37,6 +41,10 @@ private[thriftserver] object ThriftserverShimUtils {
private[thriftserver] type TGetInfoReq = org.apache.hive.service.cli.thrift.TGetInfoReq
private[thriftserver] type TExecuteStatementReq =
org.apache.hive.service.cli.thrift.TExecuteStatementReq
private[thriftserver] type THandleIdentifier =
org.apache.hive.service.cli.thrift.THandleIdentifier
private[thriftserver] type TOperationType = org.apache.hive.service.cli.thrift.TOperationType
private[thriftserver] type TOperationHandle = org.apache.hive.service.cli.thrift.TOperationHandle
private[thriftserver] def getConsole: SessionState.LogHelper = {
val LOG = LogFactory.getLog(classOf[SparkSQLCLIDriver])

View file

@ -29,6 +29,10 @@ import org.slf4j.LoggerFactory
*/
private[thriftserver] object ThriftserverShimUtils {
private[thriftserver] object TOperationType {
val GET_TYPE_INFO = org.apache.hive.service.rpc.thrift.TOperationType.GET_TYPE_INFO
}
private[thriftserver] type TProtocolVersion = org.apache.hive.service.rpc.thrift.TProtocolVersion
private[thriftserver] type Client = org.apache.hive.service.rpc.thrift.TCLIService.Client
private[thriftserver] type TOpenSessionReq = org.apache.hive.service.rpc.thrift.TOpenSessionReq
@ -38,6 +42,10 @@ private[thriftserver] object ThriftserverShimUtils {
private[thriftserver] type TGetInfoReq = org.apache.hive.service.rpc.thrift.TGetInfoReq
private[thriftserver] type TExecuteStatementReq =
org.apache.hive.service.rpc.thrift.TExecuteStatementReq
private[thriftserver] type THandleIdentifier =
org.apache.hive.service.rpc.thrift.THandleIdentifier
private[thriftserver] type TOperationType = org.apache.hive.service.rpc.thrift.TOperationType
private[thriftserver] type TOperationHandle = org.apache.hive.service.rpc.thrift.TOperationHandle
private[thriftserver] def getConsole: SessionState.LogHelper = {
val LOG = LoggerFactory.getLogger(classOf[SparkSQLCLIDriver])

View file

@ -1,50 +0,0 @@
/*
* 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.ByteBuffer
import java.util.UUID
import org.apache.hive.service.cli.OperationHandle
import org.apache.hive.service.cli.operation.GetCatalogsOperation
import org.apache.hive.service.cli.session.HiveSession
import org.apache.hive.service.rpc.thrift.{THandleIdentifier, TOperationHandle, TOperationType}
class GetCatalogsOperationMock(parentSession: HiveSession)
extends GetCatalogsOperation(parentSession) {
override def runInternal(): Unit = {}
override def getHandle: OperationHandle = {
val uuid: UUID = UUID.randomUUID()
val tHandleIdentifier: THandleIdentifier = new THandleIdentifier()
tHandleIdentifier.setGuid(getByteBufferFromUUID(uuid))
tHandleIdentifier.setSecret(getByteBufferFromUUID(uuid))
val tOperationHandle: TOperationHandle = new TOperationHandle()
tOperationHandle.setOperationId(tHandleIdentifier)
tOperationHandle.setOperationType(TOperationType.GET_TYPE_INFO)
tOperationHandle.setHasResultSetIsSet(false)
new OperationHandle(tOperationHandle)
}
private def getByteBufferFromUUID(uuid: UUID): Array[Byte] = {
val bb: ByteBuffer = ByteBuffer.wrap(new Array[Byte](16))
bb.putLong(uuid.getMostSignificantBits)
bb.putLong(uuid.getLeastSignificantBits)
bb.array
}
}