rdblue commented on a change in pull request #24117: [SPARK-27181][SQL]: Add public transform API URL: https://github.com/apache/spark/pull/24117#discussion_r270582232
########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/catalog/v2/expressions/Literal.java ########## @@ -0,0 +1,39 @@ +/* + * 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.catalog.v2.expressions; + +import org.apache.spark.annotation.Experimental; +import org.apache.spark.sql.types.DataType; + +/** + * Represents a constant literal value in the public expression API. + * + * @param <T> the Java type of a value held by the literal + */ +@Experimental +public interface Literal<T> extends Expression { Review comment: The alternative is to cast the value instead, so you have to cast either way. You can't get around casting when the type is discarded. I don't think it is a good idea to throw away type information in all cases just because it isn't useful in some cases. Here's an example of how it is [used in Iceberg](https://github.com/apache/incubator-iceberg/blob/master/api/src/main/java/org/apache/iceberg/expressions/Evaluator.java#L102-L105) in expression evaluation: ```java public <T> Boolean lt(BoundReference<T> ref, Literal<T> lit) { Comparator<T> cmp = lit.comparator(); return cmp.compare(ref.get(struct), lit.value()) < 0; } ``` In Iceberg, expression binding guarantees that the literal's type matches the reference's type. With that information, this code knows that the value returned by the reference's get method matches the type of the comparator and of the literal value. ---------------------------------------------------------------- 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]
