Skip to content

Commit c353a84

Browse files
wangyumgatorsmile
authored andcommitted
[SPARK-28642][SQL][TEST][FOLLOW-UP] Test spark.sql.redaction.options.regex with and without default values
### What changes were proposed in this pull request? Test `spark.sql.redaction.options.regex` with and without default values. ### Why are the changes needed? Normally, we do not rely on the default value of `spark.sql.redaction.options.regex`. ### Does this PR introduce any user-facing change? No ### How was this patch tested? N/A Closes #25579 from wangyum/SPARK-28642-f1. Authored-by: Yuming Wang <[email protected]> Signed-off-by: Xiao Li <[email protected]>
1 parent adb506a commit c353a84

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,27 +1031,41 @@ class JDBCSuite extends QueryTest
10311031
}
10321032

10331033
test("Hide credentials in show create table") {
1034+
val userName = "testUser"
10341035
val password = "testPass"
10351036
val tableName = "tab1"
1037+
val dbTable = "TEST.PEOPLE"
10361038
withTable(tableName) {
10371039
sql(
10381040
s"""
10391041
|CREATE TABLE $tableName
10401042
|USING org.apache.spark.sql.jdbc
10411043
|OPTIONS (
10421044
| url '$urlWithUserAndPass',
1043-
| dbtable 'TEST.PEOPLE',
1044-
| user 'testUser',
1045+
| dbtable '$dbTable',
1046+
| user '$userName',
10451047
| password '$password')
10461048
""".stripMargin)
10471049

10481050
val show = ShowCreateTableCommand(TableIdentifier(tableName))
10491051
spark.sessionState.executePlan(show).executedPlan.executeCollect().foreach { r =>
10501052
assert(!r.toString.contains(password))
1053+
assert(r.toString.contains(dbTable))
1054+
assert(r.toString.contains(userName))
10511055
}
10521056

10531057
sql(s"SHOW CREATE TABLE $tableName").collect().foreach { r =>
1054-
assert(!r.toString().contains(password))
1058+
assert(!r.toString.contains(password))
1059+
assert(r.toString.contains(dbTable))
1060+
assert(r.toString.contains(userName))
1061+
}
1062+
1063+
withSQLConf(SQLConf.SQL_OPTIONS_REDACTION_PATTERN.key -> "(?i)dbtable|user") {
1064+
spark.sessionState.executePlan(show).executedPlan.executeCollect().foreach { r =>
1065+
assert(!r.toString.contains(password))
1066+
assert(!r.toString.contains(dbTable))
1067+
assert(!r.toString.contains(userName))
1068+
}
10551069
}
10561070
}
10571071
}

0 commit comments

Comments
 (0)