AngersZhuuuu commented on a change in pull request #25694: [SPARK-28982][SQL] Implementation Spark's own GetTypeInfoOperation URL: https://github.com/apache/spark/pull/25694#discussion_r321663582
########## File path: sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/cli/Type.scala ########## @@ -0,0 +1,376 @@ +/* + * 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.cli + +import java.sql.DatabaseMetaData + +import org.apache.spark.sql.types.DecimalType + +trait Type { + + def getName: String + + def isComplex: Boolean + + def isQualifiedType: Boolean + + def isCollectionType: Boolean + + def isPrimitiveType: Boolean = !isComplex + + def isComplexType: Boolean = isComplex + + /** + * Radix for this type (typically either 2 or 10) + * Null is returned for data types where this is not applicable. + */ + def getNumPrecRadix: Integer = { + if (this.isNumericType) { + 10 + } else { + null + } + } + + def getMaxPrecision(): Option[Int] + + def isNumericType(): Boolean = false + + /** + * Prefix used to quote a literal of this type (may be null) + */ + def getLiteralPrefix: String = null + + /** + * Suffix used to quote a literal of this type (may be null) + * + * @return + */ + def getLiteralSuffix: String = null + + /** + * Can you use NULL for this type? + * + * @return + * DatabaseMetaData.typeNoNulls - does not allow NULL values + * DatabaseMetaData.typeNullable - allows NULL values + * DatabaseMetaData.typeNullableUnknown - nullability unknown + */ + def getNullable: Short = { + // All Hive types are nullable + DatabaseMetaData.typeNullable.toShort + } + + /** + * Is the type case sensitive? + * + * @return + */ + def isCaseSensitive: Boolean = false + + /** + * Parameters used in creating the type (may be null) + * + * @return + */ + def getCreateParams: String = null + + /** + * Can you use WHERE based on this type? + * + * @return + * DatabaseMetaData.typePredNone - No support + * DatabaseMetaData.typePredChar - Only support with WHERE .. LIKE + * DatabaseMetaData.typePredBasic - Supported except for WHERE .. LIKE + * DatabaseMetaData.typeSearchable - Supported for all WHERE .. + */ + def getSearchable: Short = { + if (isPrimitiveType) { + DatabaseMetaData.typeSearchable.toShort + } else { + DatabaseMetaData.typePredNone.toShort Review comment: String is searchable. In my return it's 3, means searchable. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
