spark-test commented on code in PR #60380:
URL: https://github.com/apache/spark/pull/60380#discussion_r4549827545
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryTableWithV2Filter.scala:
##########
@@ -203,15 +214,36 @@ object InMemoryTableWithV2Filter {
}
}
+ /**
+ * Table property that lets an overwrite compare `CHAR_READ_SIDE_PADDING` of
a column with a
+ * literal, as a connector that pads the CHAR values stored without padding
would do.
+ */
+ val AcceptCharReadSidePaddingKey = "accept-char-read-side-padding"
+
+ private object CharReadSidePadding {
+ def unapply(expr: V2Expression): Option[(NamedReference, Int)] = expr
match {
+ case e: GeneralScalarExpression if e.name() ==
CharVarcharUtils.V2_CHAR_READ_SIDE_PADDING =>
+ e.children().toSeq match {
+ case Seq(ref: NamedReference, LiteralValue(length: Int, _), _) =>
Some((ref, length))
+ case _ => None
+ }
+ case _ => None
+ }
+ }
+
/**
* Whether every predicate has a shape [[evalPredicate]] can evaluate: a
plain column, or a
* column and a literal. A predicate over an expression, e.g. a cast, is not
supported and
* returned to Spark, as a real connector without expression support would
do.
*/
- def supportsPredicates(predicates: Array[Predicate]): Boolean = {
+ def supportsPredicates(
+ predicates: Array[Predicate],
+ acceptCharReadSidePadding: Boolean = false): Boolean = {
Review Comment:
**Nit (P3):** This scaladoc still says the method accepts only a plain
column or a column and a literal, and that a predicate over an expression is
not supported. With `acceptCharReadSidePadding = true`, though, the new case
accepts `=` and `<=>` whose left side is `CHAR_READ_SIDE_PADDING(col, n, ' ')`,
and with the default `false` it rejects that shape even though `evalPredicate`
can now evaluate it. The doc also does not mention the parameter or that
`canOverwrite` sets it from the `accept-char-read-side-padding` table property,
so a later test or fixture change can misjudge which predicates the V2-filter
test table accepts. A possible wording for the scaladoc above the method:
```scala
/**
* Whether every predicate has one of the shapes this table accepts: `=`
or `<=>` between a
* column and a literal, `IS_NULL` or `IS_NOT_NULL` on a column,
`ALWAYS_TRUE`, and, only when
* `acceptCharReadSidePadding` is true, `=` or `<=>` between
`CHAR_READ_SIDE_PADDING` of a
* column and a literal. `canOverwrite` sets that flag from the
[[AcceptCharReadSidePaddingKey]]
* table property, and the other callers keep the default. Any other
predicate over an
* expression, e.g. a cast, is not supported and returned to Spark, as a
real connector without
* expression support would do.
*/
```
**Verification:**
- **Inspection:** Reading the supportsPredicates scaladoc against the method
body shows that every accepted shape is described, that the
CHAR_READ_SIDE_PADDING comparison is stated as accepted only when
acceptCharReadSidePadding is true, and that the parameter and how canOverwrite
sets it are documented.
--
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]