JkSelf commented on code in PR #6651: URL: https://github.com/apache/incubator-gluten/pull/6651#discussion_r1697888773
########## shims/spark32/src/main/scala/org/apache/spark/sql/types/AbstractDataType.scala: ########## @@ -0,0 +1,86 @@ +/* + * 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.types + +/** A non-concrete data type, reserved for internal uses. */ +abstract private[sql] class AbstractDataType { + + /** The default concrete type to use if we want to cast a null literal into this type. */ + private[sql] def defaultConcreteType: DataType + + /** + * Returns true if `other` is an acceptable input type for a function that expects this, possibly + * abstract DataType. + * + * {{{ + * // this should return true + * DecimalType.acceptsType(DecimalType(10, 2)) + * + * // this should return true as well + * NumericType.acceptsType(DecimalType(10, 2)) + * }}} + */ + private[sql] def acceptsType(other: DataType): Boolean + + /** Readable string representation for the type. */ + private[sql] def simpleString: String +} + +/** + * A collection of types that can be used to specify type constraints. The sequence also specifies + * precedence: an earlier type takes precedence over a latter type. + * + * {{{ + * TypeCollection(StringType, BinaryType) + * }}} + * + * This means that we prefer StringType over BinaryType if it is possible to cast to StringType. + */ +private[sql] class TypeCollection(private val types: Seq[AbstractDataType]) + extends AbstractDataType { + + require(types.nonEmpty, s"TypeCollection ($types) cannot be empty") + + override private[sql] def defaultConcreteType: DataType = types.head.defaultConcreteType + + override private[sql] def acceptsType(other: DataType): Boolean = + types.exists(_.acceptsType(other)) + + override private[sql] def simpleString: String = { + types.map(_.simpleString).mkString("(", " or ", ")") + } +} + +private[sql] object TypeCollection { + + /** Types that include numeric types and ANSI interval types. */ + val NumericAndAnsiInterval = + TypeCollection(NumericType, DayTimeIntervalType, YearMonthIntervalType, DateType) Review Comment: Add the `DateType ` in `NumericAndAnsiInterval`. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
