voonhous commented on code in PR #20540:
URL: https://github.com/apache/hudi/pull/20540#discussion_r4520662031


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/dataskipping/IndexedExpression.scala:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.hudi.dataskipping
+
+import org.apache.hudi.common.model.HoodieIndexDefinition
+import org.apache.hudi.common.util.StringUtils
+import 
org.apache.hudi.core.index.expression.HoodieExpressionIndex.{DAYS_OPTION, 
FORMAT_OPTION, IDENTITY_TRANSFORM, LENGTH_OPTION, PATTERN_OPTION, 
POSITION_OPTION, REGEX_GROUP_INDEX_OPTION, REPLACEMENT_OPTION, 
TRIM_STRING_OPTION}
+
+import org.apache.spark.sql.catalyst.expressions.{AttributeReference, Cast, 
DateAdd, DateFormatClass, DateSub, DayOfMonth, Expression, FromUnixTime, Hour, 
Length, Literal, Lower, Month, ParseToDate, ParseToTimestamp, RegExpExtract, 
RegExpReplace, StringSplit, StringTrim, StringTrimLeft, StringTrimRight, 
Substring, UnixTimestamp, Upper, Year}
+import org.apache.spark.sql.catalyst.util.TimestampFormatter
+
+import scala.collection.JavaConverters._
+
+/**
+ * The expression an expression index holds stats for: 
`function(sourceColumn)` with the index's options, as
+ * `ExpressionIndexSparkFunctions` computes it on write.
+ *
+ * A filter term reads the index only if [[matches]] says it is this 
expression: the same function, the same
+ * options and the same column. Any other term, including the bare column of a 
non-identity index, has no
+ * range in the index, so [[ExpressionIndexSource]] returns none and the file 
is kept.
+ */
+case class IndexedExpression(function: String, sourceColumn: String, options: 
Map[String, String]) {
+
+  def matches(term: Expression): Boolean = term.resolved && (term match {
+    case column: AttributeReference => function == IDENTITY_TRANSFORM && 
isSourceColumn(column)
+
+    case e: Year => function == "year" && isSource(e.child)
+    case e: Month => function == "month" && isSource(e.child)
+    case e: DayOfMonth => function == "day" && isSource(e.child)
+    case e: Hour => function == "hour" && isSource(e.child)
+    case e: DateFormatClass =>
+      function == "date_format" && isSource(e.left) && literalEquals(e.right, 
options.get(FORMAT_OPTION))
+    case e: FromUnixTime =>
+      function == "from_unixtime" && isSource(e.sec) && 
literalEquals(e.format, Some(formatOrDefault))
+    case e: UnixTimestamp =>
+      function == "unix_timestamp" && isSource(e.timeExp) && 
literalEquals(e.format, Some(formatOrDefault))
+    case e: ParseToDate => function == "to_date" && isSource(e.left) && 
optionalLiteralEquals(e.format, FORMAT_OPTION)

Review Comment:
   Fixed, `matches` now takes that `Cast` for a format-less index. #19480 stays 
for the with-format case.



-- 
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]

Reply via email to