yaooqinn commented on code in PR #47412:
URL: https://github.com/apache/spark/pull/47412#discussion_r1683736335
##########
sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala:
##########
@@ -960,25 +960,45 @@ class FileSourceCharVarcharTestSuite extends
CharVarcharTestSuite with SharedSpa
import testImplicits._
withSQLConf(SQLConf.READ_SIDE_CHAR_PADDING.key -> "false") {
withTempPath { dir =>
- withTable("t") {
+ withTable("t1", "t2") {
Seq(
"12" -> "12",
"12" -> "12 ",
"12 " -> "12",
"12 " -> "12 "
).toDF("c1", "c2").write.format(format).save(dir.toString)
- sql(s"CREATE TABLE t (c1 CHAR(3), c2 STRING) USING $format LOCATION
'$dir'")
+
+ sql(s"CREATE TABLE t1 (c1 CHAR(3), c2 STRING) USING $format LOCATION
'$dir'")
// Comparing CHAR column with STRING column directly compares the
stored value.
checkAnswer(
- sql("SELECT c1 = c2 FROM t"),
+ sql("SELECT c1 = c2 FROM t1"),
+ Seq(Row(true), Row(false), Row(false), Row(true))
+ )
+ checkAnswer(
+ sql("SELECT c1 IN (c2) FROM t1"),
Seq(Row(true), Row(false), Row(false), Row(true))
)
// No matter the CHAR type value is padded or not in the storage, we
should always pad it
// before comparison with STRING literals.
checkAnswer(
- sql("SELECT c1 = '12', c1 = '12 ', c1 = '12 ' FROM t WHERE c2 =
'12'"),
+ sql("SELECT c1 = '12', c1 = '12 ', c1 = '12 ' FROM t1 WHERE c2 =
'12'"),
Seq(Row(true, true, true), Row(true, true, true))
)
+ checkAnswer(
+ sql("SELECT c1 IN ('12'), c1 IN ('12 '), c1 IN ('12 ') FROM t1
WHERE c2 = '12'"),
+ Seq(Row(true, true, true), Row(true, true, true))
+ )
+
+ sql(s"CREATE TABLE t2 (c1 CHAR(3), c2 CHAR(5)) USING $format
LOCATION '$dir'")
+ // Comparing CHAR column with CHAR column compares the padded values.
+ checkAnswer(
+ sql("SELECT c1 = c2 FROM t2"),
Review Comment:
Can we test both c1 = c2 and c2 = c1?
##########
sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala:
##########
@@ -960,25 +960,45 @@ class FileSourceCharVarcharTestSuite extends
CharVarcharTestSuite with SharedSpa
import testImplicits._
withSQLConf(SQLConf.READ_SIDE_CHAR_PADDING.key -> "false") {
withTempPath { dir =>
- withTable("t") {
+ withTable("t1", "t2") {
Seq(
"12" -> "12",
"12" -> "12 ",
"12 " -> "12",
"12 " -> "12 "
).toDF("c1", "c2").write.format(format).save(dir.toString)
- sql(s"CREATE TABLE t (c1 CHAR(3), c2 STRING) USING $format LOCATION
'$dir'")
+
+ sql(s"CREATE TABLE t1 (c1 CHAR(3), c2 STRING) USING $format LOCATION
'$dir'")
// Comparing CHAR column with STRING column directly compares the
stored value.
checkAnswer(
- sql("SELECT c1 = c2 FROM t"),
+ sql("SELECT c1 = c2 FROM t1"),
+ Seq(Row(true), Row(false), Row(false), Row(true))
+ )
+ checkAnswer(
+ sql("SELECT c1 IN (c2) FROM t1"),
Seq(Row(true), Row(false), Row(false), Row(true))
)
// No matter the CHAR type value is padded or not in the storage, we
should always pad it
// before comparison with STRING literals.
checkAnswer(
- sql("SELECT c1 = '12', c1 = '12 ', c1 = '12 ' FROM t WHERE c2 =
'12'"),
+ sql("SELECT c1 = '12', c1 = '12 ', c1 = '12 ' FROM t1 WHERE c2 =
'12'"),
Seq(Row(true, true, true), Row(true, true, true))
)
+ checkAnswer(
+ sql("SELECT c1 IN ('12'), c1 IN ('12 '), c1 IN ('12 ') FROM t1
WHERE c2 = '12'"),
+ Seq(Row(true, true, true), Row(true, true, true))
+ )
+
+ sql(s"CREATE TABLE t2 (c1 CHAR(3), c2 CHAR(5)) USING $format
LOCATION '$dir'")
+ // Comparing CHAR column with CHAR column compares the padded values.
+ checkAnswer(
+ sql("SELECT c1 = c2 FROM t2"),
+ Seq(Row(true), Row(true), Row(true), Row(true))
+ )
+ checkAnswer(
+ sql("SELECT c1 IN (c2) FROM t2"),
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]