Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
52ca902
alter_add_col: initial changes
xwu0226 Nov 21, 2016
f498fa6
add testcases
xwu0226 Dec 1, 2016
522443e
negative testcases
xwu0226 Dec 1, 2016
1af2654
remove non-support testcase
xwu0226 Dec 5, 2016
ec57ee9
fix testcase
xwu0226 Dec 5, 2016
ec74849
update testcases
xwu0226 Dec 7, 2016
8fca889
update testcases
xwu0226 Dec 7, 2016
4a17529
update testcases
xwu0226 Jan 13, 2017
9699128
comments for command caseclass
xwu0226 Jan 20, 2017
9860e5c
udate comments based on review
xwu0226 Jan 21, 2017
dfff364
SPARK-19261: update to support datasource table and add new testcases
xwu0226 Feb 3, 2017
9f23254
remove workaournd for parquet issue since parquet-1.8.2 is now supported
xwu0226 Feb 4, 2017
180092f
SPARK-19261: using white list for datasource table types that support…
xwu0226 Feb 7, 2017
5a8aa80
fix code style
xwu0226 Feb 7, 2017
d3860e6
fix coding style
xwu0226 Feb 7, 2017
55577aa
update upon review
xwu0226 Feb 24, 2017
6fa913a
refactor code from alterTable function
xwu0226 Feb 25, 2017
7231efe
rebase and resolve conflict
xwu0226 Mar 6, 2017
e4e9ecf
resolve conflicts
xwu0226 Mar 9, 2017
75e7441
using ExternalCatalog.alterTableSchema
xwu0226 Mar 14, 2017
9847030
add InMemoryCatalog testcases
xwu0226 Mar 15, 2017
1a383bb
revert change in HiveExernalCatalog.scala
xwu0226 Mar 15, 2017
f994ce9
update upon review
xwu0226 Mar 16, 2017
5bf7360
add checking for duplicate column names
xwu0226 Mar 16, 2017
599c45e
add case sensativity for duplicate name checking and new testcases
xwu0226 Mar 16, 2017
b3edfea
typo
xwu0226 Mar 16, 2017
7d8a515
resolve conflicts and modify testcases
xwu0226 Mar 17, 2017
e895278
update testcases
xwu0226 Mar 17, 2017
e171ac4
move checkduplicate and schema arrangement to SessionCatalog.alterTab…
xwu0226 Mar 17, 2017
4391edd
change SessionCatalog.alterTableAddColumn back to alterTableSchema
xwu0226 Mar 18, 2017
a3fef12
update upon review comments
xwu0226 Mar 18, 2017
1eb7cd3
some minor updates upon review comments
xwu0226 Mar 19, 2017
04ce8f4
update based on review
xwu0226 Mar 21, 2017
7d8437d
update on minor comments
xwu0226 Mar 21, 2017
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
Prev Previous commit
Next Next commit
resolve conflicts and modify testcases
  • Loading branch information
xwu0226 committed Mar 19, 2017
commit 7d8a515b8327d8aec7340cc4d185bf7b2ec8c9be
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser
import org.apache.spark.sql.catalyst.plans.PlanTest
import org.apache.spark.sql.catalyst.plans.logical.{Range, SubqueryAlias, View}
import org.apache.spark.sql.types.IntegerType
import org.apache.spark.sql.types.{IntegerType, StructField, StructType}

class InMemorySessionCatalogSuite extends SessionCatalogSuite {
protected val utils = new CatalogTestUtils {
Expand Down Expand Up @@ -452,14 +452,23 @@ abstract class SessionCatalogSuite extends PlanTest {
}

test("alter table add columns") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a negative test case for dropping columns, although we do not support it now.

val externalCatalog = newBasicCatalog()
val sessionCatalog = new SessionCatalog(externalCatalog)
sessionCatalog.createTable(newTable("t1", "default"), ignoreIfExists = false)
val oldTab = externalCatalog.getTable("default", "t1")
sessionCatalog.alterTableSchema(TableIdentifier("t1", Some("default")),
oldTab.schema.add("c3", IntegerType))
val newTab = externalCatalog.getTable("default", "t1")
assert(newTab.schema.equals(oldTab.schema.add("c3", IntegerType)))
withBasicCatalog { sessionCatalog =>
sessionCatalog.createTable(newTable("t1", "default"), ignoreIfExists = false)
val oldTab = sessionCatalog.externalCatalog.getTable("default", "t1")
sessionCatalog.alterTableSchema(TableIdentifier("t1", Some("default")),
oldTab.schema.add("c3", IntegerType))
val newTab = sessionCatalog.externalCatalog.getTable("default", "t1")
if (sessionCatalog.externalCatalog.isInstanceOf[InMemoryCatalog]) {
assert(newTab.schema.toString == oldTab.schema.add("c3", IntegerType).toString)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why compare the schema with toString?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StructField returned from CatalogTable has metadata field that contains some hive related information, which the manually added schema field does not have. So directly comparing 2 StructType returns false. toString method of StructField does not include metadata field.. But I think this may not be a good way to test anyway.. I will modify this test case..

} else {
// HiveExternalCatalog will always arrange the partition columns to the end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to do this(arrange the partition columns to the end) in SessionCatalog.alterTableSchema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Thanks!

val oldTabSchema = StructType(oldTab.schema.take(
oldTab.schema.length - oldTab.partitionColumnNames.length) ++
Seq(StructField("c3", IntegerType)) ++
oldTab.schema.takeRight(oldTab.partitionColumnNames.length))
assert(newTab.schema.toString == oldTabSchema.toString)
}
}
}

test("get table") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,28 @@ class InMemoryCatalogedDDLSuite extends DDLSuite with SharedSQLContext with Befo
assert(e.contains("Hive support is required to CREATE Hive TABLE (AS SELECT)"))
}
}

Seq("true", "false").foreach { caseSensitive =>
test(s"alter table add columns with existing column name - caseSensitive $caseSensitive") {
withSQLConf(("spark.sql.caseSensitive", caseSensitive)) {
withTable("t1") {
sql("CREATE TABLE t1 (c1 int) USING PARQUET")
if (caseSensitive == "false") {
val e = intercept[AnalysisException] {
sql("ALTER TABLE t1 ADD COLUMNS (C1 string)")
}.getMessage
assert(e.contains("Found duplicate column(s)"))
} else {
// hive catalog will still complains that c1 is duplicate column name because hive
// identifiers are case insensitive.
sql("ALTER TABLE t1 ADD COLUMNS (C1 string)")
assert(sql("SELECT * FROM t1").schema
.equals(new StructType().add("c1", IntegerType).add("C1", StringType)))
}
}
}
}
}
}

abstract class DDLSuite extends QueryTest with SQLTestUtils {
Expand Down Expand Up @@ -2269,26 +2291,6 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
}
}

Seq("true", "false").foreach { caseSensitive =>
test(s"alter table add columns with existing column name - caseSensitive $caseSensitive") {
withSQLConf(("spark.sql.caseSensitive", caseSensitive)) {
withTable("t1") {
sql("CREATE TABLE t1 (c1 int) USING PARQUET")
if (caseSensitive == "false") {
val e = intercept[AnalysisException] {
sql("ALTER TABLE t1 ADD COLUMNS (C1 string)")
}.getMessage
assert(e.contains("Found duplicate column(s)"))
} else {
sql("ALTER TABLE t1 ADD COLUMNS (C1 string)")
assert(sql("SELECT * FROM t1").schema
.equals(new StructType().add("c1", IntegerType).add("C1", StringType)))
}
}
}
}
}

test("alter table add columns to table referenced by a view") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed, the view test already covered the case when the referenced table change its schema

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I will remove this test.

withTable("t1") {
withView("v1") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1940,4 +1940,25 @@ class HiveDDLSuite
assert(e.contains("Found duplicate column(s)"))
}
}

Seq("true", "false").foreach { caseSensitive =>
test(s"alter table add columns with existing column name - caseSensitive $caseSensitive") {
withSQLConf(("spark.sql.caseSensitive", caseSensitive)) {
withTable("t1") {
sql("CREATE TABLE t1 (c1 int) USING PARQUET")
if (caseSensitive == "false") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!caseSensitive)

val e = intercept[AnalysisException] {
sql("ALTER TABLE t1 ADD COLUMNS (C1 string)")
}.getMessage
assert(e.contains("Found duplicate column(s)"))
} else {
val e = intercept[AnalysisException] {
sql("ALTER TABLE t1 ADD COLUMNS (C1 string)")
}.getMessage
assert(e.contains("HiveException"))
}
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still can combine it with the one in InMemoryCatalogedDDLSuite by using isUsingHiveMetastore

}