Uh oh!
There was an error while loading. Please reload this page.
[SPARK-28443][SQL] Spark sql add exception when create field type NullType - #25198
[SPARK-28443][SQL] Spark sql add exception when create field type NullType#25198ulysses-you wants to merge 15 commits into
Conversation
ulysses-you
commented
Jul 19, 2019
cc @cloud-fan |
maropu
commented
Jul 19, 2019
ok to test |
SparkQA
commented
Jul 19, 2019
Test build #107883 has finished for PR 25198 at commit
|
botekchristophe
commented
Jul 19, 2019
Looks like a good idea to check this when creating a table with NullType |
| object CreateTableCheck extends Rule[LogicalPlan] { | ||
| override def apply(plan: LogicalPlan): LogicalPlan = { | ||
| plan match { | ||
| case ct: CreateTable if ct.tableDesc.schema.exists { f => |
There was a problem hiding this comment.
can we move it to the rule PreWriteCheck?
There was a problem hiding this comment.
I consider that it's a little different between create table(DDL) and insert data (DML). Maybe split in two rules ?
There was a problem hiding this comment.
yea we can add a DDLCheck rule. Please follow PreWriteCheck to make it a pure-checking rule.
Also don't forget to handle DS v2 CREATE TABLE as well, which has a different logical plan.
CreateV2TableCreateTableAsSelectReplaceTableReplaceTableAsSelect
also cc @rdblue
There was a problem hiding this comment.
ok, I will check this later
SparkQA
commented
Jul 23, 2019
Test build #108054 has finished for PR 25198 at commit
|
| failAnalysis("DataType NullType is not supported for create table") | ||
| // DataSourceStrategy will convert CreateTable to CreateDataSourceTableCommand before check | ||
| case cdstc: CreateDataSourceTableCommand if cdstc.table.schema.exists { f => |
There was a problem hiding this comment.
I know this isn't much code, but I think it would be better to refactor this exists and the failAnalysis call into a method so it isn't repeated several times.
There was a problem hiding this comment.
Thanks for your advise.
SparkQA
commented
Jul 25, 2019
Test build #108135 has finished for PR 25198 at commit
|
SparkQA
commented
Aug 7, 2019
Test build #108758 has finished for PR 25198 at commit
|
| } | ||
| /** | ||
| * SPARK-28443: Spark sql add exception when create field type NullType |
There was a problem hiding this comment.
nit: SPARK-28443: fail the DDL command if it creates a table with null-type columns
| def failAnalysis(msg: String): Unit = { throw new AnalysisException(msg) } | ||
| def throwWhenExistsNullType(schema: StructType): Unit = { | ||
| if (schema.exists(f => DataTypes.NullType.sameType(f.dataType))) { |
There was a problem hiding this comment.
what about nested filed? Do other databases forbid it as well?
There was a problem hiding this comment.
Hive also forbid nested field with NullType
| case ReplaceTable(_, _, tableSchema, _, _, _) => | ||
| throwWhenExistsNullType(tableSchema) | ||
| case _ => // OK |
There was a problem hiding this comment.
CreateTableAsSelect, ReplaceTableAsSelect are missing.
There was a problem hiding this comment.
Spark allowed CreateTableAsSelect and ReplaceTableAsSelect with NullType, isn't it ?
E.g. create table test as select null as c1.
SparkQA
commented
Aug 8, 2019
Test build #108791 has finished for PR 25198 at commit
|
| case CreateTable(tableDesc, _, _) => | ||
| checkSchema(tableDesc.schema) | ||
| case CreateV2Table(_, _, tableSchema, _, _, _) => |
There was a problem hiding this comment.
I think the rationale here is that, we don't want to create tables with null type field. It should be same for both CREATE TABLE and CTAS.
There was a problem hiding this comment.
OK, and also add AlterTable.
SparkQA
commented
Aug 8, 2019
Test build #108811 has finished for PR 25198 at commit
|
| test("SPARK-28443: fail the DDL command if it creates a table with null-type columns") { | ||
| withTable("t") { | ||
| val e = intercept[AnalysisException]{ | ||
| sql(s"CREATE TABLE t as SELECT NULL AS c") |
There was a problem hiding this comment.
can we also test inner fields?
| fields.foreach{field => throwWhenExistsNullType(field.dataType)} | ||
| case other if other == NullType => | ||
| failAnalysis("DataType NullType is not supported for create table.") |
There was a problem hiding this comment.
how about "cannot create tables with null-type column/field"
| def failAnalysis(msg: String): Unit = { throw new AnalysisException(msg) } | ||
| def throwWhenExistsNullType(dataType: DataType): Unit = { |
| } | ||
| } | ||
| test("SPARK-28443: fail the DDL command if it creates a table with null-type columns") { |
There was a problem hiding this comment.
BTW do we need this test? I think https://github.com/apache/spark/pull/25198/files#diff-85f240f8452fa64de6671e41801fe68fR550 is good enough.
There was a problem hiding this comment.
I forget that spark not support create table t as select null as c now. Remove this.
SparkQA
commented
Aug 8, 2019
Test build #108833 has finished for PR 25198 at commit
|
SparkQA
commented
Aug 9, 2019
Test build #108848 has finished for PR 25198 at commit
|
ulysses-you
commented
Aug 12, 2019
ping @cloud-fan |
SparkQA
commented
Sep 30, 2019
Test build #111595 has finished for PR 25198 at commit
|
6a1b4f5 to
358e2a2CompareSparkQA
commented
Sep 30, 2019
Test build #111605 has finished for PR 25198 at commit
|
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable. |
What changes were proposed in this pull request?
More detail see 25085.
This PR is to discuss details that
add exception when create field type NullTypeNow, it's ok to create table like:
But it's not the spark idea
How was this patch tested?
UT