LuciferYang commented on code in PR #59545:
URL: https://github.com/apache/spark/pull/59545#discussion_r4521577992
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/constraints/Check.java:
##########
@@ -66,17 +66,19 @@ private Check(
* Returns the SQL representation of the search condition (Spark SQL
dialect).
* <p>
* This is the canonical representation of the condition and is always
present (never
- * {@code null}). The optional {@link #predicate()} provides a structured
form when the condition
- * can be expressed using supported {@link Predicate} expressions.
+ * {@code null}). The optional {@link #predicate()} provides a structured
form, except in the
+ * cases that method lists.
*/
public String predicateSql() {
return predicateSql;
}
/**
* Returns the search condition as a {@link Predicate}, or {@code null} if
the condition cannot be
Review Comment:
Documented in 641b196cc4f: the Javadoc of `predicate()` says why Spark
leaves it null for such a condition, and that a connector that validates or
enforces the constraint itself has to evaluate `predicateSql()` then. The
migration guide entry says the same.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableConstraints.scala:
##########
@@ -71,6 +71,16 @@ class ResolveTableConstraints(
case _ =>
v2Write
}
+ // Once the analysis resolves the names of a parsed condition, drop the
ones that are not a
+ // value of the row, such as `current_user` without parentheses or a
variable, from the values
+ // that the violation message lists.
+ case v2Write: V2WriteCommand if containsCheckInvariant(v2Write.query) =>
Review Comment:
Agreed, it is outside the ALTER TABLE fix: since a name without parentheses
and a variable keep the predicate, a constraint that this PR stores without one
never lists such a value. I removed the change in 641b196cc4f and opened
SPARK-61337, which can drop those values once in `CheckInvariant` as you
suggest.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala:
##########
@@ -877,6 +877,32 @@ object DateTimeUtils extends SparkDateTimeUtils {
}
}
+ /**
+ * Whether `input` is one of the special values that read the current date
or time: 'now',
+ * 'today', 'tomorrow' and 'yesterday'.
+ *
+ * @param input A string to check. It can contain trailing or leading
whitespaces.
+ */
+ private[sql] def isCurrentSpecialValue(input: String): Boolean = {
Review Comment:
Done in 641b196cc4f: `SpecialDatetimeValues.readsCurrentDate` asks the
conversion that the rule uses for the type and excludes only 'epoch'
(`DateTimeUtils.isEpochSpecialValue`), so a new special value of the
conversions counts as reading the current date.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala:
##########
@@ -877,6 +877,32 @@ object DateTimeUtils extends SparkDateTimeUtils {
}
}
+ /**
+ * Whether `input` is one of the special values that read the current date
or time: 'now',
+ * 'today', 'tomorrow' and 'yesterday'.
+ *
+ * @param input A string to check. It can contain trailing or leading
whitespaces.
+ */
+ private[sql] def isCurrentSpecialValue(input: String): Boolean = {
+ extractSpecialValue(input.trim).exists {
+ case "now" | "today" | "tomorrow" | "yesterday" => true
+ case _ => false
+ }
+ }
+
+ /**
+ * Whether `input` is a valid timestamp string with only a time part, which
a cast to a timestamp
+ * with local time zone completes with the current date.
+ */
+ private[sql] def isTimeOnlyTimestamp(input: UTF8String): Boolean = {
Review Comment:
Done in 641b196cc4f: it parses once and validates the time fields with
`LocalTime.of`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/LiteralFunctionResolution.scala:
##########
@@ -38,6 +38,12 @@ object LiteralFunctionResolution {
}
}
+ /** Whether `nameParts` is the name of a literal function, which `resolve`
resolves. */
+ def isLiteralFunction(nameParts: Seq[String]): Boolean = {
Review Comment:
Done in 641b196cc4f with a shared `find`.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/constraints.scala:
##########
@@ -120,7 +122,9 @@ case class CheckConstraint(
condition: String,
override val userProvidedName: String = null,
override val tableName: String = null,
- override val userProvidedCharacteristic: ConstraintCharacteristic =
ConstraintCharacteristic.empty)
+ override val userProvidedCharacteristic: ConstraintCharacteristic =
ConstraintCharacteristic.empty,
+ keepPredicate: Boolean = false,
Review Comment:
Done in 641b196cc4f: the two flags are one `omitPredicate: Option[Boolean]`.
The parser sets `Some(false)` for a condition that keeps its predicate,
`withPredicateDecision` decides only while it is `None`, and CREATE and REPLACE
TABLE leave it `None`. `keepsCheckPredicate` now checks the name parts of both
kinds of names in one place.
--
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]