[GitHub] [carbondata] ravipesala commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv

2019-05-09 Thread GitBox
ravipesala 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_r282552675
 
 

 ##
 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:
   Don't put mv name here, just check for child tables and throw exception.


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] ravipesala commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv

2019-05-09 Thread GitBox
ravipesala 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_r282552816
 
 

 ##
 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:
   CarbonTable should not have this method, 


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] ravipesala commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv

2019-05-09 Thread GitBox
ravipesala 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_r282552106
 
 

 ##
 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] ravipesala commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv

2019-04-29 Thread GitBox
ravipesala 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_r279301188
 
 

 ##
 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:
   I am confused about why so much code is added for each plan. I think it 
should be handled generic enough for most of the plans


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] ravipesala commented on a change in pull request #3184: [CARBONDATA-3357] Support TableProperties from single parent table and restrict alter/delete/partition on mv

2019-04-29 Thread GitBox
ravipesala 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_r279300690
 
 

 ##
 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 {
+  case Project(projectList, logicalPlan: LogicalPlan) =>
+getFieldsFromProject(projectList, logicalPlan, selectStmt, 
sparkSession)
+  case Aggregate(groupByExp, aggExp, SubqueryAlias(_, logicalRelation: 
LogicalRelation)) =>
+getFieldsFromAggregate(groupByExp, aggExp, logicalRelation, selectStmt)
+  case Aggregate(groupByExp, aggExp, logicalRelation: LogicalRelation) =>
+getFieldsFromAggregate(groupByExp, aggExp, logicalRelation, selectStmt)
+  case Aggregate(groupByExp, aggExp, join: Join) =>
+getFieldsFromPlanAggregateWithJoin(groupByExp, aggExp, join, Seq.empty)
+  case Aggregate(groupByExp, aggExp, filter: Filter) =>
+getFieldsFromPlanAggreagteWithFilter(groupByExp, aggExp, filter)
+}
+  }
+
+  /**
+   * Collect Project, Filter and sort List attributes from plan and return 
fieldToDataMapField map
+   */
+  def getFieldsFromProject(projectList: Seq[NamedExpression],
+  child: LogicalPlan,
+  selectStmt: String,
+  sparkSession: SparkSession): mutable.LinkedHashMap[Field, DataMapField] 
= {
+var fieldToDataMapFieldMap = 
scala.collection.mutable.LinkedHashMap.empty[Field, DataMapField]
+var logicalRelation: LogicalRelation = null
+var filterList: Seq[AttributeReference] = Seq.empty
+var sortList: Seq[AttributeReference] = Seq.empty
+if (!child.isInstanceOf[Join]) {
+  child.transform {
+case lr: LogicalRelation =>
+  logicalRelation = lr
+  lr
+  }
+} else {
+  val condition = child.asInstanceOf[Join].condition
+  return getFieldsFromPlanJoin(child, projectList, filterList, sortList, 
condition)
+}
+child match {
+  case sort: Sort =>
+// collect sort attributes list
+sort.order.map { s =>
+  s.collect {
+case attr: AttributeReference =>
+  sortList = sortList.+:(attr)
+  }
+}
+sort.transformDown {
+  case agg@Aggregate(groupByExp,
+  aggExp, SubqueryAlias(_, logicalRelation: LogicalRelation)) =>
+fieldToDataMapFieldMap = fieldToDataMapFieldMap ++ 
getFieldsFromAggregate(groupByExp,
+  aggExp,
+  logicalRelation,
+  selectStmt)
+agg
+  case agg1@Aggregate(groupByExp, aggExp, logicalRelation: 
LogicalRelation) =>
+fieldToDataMapFieldMap = fieldToDataMapFieldMap ++ 
getFieldsFromAggregate(groupByExp,
+  aggExp,
+  logicalRelation,
+  selectStmt)
+agg1
+}
+  case filter: Filter =>
+