Github user jackylk commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2579#discussion_r206903988
  
    --- Diff: 
datamap/mv/core/src/main/scala/org/apache/carbondata/mv/datamap/MVAnalyzerRule.scala
 ---
    @@ -80,26 +83,54 @@ class MVAnalyzerRule(sparkSession: SparkSession) 
extends Rule[LogicalPlan] {
       }
     
       def isValidPlan(plan: LogicalPlan, catalog: SummaryDatasetCatalog): 
Boolean = {
    -    !plan.isInstanceOf[Command] && !isDataMapExists(plan, 
catalog.listAllSchema()) &&
    -    !plan.isInstanceOf[DeserializeToObject]
    +    if (!plan.isInstanceOf[Command]  && 
!plan.isInstanceOf[DeserializeToObject]) {
    +      val catalogs = extractCatalogs(plan)
    +      !isDataMapReplaced(catalog.listAllValidSchema(), catalogs) &&
    +      isDataMapExists(catalog.listAllValidSchema(), catalogs)
    +    } else {
    +      false
    +    }
    +
       }
       /**
        * Check whether datamap table already updated in the query.
        *
    -   * @param plan
        * @param mvs
        * @return
        */
    -  def isDataMapExists(plan: LogicalPlan, mvs: Array[SummaryDataset]): 
Boolean = {
    -    val catalogs = plan collect {
    -      case l: LogicalRelation => l.catalogTable
    -    }
    -    catalogs.isEmpty || catalogs.exists { c =>
    +  def isDataMapReplaced(
    +      mvs: Array[SummaryDataset],
    +      catalogs: Seq[Option[CatalogTable]]): Boolean = {
    +    catalogs.exists { c =>
           mvs.exists { mv =>
             val identifier = mv.dataMapSchema.getRelationIdentifier
             identifier.getTableName.equals(c.get.identifier.table) &&
             identifier.getDatabaseName.equals(c.get.database)
           }
         }
       }
    +
    +  /**
    +   * Check whether any suitable datamaps exists for this plan.
    --- End diff --
    
    suitable means matched plan?


---

Reply via email to