This is an automated email from the ASF dual-hosted git repository.
akashrn5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/carbondata.git
The following commit(s) were added to refs/heads/master by this push:
new 91f1b69 [CARBONDATA-4124] Fix Refresh MV which does not exist error
message
91f1b69 is described below
commit 91f1b69857cae61b68fec1df5f7a52f9b1d9d850
Author: Indhumathi27 <[email protected]>
AuthorDate: Tue Feb 9 11:01:54 2021 +0530
[CARBONDATA-4124] Fix Refresh MV which does not exist error message
Why is this PR needed?
Refreshing MV which does not exist, is not throwing proper carbon error
message.
It throws Table NOT found message from Spark. This is because, getSchema is
returning null, if schema is not present.
What changes were proposed in this PR?
1. Check If getSchema is null and throw No such MV exception.
2. While drop table, drop mv and then drop fact table from metastore, to
avoid
getting Nullpointer exception, when trying to access fact table while drop
MV.
Does this PR introduce any user interface change?
No
Is any new testcase added?
Yes
This closes #4091
---
.../sql/execution/command/table/CarbonDropTableCommand.scala | 6 ++++--
.../sql/execution/command/view/CarbonRefreshMVCommand.scala | 12 +++++-------
.../carbondata/view/rewrite/TestAllOperationsOnMV.scala | 6 ++++++
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonDropTableCommand.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonDropTableCommand.scala
index 35ecb21..f54ff59 100644
---
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonDropTableCommand.scala
+++
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonDropTableCommand.scala
@@ -99,8 +99,6 @@ case class CarbonDropTableCommand(
isInternalCall)
OperationListenerBus.getInstance.fireEvent(dropTablePreEvent,
operationContext)
-
CarbonEnv.getInstance(sparkSession).carbonMetaStore.dropTable(identifier)(sparkSession)
-
val viewManager = MVManagerInSpark.get(sparkSession)
val viewSchemas = viewManager.getSchemasOnTable(carbonTable)
if (!viewSchemas.isEmpty) {
@@ -117,6 +115,10 @@ case class CarbonDropTableCommand(
viewDropCommands.foreach(_.processMetadata(sparkSession))
}
+ // drop mv and then drop fact table from metastore, to avoid getting NPE,
+ // when trying to access fact table during drop MV operation.
+
CarbonEnv.getInstance(sparkSession).carbonMetaStore.dropTable(identifier)(sparkSession)
+
// fires the event after dropping main table
val dropTablePostEvent: DropTablePostEvent =
DropTablePostEvent(
diff --git
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonRefreshMVCommand.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonRefreshMVCommand.scala
index ab43241..ef7ca64 100644
---
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonRefreshMVCommand.scala
+++
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonRefreshMVCommand.scala
@@ -21,7 +21,7 @@ import org.apache.spark.sql.{CarbonEnv, Row, SparkSession}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.execution.command.DataCommand
-import
org.apache.carbondata.common.exceptions.sql.{MalformedMVCommandException,
NoSuchMVException}
+import org.apache.carbondata.common.exceptions.sql.MalformedMVCommandException
import org.apache.carbondata.core.view.MVStatus
import org.apache.carbondata.events.{OperationContext, OperationListenerBus}
import org.apache.carbondata.view.{MVHelper, MVManagerInSpark, MVRefresher,
RefreshMVPostExecutionEvent, RefreshMVPreExecutionEvent}
@@ -39,12 +39,10 @@ case class CarbonRefreshMVCommand(
val databaseName =
databaseNameOption.getOrElse(session.sessionState.catalog.getCurrentDatabase)
val viewManager = MVManagerInSpark.get(session)
- val schema = try {
- viewManager.getSchema(databaseName, mvName)
- } catch {
- case _: NoSuchMVException =>
- throw new MalformedMVCommandException(
- s"Materialized view ${ databaseName }.${ mvName } does not exist")
+ val schema = viewManager.getSchema(databaseName, mvName)
+ if (schema == null) {
+ throw new MalformedMVCommandException(
+ s"Materialized view $databaseName.$mvName does not exist")
}
// refresh table property of parent table if needed
diff --git
a/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestAllOperationsOnMV.scala
b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestAllOperationsOnMV.scala
index 6dfe894..167d628 100644
---
a/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestAllOperationsOnMV.scala
+++
b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestAllOperationsOnMV.scala
@@ -702,6 +702,12 @@ class TestAllOperationsOnMV extends QueryTest with
BeforeAndAfterEach {
sql("drop table IF EXISTS maintable")
}
+ test("test refresh mv which does not exists") {
+ intercept[MalformedMVCommandException] {
+ sql("refresh materialized view does_not_exist")
+ }.getMessage.contains("Materialized view default.does_not_exist does not
exist")
+ }
+
test("drop meta cache on mv materialized view table") {
defaultConfig()
sql("drop table IF EXISTS maintable")