amaliujia commented on code in PR #41559: URL: https://github.com/apache/spark/pull/41559#discussion_r1238815647
########## sql/catalyst/src/main/scala/org/apache/spark/sql/types/DataTypeExpression.scala: ########## @@ -0,0 +1,99 @@ +/* + * 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 + +import org.apache.spark.sql.catalyst.expressions.Expression +import org.apache.spark.sql.errors.QueryExecutionErrors + +abstract class DataTypeExpression(val dataType: DataType) { + /** + * Enables matching against DataType for expressions: + * {{{ + * case Cast(child @ BinaryType(), StringType) => + * ... + * }}} + */ + private[sql] def unapply(e: Expression): Boolean = e.dataType == dataType +} + +abstract class AtomicTypeExpression(override val dataType: DataType) + extends DataTypeExpression(dataType) + +abstract class DatetimeTypeExpression(override val dataType: DataType) + extends AtomicTypeExpression(dataType) + +case object BooleanTypeExpression extends DataTypeExpression(BooleanType) +case object StringTypeExpression extends DataTypeExpression(StringType) +case object TimestampTypeExpression extends DataTypeExpression(TimestampType) +case object DateTypeExpression extends DataTypeExpression(DateType) +case object ByteTypeExpression extends DataTypeExpression(ByteType) +case object ShortTypeExpression extends DataTypeExpression(ShortType) +case object IntegerTypeExpression extends DataTypeExpression(IntegerType) +case object LongTypeExpression extends DataTypeExpression(LongType) +case object DoubleTypeExpression extends DataTypeExpression(DoubleType) +case object FloatTypeExpression extends DataTypeExpression(FloatType) + +object NumericTypeExpression { + /** + * Enables matching against NumericType for expressions: + * {{{ + * case Cast(child @ NumericType(), StringType) => + * ... + * }}} + */ + def unapply(e: Expression): Boolean = { Review Comment: This is something I am not sure: Use this code as example `case EqualNullSafe(left @ BooleanTypeExpression(), right @ NumericType())` is this code's semantic for example when passing in a IntegerType, but we are calling NumericType unapply, is 1. this code expect to know that this is just a NumericType 2. or this code expect to know that this should be a IntegerType so not only NumericType. I implemented for 2. But do you think this semantic is just 1. -- 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]
