Skip to content

Commit

Permalink
[SPARK-33480][SQL][FOLLOWUP] do not expose user data in error message
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

This is a followup of #30412. This PR updates the error message of char/varchar table insertion length check, to not expose user data.

### Why are the changes needed?

This is risky to expose user data in the error message, especially the string data, as it may contain sensitive data.

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

no

### How was this patch tested?

updated tests

Closes #30653 from cloud-fan/minor2.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
cloud-fan authored and dongjoon-hyun committed Dec 7, 2020
1 parent 6aff215 commit c0874ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Expand Up @@ -183,9 +183,9 @@ object CharVarcharUtils extends Logging {

private def raiseError(expr: Expression, typeName: String, length: Int): Expression = {
val errorMsg = Concat(Seq(
Literal("input string '"),
expr,
Literal(s"' exceeds $typeName type length limitation: $length")))
Literal("input string of length "),
Cast(Length(expr), StringType),
Literal(s" exceeds $typeName type length limitation: $length")))
Cast(RaiseError(errorMsg), StringType)
}

Expand Down
Expand Up @@ -190,7 +190,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(null))
val e = intercept[SparkException](sql("INSERT INTO t VALUES ('123456')"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -203,7 +203,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(1, null))
val e = intercept[SparkException](sql("INSERT INTO t VALUES (1, '123456')"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}
}
Expand All @@ -215,7 +215,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(Row(null)))
val e = intercept[SparkException](sql("INSERT INTO t SELECT struct('123456')"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -226,7 +226,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(Seq(null)))
val e = intercept[SparkException](sql("INSERT INTO t VALUES (array('a', '123456'))"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -235,7 +235,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
sql(s"CREATE TABLE t(c MAP<$typeName(5), STRING>) USING $format")
val e = intercept[SparkException](sql("INSERT INTO t VALUES (map('123456', 'a'))"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -246,7 +246,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(Map("a" -> null)))
val e = intercept[SparkException](sql("INSERT INTO t VALUES (map('a', '123456'))"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -255,10 +255,10 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
sql(s"CREATE TABLE t(c MAP<$typeName(5), $typeName(5)>) USING $format")
val e1 = intercept[SparkException](sql("INSERT INTO t VALUES (map('123456', 'a'))"))
assert(e1.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
val e2 = intercept[SparkException](sql("INSERT INTO t VALUES (map('a', '123456'))"))
assert(e2.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -269,7 +269,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(Row(Seq(null))))
val e = intercept[SparkException](sql("INSERT INTO t SELECT struct(array('123456'))"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -280,7 +280,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(Seq(Row(null))))
val e = intercept[SparkException](sql("INSERT INTO t VALUES (array(struct('123456')))"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -291,7 +291,7 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row(Seq(Seq(null))))
val e = intercept[SparkException](sql("INSERT INTO t VALUES (array(array('123456')))"))
assert(e.getCause.getMessage.contains(
s"input string '123456' exceeds $typeName type length limitation: 5"))
s"input string of length 6 exceeds $typeName type length limitation: 5"))
}
}

Expand All @@ -313,10 +313,10 @@ trait CharVarcharTestSuite extends QueryTest with SQLTestUtils {
checkAnswer(spark.table("t"), Row("1234 ", "1234"))
val e1 = intercept[SparkException](sql("INSERT INTO t VALUES (123456, 1)"))
assert(e1.getCause.getMessage.contains(
"input string '123456' exceeds char type length limitation: 5"))
"input string of length 6 exceeds char type length limitation: 5"))
val e2 = intercept[SparkException](sql("INSERT INTO t VALUES (1, 123456)"))
assert(e2.getCause.getMessage.contains(
"input string '123456' exceeds varchar type length limitation: 5"))
"input string of length 6 exceeds varchar type length limitation: 5"))
}
}

Expand Down

0 comments on commit c0874ba

Please sign in to comment.