[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv
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
[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv
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_r282591445 ## 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)) { Review comment: Moved to integration/spark2/src/main/scala/org/apache/spark/util/DataMapUtil.scala 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv
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_r282590217 ## 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") 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv
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_r281238858 ## File path: core/src/main/java/org/apache/carbondata/core/datamap/DataMapUtil.java ## @@ -159,4 +160,13 @@ private static DistributableDataMapFormat createDataMapJob(CarbonTable carbonTab return ssm.getValidAndInvalidSegments(); } + /** + * Check if carbonTable is mv datamap table + */ + public static Boolean isMVdatamapTable(CarbonTable carbonTable) { 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv
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_r280009199 ## File path: datamap/mv/core/src/main/scala/org/apache/carbondata/mv/datamap/MVUtil.scala ## @@ -0,0 +1,615 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.carbondata.mv.datamap + +import scala.collection.mutable +import scala.collection.mutable.ArrayBuffer + +import org.apache.spark.sql.{CarbonDatasourceHadoopRelation, SparkSession} +import org.apache.spark.sql.catalyst.expressions._ +import org.apache.spark.sql.catalyst.expressions.aggregate._ +import org.apache.spark.sql.catalyst.plans.logical._ +import org.apache.spark.sql.execution.command.{ColumnTableRelation, DataMapField, Field} +import org.apache.spark.sql.execution.datasources.LogicalRelation +import org.apache.spark.sql.types.DataType + +import org.apache.carbondata.core.metadata.schema.table.CarbonTable +import org.apache.carbondata.mv.plans.util.ExtractSelectModule +import org.apache.carbondata.spark.util.CommonUtil + +/** + * Utility class for keeping all the utility method for mv datamap + */ +object MVUtil { + + /** + * Below method will be used to validate and get the required fields from select plan + */ + def getFieldsAndDataMapFieldsFromPlan(plan: LogicalPlan, + selectStmt: String, + sparkSession: SparkSession): scala.collection.mutable.LinkedHashMap[Field, DataMapField] = { +plan match { Review comment: ok.. Now handled generic for most of the plans to get FieldToDataMapFieldMap.. Please check 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: us...@infra.apache.org With regards, Apache Git Services