Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions python/pyspark/sql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ class NullType(DataType):

__metaclass__ = DataTypeSingleton

def simpleString(self):
return 'unknown'


class AtomicType(DataType):
"""An internal type used to represent everything that is not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private[sql] object CatalogV2Util {
}
if (containsNullType(dt)) {
throw new AnalysisException(
"Cannot create tables with unknown type.")
s"Cannot create tables with ${NullType.simpleString} type.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ class NullType private() extends DataType {
override def defaultSize: Int = 1

private[spark] override def asNullable: NullType = this

// "null" is mainly used to represent a literal in Spark,
// it's better to avoid using it for data types.
override def simpleString: String = "unknown"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
| org.apache.spark.sql.catalyst.expressions.Ascii | ascii | SELECT ascii('222') | struct<ascii(222):int> |
| org.apache.spark.sql.catalyst.expressions.Asin | asin | SELECT asin(0) | struct<ASIN(CAST(0 AS DOUBLE)):double> |
| org.apache.spark.sql.catalyst.expressions.Asinh | asinh | SELECT asinh(0) | struct<ASINH(CAST(0 AS DOUBLE)):double> |
| org.apache.spark.sql.catalyst.expressions.AssertTrue | assert_true | SELECT assert_true(0 < 1) | struct<assert_true((0 < 1)):unknown> |
| org.apache.spark.sql.catalyst.expressions.AssertTrue | assert_true | SELECT assert_true(0 < 1) | struct<assert_true((0 < 1)):null> |
| org.apache.spark.sql.catalyst.expressions.Atan | atan | SELECT atan(0) | struct<ATAN(CAST(0 AS DOUBLE)):double> |
| org.apache.spark.sql.catalyst.expressions.Atan2 | atan2 | SELECT atan2(0, 0) | struct<ATAN2(CAST(0 AS DOUBLE), CAST(0 AS DOUBLE)):double> |
| org.apache.spark.sql.catalyst.expressions.Atanh | atanh | SELECT atanh(0) | struct<ATANH(CAST(0 AS DOUBLE)):double> |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- !query
select null, Null, nUll
-- !query schema
struct<NULL:unknown,NULL:unknown,NULL:unknown>
struct<NULL:null,NULL:null,NULL:null>
-- !query output
NULL NULL NULL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ two 2
-- !query
select * from values ("one", null), ("two", null) as data(a, b)
-- !query schema
struct<a:string,b:unknown>
struct<a:string,b:null>
-- !query output
one NULL
two NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- !query
select null, Null, nUll
-- !query schema
struct<NULL:unknown,NULL:unknown,NULL:unknown>
struct<NULL:null,NULL:null,NULL:null>
-- !query output
NULL NULL NULL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ select typeof(null)
-- !query schema
struct<typeof(NULL):string>
-- !query output
unknown
null


-- !query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ struct<1:int>
-- !query
select foo.* from (select null) as foo
-- !query schema
struct<NULL:unknown>
struct<NULL:null>
-- !query output
NULL


-- !query
select foo.* from (select 'xyzzy',1,null) as foo
-- !query schema
struct<xyzzy:string,1:int,NULL:unknown>
struct<xyzzy:string,1:int,NULL:null>
-- !query output
xyzzy 1 NULL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- !query
SELECT ifnull(null, 'x'), ifnull('y', 'x'), ifnull(null, null)
-- !query schema
struct<ifnull(NULL, x):string,ifnull(y, x):string,ifnull(NULL, NULL):unknown>
struct<ifnull(NULL, x):string,ifnull(y, x):string,ifnull(NULL, NULL):null>
-- !query output
x y NULL

Expand All @@ -21,15 +21,15 @@ NULL x
-- !query
SELECT nvl(null, 'x'), nvl('y', 'x'), nvl(null, null)
-- !query schema
struct<nvl(NULL, x):string,nvl(y, x):string,nvl(NULL, NULL):unknown>
struct<nvl(NULL, x):string,nvl(y, x):string,nvl(NULL, NULL):null>
-- !query output
x y NULL


-- !query
SELECT nvl2(null, 'x', 'y'), nvl2('n', 'x', 'y'), nvl2(null, null, null)
-- !query schema
struct<nvl2(NULL, x, y):string,nvl2(n, x, y):string,nvl2(NULL, NULL, NULL):unknown>
struct<nvl2(NULL, x, y):string,nvl2(n, x, y):string,nvl2(NULL, NULL, NULL):null>
-- !query output
y x NULL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ two 2
-- !query
select udf(a), b from values ("one", null), ("two", null) as data(a, b)
-- !query schema
struct<CAST(udf(cast(a as string)) AS STRING):string,b:unknown>
struct<CAST(udf(cast(a as string)) AS STRING):string,b:null>
-- !query output
one NULL
two NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class FileBasedDataSourceSuite extends QueryTest
""
}
def errorMessage(format: String): String = {
s"$format data source does not support unknown data type."
s"$format data source does not support null data type."
}
withSQLConf(SQLConf.USE_V1_SOURCE_LIST.key -> useV1List) {
withTempDir { dir =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2310,64 +2310,64 @@ class HiveDDLSuite
}
}

test("SPARK-20680: Spark-sql do not support for unknown column datatype") {
test("SPARK-20680: do not support for null column datatype") {
withTable("t") {
withView("tabUnknownType") {
withView("tabNullType") {
hiveClient.runSqlHive("CREATE TABLE t (t1 int)")
hiveClient.runSqlHive("INSERT INTO t VALUES (3)")
hiveClient.runSqlHive("CREATE VIEW tabUnknownType AS SELECT NULL AS col FROM t")
checkAnswer(spark.table("tabUnknownType"), Row(null))
hiveClient.runSqlHive("CREATE VIEW tabNullType AS SELECT NULL AS col FROM t")
checkAnswer(spark.table("tabNullType"), Row(null))
// No exception shows
val desc = spark.sql("DESC tabUnknownType").collect().toSeq
val desc = spark.sql("DESC tabNullType").collect().toSeq
assert(desc.contains(Row("col", NullType.simpleString, null)))
}
}

// Forbid CTAS with unknown type
// Forbid CTAS with null type
withTable("t1", "t2", "t3") {
val e1 = intercept[AnalysisException] {
spark.sql("CREATE TABLE t1 USING PARQUET AS SELECT null as null_col")
}.getMessage
assert(e1.contains("Cannot create tables with unknown type"))
assert(e1.contains("Cannot create tables with null type"))

val e2 = intercept[AnalysisException] {
spark.sql("CREATE TABLE t2 AS SELECT null as null_col")
}.getMessage
assert(e2.contains("Cannot create tables with unknown type"))
assert(e2.contains("Cannot create tables with null type"))

val e3 = intercept[AnalysisException] {
spark.sql("CREATE TABLE t3 STORED AS PARQUET AS SELECT null as null_col")
}.getMessage
assert(e3.contains("Cannot create tables with unknown type"))
assert(e3.contains("Cannot create tables with null type"))
}

// Forbid Replace table AS SELECT with unknown type
// Forbid Replace table AS SELECT with null type
withTable("t") {
val v2Source = classOf[FakeV2Provider].getName
val e = intercept[AnalysisException] {
spark.sql(s"CREATE OR REPLACE TABLE t USING $v2Source AS SELECT null as null_col")
}.getMessage
assert(e.contains("Cannot create tables with unknown type"))
assert(e.contains("Cannot create tables with null type"))
}

// Forbid creating table with VOID type in Spark
withTable("t1", "t2", "t3", "t4") {
val e1 = intercept[AnalysisException] {
spark.sql(s"CREATE TABLE t1 (v VOID) USING PARQUET")
}.getMessage
assert(e1.contains("Cannot create tables with unknown type"))
assert(e1.contains("Cannot create tables with null type"))
val e2 = intercept[AnalysisException] {
spark.sql(s"CREATE TABLE t2 (v VOID) USING hive")
}.getMessage
assert(e2.contains("Cannot create tables with unknown type"))
assert(e2.contains("Cannot create tables with null type"))
val e3 = intercept[AnalysisException] {
spark.sql(s"CREATE TABLE t3 (v VOID)")
}.getMessage
assert(e3.contains("Cannot create tables with unknown type"))
assert(e3.contains("Cannot create tables with null type"))
val e4 = intercept[AnalysisException] {
spark.sql(s"CREATE TABLE t4 (v VOID) STORED AS PARQUET")
}.getMessage
assert(e4.contains("Cannot create tables with unknown type"))
assert(e4.contains("Cannot create tables with null type"))
}

// Forbid Replace table with VOID type
Expand All @@ -2376,7 +2376,7 @@ class HiveDDLSuite
val e = intercept[AnalysisException] {
spark.sql(s"CREATE OR REPLACE TABLE t (v VOID) USING $v2Source")
}.getMessage
assert(e.contains("Cannot create tables with unknown type"))
assert(e.contains("Cannot create tables with null type"))
}

// Make sure spark.catalog.createTable with null type will fail
Expand Down Expand Up @@ -2413,7 +2413,7 @@ class HiveDDLSuite
schema = schema,
options = Map("fileFormat" -> "parquet"))
}.getMessage
assert(e.contains("Cannot create tables with unknown type"))
assert(e.contains("Cannot create tables with null type"))
}
}

Expand All @@ -2426,7 +2426,7 @@ class HiveDDLSuite
schema = schema,
options = Map.empty[String, String])
}.getMessage
assert(e.contains("Cannot create tables with unknown type"))
assert(e.contains("Cannot create tables with null type"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class HiveOrcSourceSuite extends OrcSuite with TestHiveSingleton {
msg = intercept[AnalysisException] {
sql("select null").write.mode("overwrite").orc(orcDir)
}.getMessage
assert(msg.contains("ORC data source does not support unknown data type."))
assert(msg.contains("ORC data source does not support null data type."))

msg = intercept[AnalysisException] {
spark.udf.register("testType", () => new IntervalData())
Expand Down