peter-toth commented on code in PR #59715:
URL: https://github.com/apache/spark/pull/59715#discussion_r4377262897


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/connector/StorageFilterImpl.scala:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.internal.connector
+
+import scala.util.control.NonFatal
+
+import org.apache.spark.{SparkEnv, SparkException, TaskContext}
+import org.apache.spark.executor.Executor
+import org.apache.spark.internal.{Logging, LogKeys}
+import org.apache.spark.internal.config.KILL_ON_FATAL_ERROR_DEPTH
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Attribute, BindReferences, 
Expression => CatalystExpression, Predicate => CatalystPredicate}
+import org.apache.spark.sql.connector.expressions.{FieldReference, 
NamedReference}
+import org.apache.spark.sql.connector.expressions.filter.{StorageFilter, 
StorageFilterNotAppliedException}
+
+/**
+ * A [[StorageFilter]] wrapping a Catalyst expression, so a scan can apply a 
predicate it does not
+ * have to understand. It mirrors [[PartitionPredicateImpl]], which evaluates 
a partition key
+ * rather than a data row.
+ *
+ * `attrs` is the layout of the row [[eval]] expects, in that order, and the 
expression is bound to
+ * it. The binding is built on first use, so an instance created on the driver 
can be evaluated on
+ * an executor.
+ */
+class StorageFilterImpl private (
+    private val catalystExpr: CatalystExpression,
+    private val attrs: Seq[Attribute])
+  extends StorageFilter with Logging {
+
+  // The width of the row `eval` takes.
+  private val numReferences = attrs.length
+
+  // Whether this instance has logged a failure, so a task logs only its first.
+  @transient private var loggedFailure = false
+
+  @transient private lazy val boundPredicate: InternalRow => Boolean = {
+    val bound = BindReferences.bindReference(catalystExpr, attrs)
+    CatalystPredicate.create(bound).eval
+  }
+
+  /**
+   * Wraps a non-fatal error in [[StorageFilterNotAppliedException]], unless 
the task is being
+   * killed or a fatal error is in its cause chain. Each task logs the first 
one. A row of another
+   * width than [[references]] is a reader bug, which fails the task, since 
the predicate would read
+   * the wrong values.
+   */
+  @throws[StorageFilterNotAppliedException]
+  override def eval(row: InternalRow): Boolean = {
+    // Outside the `try`, so a failure to build the predicate, or a row of 
another width, fails the
+    // task.
+    if (row.numFields != numReferences) {
+      throw SparkException.internalError(
+        s"A storage filter over ${references.mkString("[", ", ", "]")} takes 
rows of " +
+          s"$numReferences values, but got ${row.numFields}")
+    }
+    val predicate = boundPredicate
+    try {
+      predicate(row)
+    } catch {
+      case NonFatal(e) if !StorageFilterImpl.taskKilled && 
!StorageFilterImpl.hasFatalCause(e) =>

Review Comment:
   Thanks, fixed in 
[`4b01898`](https://github.com/apache/spark/pull/59715/commits/4b01898da695d7f6b5cce1ddca29d5c040dcf788).
 I had looked only at `DataSourceRDD`, which has no `ignoreCorruptFiles` catch, 
and missed `FilePartitionReader`'s. The V1 rule now lives in the new 
`StorageFilterErrors`, and `eval` follows it with `fromRead = false`. 
`StorageFilterImplSuite` now pins the V1 outcomes for a fatal cause, a bare 
`InternalError`, a kill and a `LinkageError`.



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

Reply via email to