Skip to content

Commit

Permalink
[SPARK-48915][SQL][TESTS] Add some uncovered predicates(!=, <=, >, >=…
Browse files Browse the repository at this point in the history
…) in test cases of `GeneratedSubquerySuite`

### What changes were proposed in this pull request?

This PR aims to add some predicates(!=, <=, >, >=) which are not covered in test cases of `GeneratedSubquerySuite`.

### Why are the changes needed?

Better coverage of current subquery tests in `GeneratedSubquerySuite`.
For more information about subqueries in `postgresq`, refer to:
https://www.postgresql.org/docs/current/functions-subquery.html#FUNCTIONS-SUBQUERY
https://www.postgresql.org/docs/current/functions-comparisons.html#ROW-WISE-COMPARISON

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass GA and Manual testing with `GeneratedSubquerySuite`.
![image](https://github.com/user-attachments/assets/4b265def-a7a9-405e-94ce-e9902efb79fa)

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes apache#47386 from wayneguow/SPARK-48915.

Authored-by: Wei Guo <guow93@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
  • Loading branch information
wayneguow authored and cloud-fan committed Jul 18, 2024
1 parent 2cd4a4a commit 9d4ebf7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ class GeneratedSubquerySuite extends DockerJDBCIntegrationSuite with QueryGenera
} else {
Seq()
}
val isScalarSubquery = Seq(SubqueryType.ATTRIBUTE, SubqueryType.SCALAR_PREDICATE_EQUALS,
SubqueryType.SCALAR_PREDICATE_LESS_THAN).contains(subqueryType)
val isScalarSubquery = Seq(SubqueryType.ATTRIBUTE,
SubqueryType.SCALAR_PREDICATE_EQUALS, SubqueryType.SCALAR_PREDICATE_NOT_EQUALS,
SubqueryType.SCALAR_PREDICATE_LESS_THAN, SubqueryType.SCALAR_PREDICATE_LESS_THAN_OR_EQUALS,
SubqueryType.SCALAR_PREDICATE_GREATER_THAN,
SubqueryType.SCALAR_PREDICATE_GREATER_THAN_OR_EQUALS).contains(subqueryType)
val subqueryOrganization = generateSubquery(
innerTable, correlationConditions, isDistinct, operatorInSubquery, isScalarSubquery)

Expand Down Expand Up @@ -218,8 +221,16 @@ class GeneratedSubquerySuite extends DockerJDBCIntegrationSuite with QueryGenera
val whereClausePredicate = subqueryType match {
case SubqueryType.SCALAR_PREDICATE_EQUALS =>
Equals(expr, Subquery(subqueryOrganization))
case SubqueryType.SCALAR_PREDICATE_NOT_EQUALS =>
NotEquals(expr, Subquery(subqueryOrganization))
case SubqueryType.SCALAR_PREDICATE_LESS_THAN =>
LessThan(expr, Subquery(subqueryOrganization))
case SubqueryType.SCALAR_PREDICATE_LESS_THAN_OR_EQUALS =>
LessThanOrEquals(expr, Subquery(subqueryOrganization))
case SubqueryType.SCALAR_PREDICATE_GREATER_THAN =>
GreaterThan(expr, Subquery(subqueryOrganization))
case SubqueryType.SCALAR_PREDICATE_GREATER_THAN_OR_EQUALS =>
GreaterThanOrEquals(expr, Subquery(subqueryOrganization))
case SubqueryType.EXISTS => Exists(subqueryOrganization)
case SubqueryType.NOT_EXISTS => Not(Exists(subqueryOrganization))
case SubqueryType.IN => In(expr, subqueryOrganization)
Expand Down Expand Up @@ -294,7 +305,11 @@ class GeneratedSubquerySuite extends DockerJDBCIntegrationSuite with QueryGenera
case SubqueryLocation.FROM => Seq(SubqueryType.RELATION)
case SubqueryLocation.WHERE => Seq(
SubqueryType.SCALAR_PREDICATE_LESS_THAN,
SubqueryType.SCALAR_PREDICATE_LESS_THAN_OR_EQUALS,
SubqueryType.SCALAR_PREDICATE_GREATER_THAN,
SubqueryType.SCALAR_PREDICATE_GREATER_THAN_OR_EQUALS,
SubqueryType.SCALAR_PREDICATE_EQUALS,
SubqueryType.SCALAR_PREDICATE_NOT_EQUALS,
SubqueryType.IN,
SubqueryType.NOT_IN,
SubqueryType.EXISTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,22 @@ trait QueryGeneratorHelper {
case class Equals(expr: Expression, rightSideExpr: Expression) extends Predicate {
override def toString: String = f"$expr = $rightSideExpr"
}
case class NotEquals(expr: Expression, rightSideExpr: Expression) extends Predicate {
override def toString: String = f"$expr <> $rightSideExpr"
}
case class LessThan(expr: Expression, rightSideExpr: Expression) extends Predicate {
override def toString: String = f"$expr < $rightSideExpr"
}
case class LessThanOrEquals(expr: Expression, rightSideExpr: Expression) extends Predicate {
override def toString: String = f"$expr <= $rightSideExpr"
}
case class GreaterThan(expr: Expression, rightSideExpr: Expression) extends Predicate {
override def toString: String = f"$expr > $rightSideExpr"
}
case class GreaterThanOrEquals(expr: Expression, rightSideExpr: Expression) extends Predicate {
override def toString: String = f"$expr >= $rightSideExpr"
}

case class In(expr: Expression, inner: Operator)
extends Predicate {
override def toString: String = f"$expr IN ($inner)"
Expand All @@ -96,7 +109,10 @@ trait QueryGeneratorHelper {
// Subquery to be treated as a Relation.
val RELATION = Value
// Subquery is a Predicate - types of predicate subqueries.
val SCALAR_PREDICATE_EQUALS, SCALAR_PREDICATE_LESS_THAN, IN, NOT_IN, EXISTS, NOT_EXISTS = Value
val SCALAR_PREDICATE_EQUALS, SCALAR_PREDICATE_NOT_EQUALS,
SCALAR_PREDICATE_LESS_THAN, SCALAR_PREDICATE_LESS_THAN_OR_EQUALS,
SCALAR_PREDICATE_GREATER_THAN, SCALAR_PREDICATE_GREATER_THAN_OR_EQUALS,
IN, NOT_IN, EXISTS, NOT_EXISTS = Value
}

trait SubqueryExpression extends Expression {
Expand Down

0 comments on commit 9d4ebf7

Please sign in to comment.