Indhumathi27 commented on a change in pull request #3184: [CARBONDATA-3357] 
Support TableProperties from single parent table and restrict 
alter/delete/partition on mv
URL: https://github.com/apache/carbondata/pull/3184#discussion_r282590280
 
 

 ##########
 File path: 
integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/mv/DataMapListeners.scala
 ##########
 @@ -139,3 +148,130 @@ object LoadPostDataMapListener extends 
OperationEventListener {
     }
   }
 }
+
+/**
+ * Listeners to block operations like delete segment on id or by date on tables
+ * having an mv datamap or on mv datamap tables
+ */
+object DataMapDeleteSegmentPreListener extends OperationEventListener {
+  /**
+   * Called on a specified event occurrence
+   *
+   * @param event
+   * @param operationContext
+   */
+  override def onEvent(event: Event, operationContext: OperationContext): Unit 
= {
+    val carbonTable = event match {
+      case e: DeleteSegmentByIdPreEvent =>
+        e.asInstanceOf[DeleteSegmentByIdPreEvent].carbonTable
+      case e: DeleteSegmentByDatePreEvent =>
+        e.asInstanceOf[DeleteSegmentByDatePreEvent].carbonTable
+    }
+    if (null != carbonTable) {
+      if (CarbonTable.hasMVDataMap(carbonTable)) {
+        throw new UnsupportedOperationException(
+          "Delete segment operation is not supported on tables which have mv 
datamap")
+      }
+      if (DataMapUtil.isMVDataMapTable(carbonTable)) {
+        throw new UnsupportedOperationException(
+          "Delete segment operation is not supported on mv table")
+      }
+    }
+  }
+}
+
+object DataMapAddColumnsPreListener extends OperationEventListener {
+  /**
+   * Called on a specified event occurrence
+   *
+   * @param event
+   * @param operationContext
+   */
+  override def onEvent(event: Event, operationContext: OperationContext): Unit 
= {
+    val dataTypeChangePreListener = 
event.asInstanceOf[AlterTableAddColumnPreEvent]
+    val carbonTable = dataTypeChangePreListener.carbonTable
+    if (DataMapUtil.isMVDataMapTable(carbonTable)) {
+      throw new UnsupportedOperationException(
+        s"Cannot add columns in MV DataMap table ${
+          carbonTable.getDatabaseName
+        }.${ carbonTable.getTableName }")
+    }
+  }
+}
+
+
+object DataMapDropColumnPreListener extends OperationEventListener {
+  /**
+   * Called on a specified event occurrence
+   *
+   * @param event
+   * @param operationContext
+   */
+  override def onEvent(event: Event, operationContext: OperationContext): Unit 
= {
+    val dropColumnChangePreListener = 
event.asInstanceOf[AlterTableDropColumnPreEvent]
+    val carbonTable = dropColumnChangePreListener.carbonTable
+    val alterTableDropColumnModel = 
dropColumnChangePreListener.alterTableDropColumnModel
+    val columnsToBeDropped = alterTableDropColumnModel.columns
+    if (CarbonTable.hasMVDataMap(carbonTable)) {
+      val dataMapSchemaList = DataMapStoreManager.getInstance
+        .getDataMapSchemasOfTable(carbonTable).asScala
+      for (dataMapSchema <- dataMapSchemaList) {
+        if (null != dataMapSchema && !dataMapSchema.isIndexDataMap) {
+          val listOfColumns = 
DataMapListeners.getDataMapTableColumns(dataMapSchema, carbonTable)
+          val columnExistsInChild = listOfColumns.collectFirst {
+            case parentColumnName if 
columnsToBeDropped.contains(parentColumnName) =>
+              parentColumnName
+          }
+          if (columnExistsInChild.isDefined) {
+            throw new UnsupportedOperationException(
+              s"Column ${ columnExistsInChild.head } cannot be dropped because 
it exists " +
+              s"in mv datamap ${ dataMapSchema.getRelationIdentifier.toString 
}")
+          }
+        }
+      }
+    }
+    if (DataMapUtil.isMVDataMapTable(carbonTable)) {
+      throw new UnsupportedOperationException(
+        s"Cannot drop columns present in MV datamap table ${ 
carbonTable.getDatabaseName }." +
+        s"${ carbonTable.getTableName }")
+    }
+  }
+}
+
+object DataMapChangeDataTypeorRenameColumnPreListener
+  extends OperationEventListener {
+  /**
+   * Called on a specified event occurrence
+   *
+   * @param event
+   * @param operationContext
+   */
+  override def onEvent(event: Event, operationContext: OperationContext): Unit 
= {
+    val colRenameDataTypeChangePreListener = event
+      .asInstanceOf[AlterTableColRenameAndDataTypeChangePreEvent]
+    val carbonTable = colRenameDataTypeChangePreListener.carbonTable
+    val alterTableDataTypeChangeModel = colRenameDataTypeChangePreListener
+      .alterTableDataTypeChangeModel
+    val columnToBeAltered: String = alterTableDataTypeChangeModel.columnName
+    if (CarbonTable.hasMVDataMap(carbonTable)) {
+      val dataMapSchemaList = DataMapStoreManager.getInstance
+        .getDataMapSchemasOfTable(carbonTable).asScala
+      for (dataMapSchema <- dataMapSchemaList) {
+        if (null != dataMapSchema && !dataMapSchema.isIndexDataMap) {
+          val listOfColumns = 
DataMapListeners.getDataMapTableColumns(dataMapSchema, carbonTable)
+          if (listOfColumns.contains(columnToBeAltered)) {
+            throw new UnsupportedOperationException(
+              s"Column $columnToBeAltered exists in a MV datamap. Drop MV 
datamap to " +
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to