-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28982][SQL] Implementation Spark's own GetTypeInfoOperation #25694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f61d7c2
1d47dd1
2ec8565
d202628
26de905
945074d
d3d2efc
aa1d721
9ee38eb
64ad1f3
51cb636
068352e
1c919a0
35c5a80
3c488fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * 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.util.UUID | ||
|
|
||
| import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType | ||
| import org.apache.hive.service.cli.{HiveSQLException, OperationState} | ||
| import org.apache.hive.service.cli.operation.GetTypeInfoOperation | ||
| import org.apache.hive.service.cli.session.HiveSession | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.SQLContext | ||
| import org.apache.spark.util.{Utils => SparkUtils} | ||
|
|
||
| /** | ||
| * Spark's own GetTypeInfoOperation | ||
| * | ||
| * @param sqlContext SQLContext to use | ||
| * @param parentSession a HiveSession from SessionManager | ||
| */ | ||
| private[hive] class SparkGetTypeInfoOperation( | ||
| sqlContext: SQLContext, | ||
| parentSession: HiveSession) | ||
| extends GetTypeInfoOperation(parentSession) with Logging { | ||
|
|
||
| private var statementId: String = _ | ||
|
|
||
| override def close(): Unit = { | ||
| super.close() | ||
| HiveThriftServer2.listener.onOperationClosed(statementId) | ||
| } | ||
|
|
||
| override def runInternal(): Unit = { | ||
| statementId = UUID.randomUUID().toString | ||
| val logMsg = "Listing type info" | ||
| logInfo(s"$logMsg with $statementId") | ||
| setState(OperationState.RUNNING) | ||
| // Always use the latest class loader provided by executionHive's state. | ||
| val executionHiveClassLoader = sqlContext.sharedState.jarClassLoader | ||
| Thread.currentThread().setContextClassLoader(executionHiveClassLoader) | ||
|
|
||
| if (isAuthV2Enabled) { | ||
| authorizeMetaGets(HiveOperationType.GET_TYPEINFO, null) | ||
| } | ||
|
|
||
| HiveThriftServer2.listener.onStatementStart( | ||
| statementId, | ||
| parentSession.getSessionHandle.getSessionId.toString, | ||
| logMsg, | ||
| statementId, | ||
| parentSession.getUsername) | ||
|
|
||
| try { | ||
| ThriftserverShimUtils.supportedType().foreach(typeInfo => { | ||
| val rowData = Array[AnyRef]( | ||
| typeInfo.getName, // TYPE_NAME | ||
| typeInfo.toJavaSQLType.asInstanceOf[AnyRef], // DATA_TYPE | ||
| typeInfo.getMaxPrecision.asInstanceOf[AnyRef], // PRECISION | ||
| typeInfo.getLiteralPrefix, // LITERAL_PREFIX | ||
| typeInfo.getLiteralSuffix, // LITERAL_SUFFIX | ||
| typeInfo.getCreateParams, // CREATE_PARAMS | ||
| typeInfo.getNullable.asInstanceOf[AnyRef], // NULLABLE | ||
| typeInfo.isCaseSensitive.asInstanceOf[AnyRef], // CASE_SENSITIVE | ||
| typeInfo.getSearchable.asInstanceOf[AnyRef], // SEARCHABLE | ||
| typeInfo.isUnsignedAttribute.asInstanceOf[AnyRef], // UNSIGNED_ATTRIBUTE | ||
| typeInfo.isFixedPrecScale.asInstanceOf[AnyRef], // FIXED_PREC_SCALE | ||
| typeInfo.isAutoIncrement.asInstanceOf[AnyRef], // AUTO_INCREMENT | ||
| typeInfo.getLocalizedName, // LOCAL_TYPE_NAME | ||
| typeInfo.getMinimumScale.asInstanceOf[AnyRef], // MINIMUM_SCALE | ||
| typeInfo.getMaximumScale.asInstanceOf[AnyRef], // MAXIMUM_SCALE | ||
| null, // SQL_DATA_TYPE, unused | ||
| null, // SQL_DATETIME_SUB, unused | ||
| typeInfo.getNumPrecRadix // NUM_PREC_RADIX | ||
| ) | ||
| rowSet.addRow(rowData) | ||
| }) | ||
| setState(OperationState.FINISHED) | ||
| } catch { | ||
| case e: HiveSQLException => | ||
| setState(OperationState.ERROR) | ||
| HiveThriftServer2.listener.onStatementError( | ||
| statementId, e.getMessage, SparkUtils.exceptionString(e)) | ||
| throw e | ||
| } | ||
| HiveThriftServer2.listener.onStatementFinish(statementId) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import scala.collection.JavaConverters._ | |
| import org.apache.hadoop.hive.ql.exec.AddToClassPathAction | ||
| import org.apache.hadoop.hive.ql.session.SessionState | ||
| import org.apache.hadoop.hive.serde2.thrift.Type | ||
| import org.apache.hadoop.hive.serde2.thrift.Type._ | ||
| import org.apache.hive.service.cli.{RowSet, RowSetFactory, TableSchema} | ||
| import org.apache.hive.service.rpc.thrift.TProtocolVersion._ | ||
| import org.slf4j.LoggerFactory | ||
|
|
@@ -56,6 +57,14 @@ private[thriftserver] object ThriftserverShimUtils { | |
|
|
||
| private[thriftserver] def toJavaSQLType(s: String): Int = Type.getType(s).toJavaSQLType | ||
|
|
||
| private[thriftserver] def supportedType(): Seq[Type] = { | ||
| Seq(NULL_TYPE, BOOLEAN_TYPE, STRING_TYPE, BINARY_TYPE, | ||
| TINYINT_TYPE, SMALLINT_TYPE, INT_TYPE, BIGINT_TYPE, | ||
| FLOAT_TYPE, DOUBLE_TYPE, DECIMAL_TYPE, | ||
| DATE_TYPE, TIMESTAMP_TYPE, | ||
| ARRAY_TYPE, MAP_TYPE, STRUCT_TYPE) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we skip
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Support this type just convert to string to show. Should add .
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add these types. Hive-3.1.2 also converted these types to strings.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the client handle it? Then what does
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For getMetadataResult, it truly return ARRAY, MAP, STRUCT.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. We can not fully support these type. Please remove them @AngersZhuuuu
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, thanks for explaining it @AngersZhuuuu, and you convinced me that ARRAY, MAP and STRUCT must be included. but then so that tells to the client that it is actually returned as String, and I should retrieve it as such, either with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. USER_DEFINED in java.sql.Types is OTHERS, in the convert progress, it's also converted to String , same as ARRAY, MAP, STRUCT.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But Spark will never return a USER_DEFINED type.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Remove it and resolve conflicts. |
||
|
|
||
| private[thriftserver] def addToClassPath( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: empty line between functions.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add it . |
||
| loader: ClassLoader, | ||
| auxJars: Array[String]): ClassLoader = { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.