Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
averyqi-db committed Sep 17, 2024
1 parent 3fbb1b0 commit b80796c
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,41 @@ class OptimizerSuite extends PlanTest {
assert(message1.contains("not a valid aggregate expression"))
}
}

test("validate schema output respects spark.sql.caseSensitive flag") {
/**
* A dummy optimizer rule for capitalizing alias.
*/
object CapitalizeAttribute extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transformExpressions {
case a: Alias =>
// scalastyle:off caselocale
Alias(a.child, a.name.toUpperCase)(a.exprId, a.qualifier, a.explicitMetadata)
// scalastyle:on caselocale
}
}

val optimizer = new SimpleTestOptimizer() {
override def defaultBatches: Seq[Batch] =
Batch("test", FixedPoint(1), CapitalizeAttribute) :: Nil
}

val query = Project(Alias(Literal(1), "attr")() :: Nil, OneRowRelation()).analyze

withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
try {
optimizer.execute(query)
} catch {
case sx: SparkException =>
fail("Query should run successfully with case insensitive setting.")
}
}

withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
val message = intercept[SparkException] {
optimizer.execute(query)
}.getMessage
assert(message.contains("The plan output schema has changed"))
}
}
}

0 comments on commit b80796c

Please sign in to comment.