Skip to content

Commit

Permalink
[SPARK-28642][SQL][TEST][FOLLOW-UP] Test spark.sql.redaction.options.…
Browse files Browse the repository at this point in the history
…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 apache#25579 from wangyum/SPARK-28642-f1.

Authored-by: Yuming Wang <yumwang@ebay.com>
Signed-off-by: Xiao Li <gatorsmile@gmail.com>
  • Loading branch information
wangyum authored and gatorsmile committed Aug 26, 2019
1 parent adb506a commit c353a84
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1031,27 +1031,41 @@ class JDBCSuite extends QueryTest
}

test("Hide credentials in show create table") {
val userName = "testUser"
val password = "testPass"
val tableName = "tab1"
val dbTable = "TEST.PEOPLE"
withTable(tableName) {
sql(
s"""
|CREATE TABLE $tableName
|USING org.apache.spark.sql.jdbc
|OPTIONS (
| url '$urlWithUserAndPass',
| dbtable 'TEST.PEOPLE',
| user 'testUser',
| dbtable '$dbTable',
| user '$userName',
| password '$password')
""".stripMargin)

val show = ShowCreateTableCommand(TableIdentifier(tableName))
spark.sessionState.executePlan(show).executedPlan.executeCollect().foreach { r =>
assert(!r.toString.contains(password))
assert(r.toString.contains(dbTable))
assert(r.toString.contains(userName))
}

sql(s"SHOW CREATE TABLE $tableName").collect().foreach { r =>
assert(!r.toString().contains(password))
assert(!r.toString.contains(password))
assert(r.toString.contains(dbTable))
assert(r.toString.contains(userName))
}

withSQLConf(SQLConf.SQL_OPTIONS_REDACTION_PATTERN.key -> "(?i)dbtable|user") {
spark.sessionState.executePlan(show).executedPlan.executeCollect().foreach { r =>
assert(!r.toString.contains(password))
assert(!r.toString.contains(dbTable))
assert(!r.toString.contains(userName))
}
}
}
}
Expand Down

0 comments on commit c353a84

Please sign in to comment.