[CARBONDATA-2013] executing Alter rename on non-carbon table , gives table can not found in database
This closes #1783 Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/7b5db580 Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/7b5db580 Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/7b5db580 Branch: refs/heads/carbonstore Commit: 7b5db58052c30ce08543d19e2431e3de361dfadb Parents: 770deb8 Author: kushalsaha <[email protected]> Authored: Tue Jan 9 22:41:10 2018 +0530 Committer: Venkata Ramana G <[email protected]> Committed: Wed Jan 17 14:36:32 2018 +0530 ---------------------------------------------------------------------- .../execution/strategy/StreamingTableStrategy.scala | 13 +++++++++---- .../vectorreader/AddColumnTestCases.scala | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/carbondata/blob/7b5db580/integration/spark2/src/main/scala/org/apache/spark/sql/execution/strategy/StreamingTableStrategy.scala ---------------------------------------------------------------------- diff --git a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/strategy/StreamingTableStrategy.scala b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/strategy/StreamingTableStrategy.scala index d08ef26..608ec60 100644 --- a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/strategy/StreamingTableStrategy.scala +++ b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/strategy/StreamingTableStrategy.scala @@ -61,8 +61,7 @@ private[sql] class StreamingTableStrategy(sparkSession: SparkSession) extends Sp Nil case AlterTableRenameCommand(oldTableIdentifier, _, _) => rejectIfStreamingTable( - oldTableIdentifier, - "Alter rename table") + oldTableIdentifier, "Alter rename table") Nil case _ => Nil } @@ -72,9 +71,15 @@ private[sql] class StreamingTableStrategy(sparkSession: SparkSession) extends Sp * Validate whether Update operation is allowed for specified table in the command */ private def rejectIfStreamingTable(tableIdentifier: TableIdentifier, operation: String): Unit = { - val streaming = - CarbonEnv.getCarbonTable(tableIdentifier.database, tableIdentifier.table)(sparkSession) + var streaming = false + try { + streaming = CarbonEnv.getCarbonTable( + tableIdentifier.database, tableIdentifier.table)(sparkSession) .isStreamingTable + } catch { + case e: Exception => + streaming = false + } if (streaming) { throw new MalformedCarbonCommandException( s"$operation is not allowed for streaming table") http://git-wip-us.apache.org/repos/asf/carbondata/blob/7b5db580/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AddColumnTestCases.scala ---------------------------------------------------------------------- diff --git a/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AddColumnTestCases.scala b/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AddColumnTestCases.scala index e32ca04..9a87653 100644 --- a/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AddColumnTestCases.scala +++ b/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AddColumnTestCases.scala @@ -656,6 +656,19 @@ class AddColumnTestCases extends Spark2QueryTest with BeforeAndAfterAll { sql("drop table if exists preagg1") } + test("test rename textFileTable") { + sql("drop table if exists renameTextFileTable") + sql("drop table if exists new_renameTextFileTable") + sql("create table renameTextFileTable (id int,time string) row format delimited fields terminated by ',' stored as textfile ") + sql("alter table renameTextFileTable rename to new_renameTextFileTable") + checkAnswer(sql("DESC new_renameTextFileTable"),Seq(Row("id","int",null),Row("time","string",null))) + intercept[Exception] { + sql("select * from renameTextFileTable") + } + sql("drop table if exists new_renameTextFileTable") + sql("drop table if exists renameTextFileTable") + } + override def afterAll { sql("DROP TABLE IF EXISTS addcolumntest") sql("DROP TABLE IF EXISTS hivetable") @@ -670,6 +683,8 @@ class AddColumnTestCases extends Spark2QueryTest with BeforeAndAfterAll { sql("DROP TABLE IF EXISTS alter_sort_columns") sql("DROP TABLE IF EXISTS alter_no_dict") sql("drop table if exists NO_INVERTED_CARBON") + sql("drop table if exists new_renameTextFileTable") + sql("drop table if exists renameTextFileTable") sqlContext.setConf("carbon.enable.vector.reader", "false") CarbonProperties.getInstance().addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT)
