You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by qi...@apache.org on 2020/04/26 12:11:16 UTC

[carbondata] branch master updated: [CARBONDATA-3776] Clean old materialized view implementation

This is an automated email from the ASF dual-hosted git repository.

qiangcai 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 bc76f19  [CARBONDATA-3776] Clean old materialized view implementation
bc76f19 is described below

commit bc76f1933ea32d1633cc85a425851380a5a85299
Author: liuzhi <37...@qq.com>
AuthorDate: Fri Apr 3 09:09:24 2020 +0800

    [CARBONDATA-3776] Clean old materialized view implementation
    
    Why is this PR needed?
    After the materialized view is separated from the DataMap module, the old materialized view implementation in DataMap module is not used. Should clean those code to keep code clean.
    
    What changes were proposed in this PR?
    Move materialized view test case to carbondata-spark module.
    Remove carbondata-mv-core module, because of the main code in this module have moved to carbondata-spark module.
    Remove old materialized view metadata manage implementation which doesn't support multi-tenant.
    
    This closes #3692
---
 .../core/constants/CarbonCommonConstants.java      |  10 -
 .../carbondata/core/index/CarbonIndexProvider.java | 416 ----------
 .../carbondata/core/index/IndexStoreManager.java   | 148 ----
 .../apache/carbondata/core/index/MVCatalog.java    |  56 --
 .../index/status/DatabaseIndexStatusProvider.java  |  49 --
 .../index/status/DiskBasedIndexStatusProvider.java | 257 ------
 .../core/index/status/IndexStatusDetail.java       |  62 --
 .../core/index/status/IndexStatusManager.java      | 198 -----
 .../index/status/IndexStatusStorageProvider.java   |  51 --
 .../core/index/status/MVSegmentStatusUtil.java     |  78 --
 .../metadata/schema/index/IndexClassProvider.java  |  66 --
 .../core/metadata/schema/index/MVProviderName.java |  22 -
 .../core/metadata/schema/table/CarbonTable.java    |  28 -
 .../table/DatabaseIndexSchemaStorageProvider.java  |  57 --
 .../table/DiskBasedIndexSchemaStorageProvider.java | 229 ------
 .../core/metadata/schema/table/IndexSchema.java    | 155 ----
 .../metadata/schema/table/IndexSchemaFactory.java  |  37 -
 .../schema/table/IndexSchemaStorageProvider.java   |  68 --
 .../DiskBasedDMSchemaStoraheProviderSuite.java     | 188 -----
 .../org/apache/carbondata/index/IndexManager.java  |  59 --
 .../org/apache/carbondata/index/IndexProvider.java |  40 +-
 .../spark/rdd/CarbonDataRDDFactory.scala           |   3 +-
 .../scala/org/apache/spark/sql/CarbonEnv.scala     |   3 +-
 .../command/index/CarbonCreateIndexCommand.scala   |   3 +-
 .../command/management/CarbonAddLoadCommand.scala  |   1 -
 .../CarbonAlterTableCompactionCommand.scala        |   1 -
 .../mutation/CarbonProjectForDeleteCommand.scala   |   4 -
 .../mutation/CarbonProjectForUpdateCommand.scala   |   5 +-
 .../schema/CarbonAlterTableRenameCommand.scala     |   2 +-
 .../spark/sql/execution/strategy/DDLHelper.scala   |   4 -
 .../spark/sql/hive/CarbonAnalysisRules.scala       |   2 -
 .../sql/listeners/DropCacheEventListeners.scala    |  20 +-
 .../sql/listeners/ShowCacheEventListener.scala     |  59 ++
 .../sql/listeners/ShowCacheEventListeners.scala    |  94 ---
 .../index/bloom/BloomCoarseGrainIndexSuite.scala   |   2 +-
 .../index/lucene/LuceneFineGrainIndexSuite.scala   |   5 +-
 .../RangeFilterAllDataTypesTestCases.scala         |   3 +
 .../spark/testsuite/index/CGIndexTestCase.scala    |   4 +-
 .../scala/org/apache/carbondata/view/MVTest.scala  |  16 +
 .../view}/plans/ExtractJoinConditionsSuite.scala   |   7 +-
 .../carbondata/view}/plans/IsSPJGHSuite.scala      |   9 +-
 .../view}/plans/LogicalToModularPlanSuite.scala    |  11 +-
 .../carbondata/view}/plans/ModularToSQLSuite.scala |  10 +-
 .../carbondata/view}/plans/SignatureSuite.scala    |  12 +-
 .../view}/rewrite/MVCoalesceTestCase.scala         |   2 +-
 .../view}/rewrite/MVCountAndCaseTestCase.scala     |   2 +-
 .../view}/rewrite/MVCreateTestCase.scala           |  11 +-
 .../view}/rewrite/MVExceptionTestCase.scala        |   2 +-
 .../view}/rewrite/MVFilterAndJoinTest.scala        |   2 +-
 .../rewrite/MVIncrementalLoadingTestcase.scala     | 102 +--
 .../view}/rewrite/MVInvalidTestCase.scala          |   2 +-
 .../view}/rewrite/MVMultiJoinTestCase.scala        |   2 +-
 .../view}/rewrite/MVRewriteTestCase.scala          |   2 +-
 .../view}/rewrite/MVSampleTestCase.scala           |   9 +-
 .../carbondata/view}/rewrite/MVTPCDSTestCase.scala |  11 +-
 .../carbondata/view}/rewrite/MVTpchTestCase.scala  |   3 +-
 .../view}/rewrite/SelectAllColumnsSuite.scala      |   2 +-
 .../view}/rewrite/TestAllOperationsOnMV.scala      |  22 +-
 .../view}/rewrite/TestPartitionWithMV.scala        |  10 +-
 .../carbondata/view}/rewrite/TestSQLSuite.scala    |  17 +-
 .../carbondata/view}/rewrite/Tpcds_1_4_Suite.scala |  18 +-
 .../view}/rewrite/matching/TestSQLBatch.scala      |  51 +-
 .../rewrite/matching/TestTPCDS_1_4_Batch.scala     | 562 +++++++-------
 .../view}/testutil/ModularPlanTest.scala           |   9 +-
 .../carbondata/view}/testutil/TestSQLBatch.scala   |  39 +-
 .../carbondata/view}/testutil/TestSQLBatch2.scala  |  39 +-
 .../view}/testutil/Tpcds_1_4_QueryBatch.scala      |   3 +-
 .../view}/testutil/Tpcds_1_4_Tables.scala          |  18 +-
 .../TestMVTimeSeriesCarbonCreateIndexCommand.scala |  15 +-
 .../timeseries/TestMVTimeSeriesLoadAndQuery.scala  | 111 ++-
 .../timeseries/TestMVTimeSeriesQueryRollUp.scala   | 297 +++++++
 mv/core/pom.xml                                    | 243 ------
 .../carbondata/mv/extension/MVAnalyzerRule.scala   | 242 ------
 .../carbondata/mv/extension/MVExtension.scala      |  88 ---
 .../mv/extension/MVExtensionSqlParser.scala        |  71 --
 .../apache/carbondata/mv/extension/MVHelper.scala  | 730 -----------------
 .../carbondata/mv/extension/MVIndexProvider.scala  | 208 -----
 .../apache/carbondata/mv/extension/MVParser.scala  | 206 -----
 .../apache/carbondata/mv/extension/MVUtil.scala    | 276 -------
 .../mv/extension/command/CreateMVCommand.scala     | 105 ---
 .../mv/extension/command/DropMVCommand.scala       |  95 ---
 .../mv/extension/command/RefreshMVCommand.scala    |  72 --
 .../mv/extension/command/ShowMVCommand.scala       |  98 ---
 .../carbondata/mv/rewrite/DefaultMatchMaker.scala  | 860 ---------------------
 .../org/apache/carbondata/mv/rewrite/MVUdf.scala   |  25 -
 .../apache/carbondata/mv/rewrite/MatchMaker.scala  |  47 --
 .../apache/carbondata/mv/rewrite/Navigator.scala   | 423 ----------
 .../carbondata/mv/rewrite/QueryRewrite.scala       | 602 ---------------
 .../mv/rewrite/SummaryDatasetCatalog.scala         | 303 --------
 .../org/apache/carbondata/mv/rewrite/Utils.scala   | 624 ---------------
 .../apache/carbondata/mv/session/MVSession.scala   |  84 --
 .../mv/session/internal/SessionState.scala         |  56 --
 .../carbondata/mv/timeseries/Granularity.java      |  46 --
 .../mv/timeseries/TimeSeriesFunction.scala         |  33 -
 .../carbondata/mv/timeseries/TimeSeriesUtil.scala  | 150 ----
 .../carbondata/mv/extension/MVOptimizer.scala      |  51 --
 .../carbondata/mv/extension/MVOptimizer.scala      |  51 --
 .../mv/plans/Tpcds_1_4_BenchmarkSuite.scala        |  82 --
 .../rewrite/SelectSelectExactChildrenSuite.scala   |  77 --
 .../timeseries/TestMVTimeSeriesQueryRollUp.scala   | 298 -------
 pom.xml                                            |   1 -
 101 files changed, 976 insertions(+), 9188 deletions(-)

diff --git a/core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java b/core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java
index 0e20ded..da12ca7 100644
--- a/core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java
+++ b/core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java
@@ -2245,16 +2245,6 @@ public final class CarbonCommonConstants {
   public static final String CARBON_ENABLE_AUDIT_DEFAULT = "true";
 
   /**
-   * This property will be used to store mv name
-   */
-  public static final String MV_NAME = "mv_name";
-
-  /**
-   * This property will be used to store parentable name's associated with mv
-   */
-  public static final String PARENT_TABLES = "parent_tables";
-
-  /**
    * This property will be used to store table name's related with mv
    */
   public static final String MV_RELATED_TABLES = "mv_related_tables";
diff --git a/core/src/main/java/org/apache/carbondata/core/index/CarbonIndexProvider.java b/core/src/main/java/org/apache/carbondata/core/index/CarbonIndexProvider.java
deleted file mode 100644
index 07eb58f..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/CarbonIndexProvider.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * 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.core.index;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import org.apache.carbondata.common.annotations.InterfaceAudience;
-import org.apache.carbondata.common.exceptions.sql.MalformedIndexCommandException;
-import org.apache.carbondata.common.exceptions.sql.NoSuchIndexException;
-import org.apache.carbondata.common.logging.LogServiceFactory;
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.index.dev.IndexFactory;
-import org.apache.carbondata.core.index.status.IndexStatusManager;
-import org.apache.carbondata.core.index.status.MVSegmentStatusUtil;
-import org.apache.carbondata.core.locks.ICarbonLock;
-import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier;
-import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-import org.apache.carbondata.core.metadata.schema.table.RelationIdentifier;
-import org.apache.carbondata.core.statusmanager.LoadMetadataDetails;
-import org.apache.carbondata.core.statusmanager.SegmentStatus;
-import org.apache.carbondata.core.statusmanager.SegmentStatusManager;
-import org.apache.carbondata.core.util.path.CarbonTablePath;
-
-import com.google.gson.Gson;
-import org.apache.log4j.Logger;
-
-/**
- * Index is a accelerator for certain type of query. Developer can add new Index
- * implementation to improve query performance.
- *
- * Currently two types of Index are supported
- * <ol>
- *   <li> MV: materialized view type of Index to accelerate olap style query,
- * like SPJG query (select, predicate, join, groupby) </li>
- *   <li> Index: index type of Index to accelerate filter query </li>
- * </ol>
- *
- * <p>
- * In following command <br>
- * {@code CREATE INDEX dm ON TABLE main AS 'provider'}, <br>
- * the <b>provider</b> string can be a short name or class name of the Index implementation.
- *
- * <br>Currently CarbonData supports following provider:
- * <ol>
- *   <li> lucene: index backed by Apache Lucene </li>
- *   <li> bloomfilter: index backed by Bloom Filter </li>
- * </ol>
- *
- * @since 1.4.0
- */
-@InterfaceAudience.Internal
-public abstract class CarbonIndexProvider {
-
-  public void setMainTable(CarbonTable mainTable) {
-    this.mainTable = mainTable;
-  }
-
-  private CarbonTable mainTable;
-  private IndexSchema indexSchema;
-
-  private Logger LOGGER = LogServiceFactory.getLogService(this.getClass().getCanonicalName());
-
-  public CarbonIndexProvider(CarbonTable mainTable, IndexSchema indexSchema) {
-    this.mainTable = mainTable;
-    this.indexSchema = indexSchema;
-  }
-
-  protected final CarbonTable getMainTable() {
-    return mainTable;
-  }
-
-  public final IndexSchema getIndexSchema() {
-    return indexSchema;
-  }
-
-  /**
-   * Initialize a index's metadata.
-   * This is called when user creates index "CREATE INDEX index ON mainTable"
-   * Implementation should initialize metadata for index, like creating table
-   */
-  public abstract void initMeta(String ctasSqlStatement) throws MalformedIndexCommandException,
-      IOException;
-
-  /**
-   * Initialize a index's data.
-   * This is called when user creates index, for example "CREATE INDEX dm ON TABLE mainTable"
-   * Implementation should initialize data for index, like creating data folders
-   */
-  public void initData() { }
-
-  /**
-   * Opposite operation of {@link #initMeta(String)}.
-   * This is called when user drops index, for example "DROP INDEX dm ON TABLE mainTable"
-   * Implementation should clean all meta for the index
-   */
-  public abstract void cleanMeta() throws IOException;
-
-  /**
-   * Opposite operation of {@link #initData()}.
-   * This is called when user drops index, for example "DROP INDEX dm ON TABLE mainTable"
-   * Implementation should clean all data for the index
-   */
-  public abstract void cleanData();
-
-  /**
-   * Rebuild the index by loading all existing data from mainTable
-   * This is called when refreshing the index when
-   * 1. after index creation and no "WITH DEFERRED REFRESH" defined
-   * 2. user manually trigger REFRESH index command
-   */
-  public boolean rebuild() throws IOException, NoSuchIndexException {
-    if (null == indexSchema.getRelationIdentifier()) {
-      return false;
-    }
-    String newLoadName = "";
-    String segmentMap = "";
-    CarbonTable table = CarbonTable
-        .buildFromTablePath(indexSchema.getRelationIdentifier().getTableName(),
-            indexSchema.getRelationIdentifier().getDatabaseName(),
-            indexSchema.getRelationIdentifier().getTablePath(),
-            indexSchema.getRelationIdentifier().getTableId());
-    AbsoluteTableIdentifier childTableAbsoluteTableIdentifier =
-        table.getAbsoluteTableIdentifier();
-    // Clean up the old invalid segment data before creating a new entry for new load.
-    SegmentStatusManager.deleteLoadsAndUpdateMetadata(table, false, null);
-    SegmentStatusManager segmentStatusManager =
-        new SegmentStatusManager(childTableAbsoluteTableIdentifier);
-    Map<String, List<String>> segmentMapping = new HashMap<>();
-    // Acquire table status lock to handle concurrent dataloading
-    ICarbonLock carbonLock = segmentStatusManager.getTableStatusLock();
-    try {
-      if (carbonLock.lockWithRetries()) {
-        LOGGER.info(
-            "Acquired lock for table" + indexSchema.getRelationIdentifier().getDatabaseName()
-                + "." + indexSchema.getRelationIdentifier().getTableName()
-                + " for table status updation");
-        String childTableMetadataPath =
-            CarbonTablePath.getMetadataPath(indexSchema.getRelationIdentifier().getTablePath());
-        LoadMetadataDetails[] loadMetaDataDetails =
-            SegmentStatusManager.readLoadMetadata(childTableMetadataPath);
-        // Mark for delete all stale loadMetadetail
-        for (LoadMetadataDetails loadMetadataDetail : loadMetaDataDetails) {
-          if ((loadMetadataDetail.getSegmentStatus() == SegmentStatus.INSERT_IN_PROGRESS
-              || loadMetadataDetail.getSegmentStatus()
-              == SegmentStatus.INSERT_OVERWRITE_IN_PROGRESS) && loadMetadataDetail.getVisibility()
-              .equalsIgnoreCase("false")) {
-            loadMetadataDetail.setSegmentStatus(SegmentStatus.MARKED_FOR_DELETE);
-          }
-        }
-        List<LoadMetadataDetails> listOfLoadFolderDetails =
-            new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
-        Collections.addAll(listOfLoadFolderDetails, loadMetaDataDetails);
-        if (indexSchema.isLazy()) {
-          // check if rebuild to index is already in progress and throw exception
-          if (!listOfLoadFolderDetails.isEmpty()) {
-            for (LoadMetadataDetails loadMetaDetail : loadMetaDataDetails) {
-              if ((loadMetaDetail.getSegmentStatus() == SegmentStatus.INSERT_IN_PROGRESS
-                  || loadMetaDetail.getSegmentStatus()
-                  == SegmentStatus.INSERT_OVERWRITE_IN_PROGRESS) && SegmentStatusManager
-                  .isLoadInProgress(childTableAbsoluteTableIdentifier,
-                      loadMetaDetail.getLoadName())) {
-                throw new RuntimeException("Rebuild to index " + indexSchema.getIndexName()
-                    + " is already in progress");
-              }
-            }
-          }
-        }
-        boolean incrementalBuild = indexSchema.canBeIncrementalBuild();
-        if (incrementalBuild) {
-          if (!getSpecificSegmentsTobeLoaded(segmentMapping, listOfLoadFolderDetails)) {
-            return false;
-          }
-        } else {
-          // set segment mapping only for carbondata table
-          List<RelationIdentifier> relationIdentifiers = indexSchema.getParentTables()
-              .stream()
-              .filter(RelationIdentifier::isCarbonDataTable)
-              .collect(Collectors.toList());
-          for (RelationIdentifier relationIdentifier : relationIdentifiers) {
-            List<String> mainTableSegmentList =
-                IndexUtil.getMainTableValidSegmentList(relationIdentifier);
-            if (mainTableSegmentList.isEmpty()) {
-              return false;
-            }
-            segmentMapping.put(relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT
-                + relationIdentifier.getTableName(), mainTableSegmentList);
-          }
-        }
-        segmentMap = new Gson().toJson(segmentMapping);
-
-        // To handle concurrent data loading to index, create new loadMetaEntry and
-        // set segmentMap to new loadMetaEntry and pass new segmentId with load command
-        LoadMetadataDetails loadMetadataDetail = new LoadMetadataDetails();
-        String segmentId =
-            String.valueOf(SegmentStatusManager.createNewSegmentId(loadMetaDataDetails));
-        loadMetadataDetail.setLoadName(segmentId);
-        loadMetadataDetail.setSegmentStatus(SegmentStatus.INSERT_IN_PROGRESS);
-        loadMetadataDetail.setExtraInfo(segmentMap);
-        listOfLoadFolderDetails.add(loadMetadataDetail);
-        newLoadName = segmentId;
-
-        SegmentStatusManager.writeLoadDetailsIntoFile(CarbonTablePath
-                .getTableStatusFilePath(indexSchema.getRelationIdentifier().getTablePath()),
-            listOfLoadFolderDetails
-                .toArray(new LoadMetadataDetails[listOfLoadFolderDetails.size()]));
-      } else {
-        LOGGER.error(
-            "Not able to acquire the lock for Table status updation for table " + indexSchema
-                .getRelationIdentifier().getDatabaseName() + "." + indexSchema
-                .getRelationIdentifier().getTableName());
-        IndexStatusManager.disableIndex(indexSchema.getIndexName());
-        return false;
-      }
-    } finally {
-      if (carbonLock.unlock()) {
-        LOGGER.info("Table unlocked successfully after table status updation" + indexSchema
-            .getRelationIdentifier().getDatabaseName() + "." + indexSchema.getRelationIdentifier()
-            .getTableName());
-      } else {
-        LOGGER.error("Unable to unlock Table lock for table" + indexSchema.getRelationIdentifier()
-            .getDatabaseName() + "." + indexSchema.getRelationIdentifier().getTableName()
-            + " during table status updation");
-      }
-    }
-    return rebuildInternal(newLoadName, segmentMapping, table);
-  }
-
-  /**
-   * This method will compare mainTable and index segment List and loads only newly added
-   * segment from main table to index.
-   * In case if mainTable is compacted, then based on index to mainTables segmentMapping, index
-   * will be loaded
-   * Eg:
-   * case 1: Consider mainTableSegmentList: {0, 1, 2}, indexToMainTable segmentMap:
-   * { 0 -> 0, 1-> 1,2}. If (1, 2) segments of main table are compacted to 1.1 and new segment (3)
-   * is loaded to main table, then mainTableSegmentList will be updated to{0, 1.1, 3}.
-   * In this case, segment (1) of index will be marked for delete, and new segment
-   * {2 -> 1.1, 3} will be loaded to index
-   * case 2: Consider mainTableSegmentList: {0, 1, 2, 3}, indexToMainTable segmentMap:
-   * { 0 -> 0,1,2, 1-> 3}. If (1, 2) segments of main table are compacted to 1.1 and new segment
-   * (4) is loaded to main table, then mainTableSegmentList will be updated to {0, 1.1, 3, 4}.
-   * In this case, segment (0) of index will be marked for delete and segment (0) of
-   * main table will be added to validSegmentList which needs to be loaded again. Now, new index
-   * segment (2) with main table segmentList{2 -> 1.1, 4, 0} will be loaded to index.
-   * indexToMainTable segmentMap will be updated to {1 -> 3, 2 -> 1.1, 4, 0} after rebuild
-   */
-  private boolean getSpecificSegmentsTobeLoaded(Map<String, List<String>> segmentMapping,
-      List<LoadMetadataDetails> listOfLoadFolderDetails) throws IOException {
-    List<RelationIdentifier> relationIdentifiers = indexSchema.getParentTables();
-    // invalidIndexSegmentList holds segment list which needs to be marked for delete
-    HashSet<String> invalidIndexSegmentList = new HashSet<>();
-    if (listOfLoadFolderDetails.isEmpty()) {
-      // If segment Map is empty, load all valid segments from main tables to index
-      for (RelationIdentifier relationIdentifier : relationIdentifiers) {
-        List<String> mainTableSegmentList =
-            IndexUtil.getMainTableValidSegmentList(relationIdentifier);
-        // If mainTableSegmentList is empty, no need to trigger load command
-        if (mainTableSegmentList.isEmpty()) {
-          return false;
-        }
-        segmentMapping.put(
-            relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT +
-                relationIdentifier.getTableName(), mainTableSegmentList);
-      }
-    } else {
-      for (RelationIdentifier relationIdentifier : relationIdentifiers) {
-        List<String> indexSegmentList = new ArrayList<>();
-        // Get all segments for parent relationIdentifier
-        List<String> mainTableSegmentList =
-            IndexUtil.getMainTableValidSegmentList(relationIdentifier);
-        boolean ifTableStatusUpdateRequired = false;
-        for (LoadMetadataDetails loadMetaDetail : listOfLoadFolderDetails) {
-          if (loadMetaDetail.getSegmentStatus() == SegmentStatus.SUCCESS
-              || loadMetaDetail.getSegmentStatus() == SegmentStatus.INSERT_IN_PROGRESS) {
-            Map<String, List<String>> segmentMaps =
-                MVSegmentStatusUtil.getSegmentMap(loadMetaDetail.getExtraInfo());
-            String mainTableMetaDataPath =
-                CarbonTablePath.getMetadataPath(relationIdentifier.getTablePath());
-            LoadMetadataDetails[] parentTableLoadMetaDataDetails =
-                SegmentStatusManager.readLoadMetadata(mainTableMetaDataPath);
-            String table = relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT
-                + relationIdentifier.getTableName();
-            for (String segmentId : mainTableSegmentList) {
-              // In case if index segment(0) is mapped to mainTable segments{0,1,2} and if
-              // {0,1,2} segments of mainTable are compacted to 0.1. Then,
-              // on next rebuild/load to index, no need to load segment(0.1) again. Update the
-              // segmentMapping of index segment from {0,1,2} to {0.1}
-              if (!checkIfSegmentsToBeReloaded(parentTableLoadMetaDataDetails,
-                  segmentMaps.get(table), segmentId)) {
-                ifTableStatusUpdateRequired = true;
-                // Update loadMetaDetail with updated segment info and clear old segmentMap
-                Map<String, List<String>> updatedSegmentMap = new HashMap<>();
-                List<String> segmentList = new ArrayList<>();
-                segmentList.add(segmentId);
-                updatedSegmentMap.put(table, segmentList);
-                indexSegmentList.add(segmentId);
-                loadMetaDetail.setExtraInfo(new Gson().toJson(updatedSegmentMap));
-                segmentMaps.get(table).clear();
-              }
-            }
-            indexSegmentList.addAll(segmentMaps.get(table));
-          }
-        }
-        List<String> childTableSegmentList = new ArrayList<>(indexSegmentList);
-        indexSegmentList.removeAll(mainTableSegmentList);
-        mainTableSegmentList.removeAll(childTableSegmentList);
-        if (ifTableStatusUpdateRequired && mainTableSegmentList.isEmpty()) {
-          SegmentStatusManager.writeLoadDetailsIntoFile(CarbonTablePath
-                  .getTableStatusFilePath(indexSchema.getRelationIdentifier().getTablePath()),
-              listOfLoadFolderDetails.toArray(new LoadMetadataDetails[0]));
-          return false;
-        } else if (mainTableSegmentList.isEmpty()) {
-          return false;
-        }
-        if (!indexSegmentList.isEmpty()) {
-          List<String> invalidMainTableSegmentList = new ArrayList<>();
-          // validMainTableSegmentList holds segment list which needs to be loaded again
-          HashSet<String> validMainTableSegmentList = new HashSet<>();
-
-          // For index segments which are not in main table segment list(if main table
-          // is compacted), iterate over those segments and get index segments which needs to
-          // be marked for delete and main table segments which needs to be loaded again
-          for (String segmentId : indexSegmentList) {
-            for (LoadMetadataDetails loadMetaDetail : listOfLoadFolderDetails) {
-              if (loadMetaDetail.getSegmentStatus() == SegmentStatus.SUCCESS
-                  || loadMetaDetail.getSegmentStatus() == SegmentStatus.INSERT_IN_PROGRESS) {
-                Map<String, List<String>> segmentMaps =
-                    MVSegmentStatusUtil.getSegmentMap(loadMetaDetail.getExtraInfo());
-                List<String> segmentIds = segmentMaps.get(
-                    relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT
-                        + relationIdentifier.getTableName());
-                if (segmentIds.contains(segmentId)) {
-                  segmentIds.remove(segmentId);
-                  validMainTableSegmentList.addAll(segmentIds);
-                  invalidMainTableSegmentList.add(segmentId);
-                  invalidIndexSegmentList.add(loadMetaDetail.getLoadName());
-                }
-              }
-            }
-          }
-          // remove invalid segment from validMainTableSegmentList if present
-          validMainTableSegmentList.removeAll(invalidMainTableSegmentList);
-          // Add all valid segments of main table which needs to be loaded again
-          mainTableSegmentList.addAll(validMainTableSegmentList);
-        }
-        segmentMapping.put(relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT
-            + relationIdentifier.getTableName(), mainTableSegmentList);
-      }
-    }
-    // Remove invalid index segments
-    if (!invalidIndexSegmentList.isEmpty()) {
-      for (LoadMetadataDetails loadMetadataDetail : listOfLoadFolderDetails) {
-        if (invalidIndexSegmentList.contains(loadMetadataDetail.getLoadName())) {
-          loadMetadataDetail.setSegmentStatus(SegmentStatus.MARKED_FOR_DELETE);
-        }
-      }
-    }
-    return true;
-  }
-
-  /**
-   * This method checks if index segment has to be reloaded again or not
-   */
-  private boolean checkIfSegmentsToBeReloaded(LoadMetadataDetails[] loadMetaDataDetails,
-      List<String> segmentIds, String segmentId) {
-    boolean isToBeLoadedAgain = true;
-    List<String> mergedSegments = new ArrayList<>();
-    for (LoadMetadataDetails loadMetadataDetail : loadMetaDataDetails) {
-      if (null != loadMetadataDetail.getMergedLoadName() && loadMetadataDetail.getMergedLoadName()
-          .equalsIgnoreCase(segmentId)) {
-        mergedSegments.add(loadMetadataDetail.getLoadName());
-      }
-    }
-    if (!mergedSegments.isEmpty() && segmentIds.containsAll(mergedSegments)) {
-      isToBeLoadedAgain = false;
-    }
-    return isToBeLoadedAgain;
-  }
-
-  /**
-   * Provide the MV catalog instance
-   */
-  public MVCatalog createMVCatalog() {
-    return null;
-  }
-
-  public abstract IndexFactory getIndexFactory();
-
-  public abstract boolean supportRebuild();
-
-  public abstract boolean rebuildInternal(String newLoadName, Map<String, List<String>> segmentMap,
-      CarbonTable carbonTable);
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/index/IndexStoreManager.java b/core/src/main/java/org/apache/carbondata/core/index/IndexStoreManager.java
index fe3ec47..106042c 100644
--- a/core/src/main/java/org/apache/carbondata/core/index/IndexStoreManager.java
+++ b/core/src/main/java/org/apache/carbondata/core/index/IndexStoreManager.java
@@ -28,7 +28,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import org.apache.carbondata.common.annotations.InterfaceAudience;
 import org.apache.carbondata.common.exceptions.MetadataProcessException;
 import org.apache.carbondata.common.exceptions.sql.MalformedIndexCommandException;
-import org.apache.carbondata.common.exceptions.sql.NoSuchIndexException;
 import org.apache.carbondata.common.logging.LogServiceFactory;
 import org.apache.carbondata.core.constants.CarbonCommonConstants;
 import org.apache.carbondata.core.datastore.block.SegmentPropertiesAndSchemaHolder;
@@ -43,8 +42,6 @@ import org.apache.carbondata.core.metadata.index.IndexType;
 import org.apache.carbondata.core.metadata.schema.indextable.IndexMetadata;
 import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
 import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-import org.apache.carbondata.core.metadata.schema.table.IndexSchemaFactory;
-import org.apache.carbondata.core.metadata.schema.table.IndexSchemaStorageProvider;
 import org.apache.carbondata.core.mutate.UpdateVO;
 import org.apache.carbondata.core.statusmanager.SegmentRefreshInfo;
 import org.apache.carbondata.core.statusmanager.SegmentStatusManager;
@@ -79,21 +76,11 @@ public final class IndexStoreManager {
    */
   private Map<String, String> tablePathMap = new ConcurrentHashMap<>();
 
-  /**
-   * Contains the mv catalog for each mv provider.
-   */
-  private Map<String, MVCatalog> mvCatalogMap = null;
-
   private Map<String, TableSegmentRefresher> segmentRefreshMap = new ConcurrentHashMap<>();
 
-  private IndexSchemaStorageProvider provider =
-      IndexSchemaFactory.getIndexSchemaStorageProvider();
-
   private static final Logger LOGGER =
       LogServiceFactory.getLogService(IndexStoreManager.class.getName());
 
-  private final Object lockObject = new Object();
-
   private IndexStoreManager() {
 
   }
@@ -124,141 +111,6 @@ public final class IndexStoreManager {
     }
     return indexes;
   }
-
-  /**
-   * It gives all index schemas of a given table.
-   *
-   */
-  public List<IndexSchema> getIndexSchemasOfTable(CarbonTable carbonTable) throws IOException {
-    return provider.retrieveSchemas(carbonTable);
-  }
-
-  /**
-   * It gives all index schemas from store.
-   */
-  public List<IndexSchema> getAllIndexSchemas() throws IOException {
-    return provider.retrieveAllSchemas();
-  }
-
-  public IndexSchema getIndexSchema(String indexName) throws IOException, NoSuchIndexException {
-    return provider.retrieveSchema(indexName);
-  }
-
-  /**
-   * Saves the index schema to storage
-   * @param indexSchema
-   */
-  public void saveIndexSchema(IndexSchema indexSchema) throws IOException {
-    provider.saveSchema(indexSchema);
-  }
-
-  /**
-   * Drops the index schema from storage
-   * @param indexName
-   */
-  public void dropIndexSchema(String indexName) throws IOException {
-    provider.dropSchema(indexName);
-  }
-
-  /**
-   * Register MV catalog for the MV provider
-   * @param indexProvider
-   * @param indexSchema
-   */
-  public synchronized void registerMVCatalog(
-      org.apache.carbondata.core.index.CarbonIndexProvider indexProvider,
-      IndexSchema indexSchema, boolean clearCatalogs) throws IOException {
-    // this check is added to check if when registering the datamapCatalog, if the catalog map has
-    // datasets with old session, then need to clear and reload the map, else error can be thrown
-    // if the databases are different in both the sessions
-    if (clearCatalogs) {
-      mvCatalogMap = null;
-    }
-    initializeMVCatalogs(indexProvider);
-    String name = indexSchema.getProviderName().toLowerCase();
-    MVCatalog mvCatalog = mvCatalogMap.get(name);
-    if (mvCatalog == null) {
-      mvCatalog = indexProvider.createMVCatalog();
-      // If MVDataMapProvider, then createMVCatalog will return summaryDatasetCatalog
-      // instance, which needs to be added to dataMapCatalogs.
-      // For other datamaps, createMVCatalog will return null, so no need to register
-      if (mvCatalog != null) {
-        mvCatalogMap.put(name, mvCatalog);
-        mvCatalog.registerSchema(indexSchema);
-      }
-    } else {
-      if (!mvCatalog.isMVExists(indexSchema.getIndexName())) {
-        mvCatalog.registerSchema(indexSchema);
-      }
-    }
-  }
-
-  /**
-   * Unregister index.
-   * @param indexSchema
-   */
-  public synchronized void unRegisterIndex(IndexSchema indexSchema) {
-    if (mvCatalogMap == null) {
-      return;
-    }
-    String name = indexSchema.getProviderName().toLowerCase();
-    MVCatalog MVCatalog = mvCatalogMap.get(name);
-    if (MVCatalog != null) {
-      MVCatalog.unregisterSchema(indexSchema.getIndexName());
-    }
-  }
-
-  /**
-   * Get the MV catalog for provider.
-   * @param providerName
-   * @return
-   */
-  public synchronized MVCatalog getMVCatalog(
-      org.apache.carbondata.core.index.CarbonIndexProvider indexProvider,
-      String providerName,
-      boolean clearCatalogs) throws IOException {
-    // This method removes the datamapCatalog for the corresponding provider if the session gets
-    // refreshed or updated
-    if (clearCatalogs) {
-      mvCatalogMap = null;
-    }
-    initializeMVCatalogs(indexProvider);
-    return mvCatalogMap.get(providerName.toLowerCase());
-  }
-
-  /**
-   * Initialize by reading all datamaps from store and re register it
-   * @param indexProvider
-   */
-  private synchronized void initializeMVCatalogs(
-      org.apache.carbondata.core.index.CarbonIndexProvider indexProvider)
-      throws IOException {
-    if (mvCatalogMap == null) {
-      mvCatalogMap = new ConcurrentHashMap<>();
-      List<IndexSchema> indexSchemas = getAllIndexSchemas();
-      for (IndexSchema schema : indexSchemas) {
-        if (schema.getProviderName()
-            .equalsIgnoreCase(indexProvider.getIndexSchema().getProviderName())) {
-          MVCatalog MVCatalog =
-              mvCatalogMap.get(schema.getProviderName().toLowerCase());
-          if (MVCatalog == null) {
-            MVCatalog = indexProvider.createMVCatalog();
-            if (null == MVCatalog) {
-              throw new RuntimeException("Internal Error.");
-            }
-            mvCatalogMap.put(schema.getProviderName().toLowerCase(), MVCatalog);
-          }
-          try {
-            MVCatalog.registerSchema(schema);
-          } catch (Exception e) {
-            // Ignore the schema
-            LOGGER.error("Error while registering schema", e);
-          }
-        }
-      }
-    }
-  }
-
   /**
    * It gives the default index of the table. Default index of any table is BlockletIndex
    *
diff --git a/core/src/main/java/org/apache/carbondata/core/index/MVCatalog.java b/core/src/main/java/org/apache/carbondata/core/index/MVCatalog.java
deleted file mode 100644
index 695c3a1..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/MVCatalog.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.core.index;
-
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-
-/**
- * This is the interface for inmemory catalog registry for MV.
- * @since 1.4.0
- */
-public interface MVCatalog<T> {
-
-  /**
-   * Register schema to the catalog.
-   * @param indexSchema
-   */
-  void registerSchema(IndexSchema indexSchema);
-
-  /**
-   * Unregister schema from catalog.
-   * @param mvName
-   */
-  void unregisterSchema(String mvName);
-
-  /**
-   * List all registered valid schema catalogs
-   * @return
-   */
-  T[] listAllValidSchema();
-
-  /**
-   * It reloads/removes all registered schema catalogs
-   */
-  void refresh();
-
-  /**
-   * This checks whether the datamapSchema is already registered
-   */
-  Boolean isMVExists(String mvName);
-
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/index/status/DatabaseIndexStatusProvider.java b/core/src/main/java/org/apache/carbondata/core/index/status/DatabaseIndexStatusProvider.java
deleted file mode 100644
index 852e021..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/status/DatabaseIndexStatusProvider.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.core.index.status;
-
-import java.util.List;
-
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-
-/**
- * It saves/serializes the array of {{@link IndexStatusDetail}} to database folder.
- * It ensures the data consistance while concurrent write through write lock. It saves the status
- * to the indexstatus under the database folder.
- * Now the implement not finished, it used to disable Index in multi-tenant scenario.
- */
-public class DatabaseIndexStatusProvider implements IndexStatusStorageProvider {
-
-  @Override
-  public IndexStatusDetail[] getIndexStatusDetails() {
-    return new IndexStatusDetail[0];
-  }
-
-  /**
-   * Update or add the status of passed indexes with the given indexstatus. If the indexstatus
-   * given is enabled/disabled then updates/adds the index, in case of drop it just removes it
-   * from the file.
-   * This method always overwrites the old file.
-   * @param indexSchemas schemas of which are need to be updated in index status
-   * @param indexStatus  status to be updated for the index schemas
-   */
-  @Override
-  public void updateIndexStatus(
-      List<IndexSchema> indexSchemas, IndexStatus indexStatus) {
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/index/status/DiskBasedIndexStatusProvider.java b/core/src/main/java/org/apache/carbondata/core/index/status/DiskBasedIndexStatusProvider.java
deleted file mode 100644
index 3b81c5c..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/status/DiskBasedIndexStatusProvider.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * 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.core.index.status;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.carbondata.common.logging.LogServiceFactory;
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.datastore.impl.FileFactory;
-import org.apache.carbondata.core.fileoperations.AtomicFileOperationFactory;
-import org.apache.carbondata.core.fileoperations.AtomicFileOperations;
-import org.apache.carbondata.core.fileoperations.FileWriteOperation;
-import org.apache.carbondata.core.index.IndexUtil;
-import org.apache.carbondata.core.locks.CarbonLockFactory;
-import org.apache.carbondata.core.locks.CarbonLockUtil;
-import org.apache.carbondata.core.locks.ICarbonLock;
-import org.apache.carbondata.core.locks.LockUsage;
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-import org.apache.carbondata.core.metadata.schema.table.RelationIdentifier;
-import org.apache.carbondata.core.statusmanager.LoadMetadataDetails;
-import org.apache.carbondata.core.statusmanager.SegmentStatus;
-import org.apache.carbondata.core.statusmanager.SegmentStatusManager;
-import org.apache.carbondata.core.util.CarbonProperties;
-import org.apache.carbondata.core.util.CarbonUtil;
-import org.apache.carbondata.core.util.path.CarbonTablePath;
-
-import com.google.gson.Gson;
-import org.apache.log4j.Logger;
-
-/**
- * It saves/serializes the array of {{@link IndexStatusDetail}} to disk in json format.
- * It ensures the data consistance while concurrent write through write lock. It saves the status
- * to the index status under the system folder.
- */
-public class DiskBasedIndexStatusProvider implements IndexStatusStorageProvider {
-
-  private static final Logger LOG =
-      LogServiceFactory.getLogService(DiskBasedIndexStatusProvider.class.getName());
-
-  private static final String INDEX_STATUS_FILE = "indexstatus";
-
-  @Override
-  public IndexStatusDetail[] getIndexStatusDetails() throws IOException {
-    String statusPath = CarbonProperties.getInstance().getSystemFolderLocation()
-        + CarbonCommonConstants.FILE_SEPARATOR + INDEX_STATUS_FILE;
-    Gson gsonObjectToRead = new Gson();
-    DataInputStream dataInputStream = null;
-    BufferedReader buffReader = null;
-    InputStreamReader inStream = null;
-    IndexStatusDetail[] indexStatusDetails;
-    try {
-      if (!FileFactory.isFileExist(statusPath)) {
-        return new IndexStatusDetail[0];
-      }
-      dataInputStream = FileFactory.getDataInputStream(statusPath);
-      inStream = new InputStreamReader(dataInputStream,
-          Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
-      buffReader = new BufferedReader(inStream);
-      indexStatusDetails = gsonObjectToRead.fromJson(buffReader, IndexStatusDetail[].class);
-    } catch (IOException e) {
-      LOG.error("Failed to read index status", e);
-      throw e;
-    } finally {
-      CarbonUtil.closeStreams(buffReader, inStream, dataInputStream);
-    }
-
-    // if indexStatusDetails is null, return empty array
-    if (null == indexStatusDetails) {
-      return new IndexStatusDetail[0];
-    }
-
-    return indexStatusDetails;
-  }
-
-  /**
-   * Update or add the status of passed indexes with the given indexstatus. If the indexstatus
-   * given is enabled/disabled then updates/adds the index, in case of drop it just removes it
-   * from the file.
-   * This method always overwrites the old file.
-   * @param indexSchemas schemas of which are need to be updated in index status
-   * @param indexStatus  status to be updated for the index schemas
-   * @throws IOException
-   */
-  @Override
-  public void updateIndexStatus(List<IndexSchema> indexSchemas, IndexStatus indexStatus)
-      throws IOException {
-    if (indexSchemas == null || indexSchemas.size() == 0) {
-      // There is nothing to update
-      return;
-    }
-    ICarbonLock carbonTableStatusLock = getIndexStatusLock();
-    boolean locked = false;
-    try {
-      locked = carbonTableStatusLock.lockWithRetries();
-      if (locked) {
-        LOG.info("index status lock has been successfully acquired.");
-        if (indexStatus == IndexStatus.ENABLED && !indexSchemas.get(0).isIndex()) {
-          // Enable index only if index tables and main table are in sync
-          if (!canIndexBeEnabled(indexSchemas.get(0))) {
-            return;
-          }
-        }
-        IndexStatusDetail[] indexStatusDetails = getIndexStatusDetails();
-        List<IndexStatusDetail> indexStatusList = Arrays.asList(indexStatusDetails);
-        indexStatusList = new ArrayList<>(indexStatusList);
-        List<IndexStatusDetail> changedStatusDetails = new ArrayList<>();
-        List<IndexStatusDetail> newStatusDetails = new ArrayList<>();
-        for (IndexSchema indexSchema : indexSchemas) {
-          boolean exists = false;
-          for (IndexStatusDetail statusDetail : indexStatusList) {
-            if (statusDetail.getIndexName().equals(indexSchema.getIndexName())) {
-              statusDetail.setStatus(indexStatus);
-              changedStatusDetails.add(statusDetail);
-              exists = true;
-            }
-          }
-          if (!exists) {
-            newStatusDetails
-                .add(new IndexStatusDetail(indexSchema.getIndexName(), indexStatus));
-          }
-        }
-        // Add the newly added index to the list.
-        if (newStatusDetails.size() > 0 && indexStatus != IndexStatus.DROPPED) {
-          indexStatusList.addAll(newStatusDetails);
-        }
-        // In case of dropped index, just remove from the list.
-        if (indexStatus == IndexStatus.DROPPED) {
-          indexStatusList.removeAll(changedStatusDetails);
-        }
-        writeLoadDetailsIntoFile(CarbonProperties.getInstance().getSystemFolderLocation()
-                + CarbonCommonConstants.FILE_SEPARATOR + INDEX_STATUS_FILE,
-            indexStatusList.toArray(new IndexStatusDetail[indexStatusList.size()]));
-      } else {
-        String errorMsg = "Upadating index status is failed due to another process taken the lock"
-            + " for updating it";
-        LOG.error(errorMsg);
-        throw new IOException(errorMsg + " Please try after some time.");
-      }
-    } finally {
-      if (locked) {
-        CarbonLockUtil.fileUnlock(carbonTableStatusLock, LockUsage.INDEX_STATUS_LOCK);
-      }
-    }
-  }
-
-  /**
-   * This method checks if main table and index table are synchronised or not. If synchronised
-   * return true to enable the index
-   *
-   * @param indexSchema of index to be disabled or enabled
-   * @return flag to enable or disable index
-   * @throws IOException
-   */
-  private boolean canIndexBeEnabled(IndexSchema indexSchema) throws IOException {
-    boolean isIndexInSync = true;
-    String metaDataPath =
-        CarbonTablePath.getMetadataPath(indexSchema.getRelationIdentifier().getTablePath());
-    LoadMetadataDetails[] indexLoadMetadataDetails =
-        SegmentStatusManager.readLoadMetadata(metaDataPath);
-    Map<String, List<String>> indexSegmentMap = new HashMap<>();
-    for (LoadMetadataDetails loadMetadataDetail : indexLoadMetadataDetails) {
-      if (loadMetadataDetail.getSegmentStatus() == SegmentStatus.SUCCESS) {
-        Map<String, List<String>> segmentMap =
-            MVSegmentStatusUtil.getSegmentMap(loadMetadataDetail.getExtraInfo());
-        if (indexSegmentMap.isEmpty()) {
-          indexSegmentMap.putAll(segmentMap);
-        } else {
-          for (Map.Entry<String, List<String>> entry : segmentMap.entrySet()) {
-            if (null != indexSegmentMap.get(entry.getKey())) {
-              indexSegmentMap.get(entry.getKey()).addAll(entry.getValue());
-            }
-          }
-        }
-      }
-    }
-    List<RelationIdentifier> parentTables = indexSchema.getParentTables();
-    for (RelationIdentifier parentTable : parentTables) {
-      List<String> mainTableValidSegmentList =
-          IndexUtil.getMainTableValidSegmentList(parentTable);
-      if (!mainTableValidSegmentList.isEmpty() && !indexSegmentMap.isEmpty()) {
-        isIndexInSync = indexSegmentMap.get(
-            parentTable.getDatabaseName() + CarbonCommonConstants.POINT + parentTable
-                .getTableName()).containsAll(mainTableValidSegmentList);
-      } else if (indexSegmentMap.isEmpty() && !mainTableValidSegmentList.isEmpty()) {
-        isIndexInSync = false;
-      }
-    }
-    return isIndexInSync;
-  }
-
-  /**
-   * writes index status details
-   *
-   * @param indexStatusDetails
-   * @throws IOException
-   */
-  private static void writeLoadDetailsIntoFile(String location,
-      IndexStatusDetail[] indexStatusDetails) throws IOException {
-    AtomicFileOperations fileWrite = AtomicFileOperationFactory.getAtomicFileOperations(location);
-    BufferedWriter brWriter = null;
-    DataOutputStream dataOutputStream = null;
-    Gson gsonObjectToWrite = new Gson();
-    // write the updated data into the index status file.
-    try {
-      dataOutputStream = fileWrite.openForWrite(FileWriteOperation.OVERWRITE);
-      brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream,
-          Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
-
-      String metadataInstance = gsonObjectToWrite.toJson(indexStatusDetails);
-      brWriter.write(metadataInstance);
-    } catch (IOException ioe) {
-      LOG.error("Error message: " + ioe.getLocalizedMessage());
-      fileWrite.setFailed();
-      throw ioe;
-    } finally {
-      if (null != brWriter) {
-        brWriter.flush();
-      }
-      CarbonUtil.closeStreams(brWriter);
-      fileWrite.close();
-    }
-
-  }
-
-  private static ICarbonLock getIndexStatusLock() {
-    return CarbonLockFactory
-        .getSystemLevelCarbonLockObj(CarbonProperties.getInstance().getSystemFolderLocation(),
-            LockUsage.INDEX_STATUS_LOCK);
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusDetail.java b/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusDetail.java
deleted file mode 100644
index b89146e..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusDetail.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.core.index.status;
-
-import java.io.Serializable;
-
-import org.apache.carbondata.common.annotations.InterfaceAudience;
-
-/**
- * Status of each index
- */
-@InterfaceAudience.Internal
-public class IndexStatusDetail implements Serializable {
-
-  private static final long serialVersionUID = 1570997199499681821L;
-  private String indexName;
-
-  private IndexStatus status;
-
-  public IndexStatusDetail() {
-  }
-
-  public IndexStatusDetail(String indexName, IndexStatus status) {
-    this.indexName = indexName;
-    this.status = status;
-  }
-
-  public String getIndexName() {
-    return indexName;
-  }
-
-  public void setIndexName(String indexName) {
-    this.indexName = indexName;
-  }
-
-  public IndexStatus getStatus() {
-    return status;
-  }
-
-  public boolean isEnabled() {
-    return status == IndexStatus.ENABLED;
-  }
-
-  public void setStatus(IndexStatus status) {
-    this.status = status;
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusManager.java b/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusManager.java
deleted file mode 100644
index 864a282..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusManager.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * 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.core.index.status;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.carbondata.common.exceptions.sql.NoSuchIndexException;
-import org.apache.carbondata.common.logging.LogServiceFactory;
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.index.IndexStoreManager;
-import org.apache.carbondata.core.locks.ICarbonLock;
-import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier;
-import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-import org.apache.carbondata.core.metadata.schema.table.RelationIdentifier;
-import org.apache.carbondata.core.statusmanager.LoadMetadataDetails;
-import org.apache.carbondata.core.statusmanager.SegmentStatus;
-import org.apache.carbondata.core.statusmanager.SegmentStatusManager;
-import org.apache.carbondata.core.util.CarbonProperties;
-import org.apache.carbondata.core.util.path.CarbonTablePath;
-
-import org.apache.log4j.Logger;
-
-/**
- * Maintains the status of each index. As per the status query will decide whether to hit index
- * or not.
- */
-public class IndexStatusManager {
-
-  // Create private constructor to not allow create instance of it
-  private IndexStatusManager() {
-
-  }
-
-  private static final Logger LOGGER =
-      LogServiceFactory.getLogService(IndexStatusManager.class.getName());
-
-  /**
-   * TODO Use factory when we have more storage providers
-   */
-  private static IndexStatusStorageProvider storageProvider =
-      getIndexStatusStorageProvider();
-
-  /**
-   * Get enabled index status details
-   * @return
-   * @throws IOException
-   */
-  public static IndexStatusDetail[] getEnabledIndexStatusDetails() throws IOException {
-    IndexStatusDetail[] indexStatusDetails = storageProvider.getIndexStatusDetails();
-    List<IndexStatusDetail> statusDetailList = new ArrayList<>();
-    for (IndexStatusDetail statusDetail : indexStatusDetails) {
-      if (statusDetail.getStatus() == IndexStatus.ENABLED) {
-        statusDetailList.add(statusDetail);
-      }
-    }
-    return statusDetailList.toArray(new IndexStatusDetail[statusDetailList.size()]);
-  }
-
-  public static Map<String, IndexStatusDetail> readIndexStatusMap() throws IOException {
-    IndexStatusDetail[] details = storageProvider.getIndexStatusDetails();
-    Map<String, IndexStatusDetail> map = new HashMap<>(details.length);
-    for (IndexStatusDetail detail : details) {
-      map.put(detail.getIndexName(), detail);
-    }
-    return map;
-  }
-
-  public static void disableIndex(String indexName) throws IOException, NoSuchIndexException {
-    IndexSchema indexSchema = getIndexSchema(indexName);
-    if (indexSchema != null) {
-      List<IndexSchema> list = new ArrayList<>();
-      list.add(indexSchema);
-      storageProvider.updateIndexStatus(list, IndexStatus.DISABLED);
-    }
-  }
-
-  /**
-   * This method will disable all lazy (DEFERRED REFRESH) index in the given table
-   */
-  public static void disableAllLazyIndexes(CarbonTable table) throws IOException {
-    List<IndexSchema> allIndexSchemas =
-        IndexStoreManager.getInstance().getIndexSchemasOfTable(table);
-    List<IndexSchema> indexToBeDisabled = new ArrayList<>(allIndexSchemas.size());
-    for (IndexSchema indexSchema : allIndexSchemas) {
-      if (indexSchema.isLazy()) {
-        indexToBeDisabled.add(indexSchema);
-      }
-    }
-    storageProvider.updateIndexStatus(indexToBeDisabled, IndexStatus.DISABLED);
-  }
-
-  public static void enableIndex(String indexName) throws IOException, NoSuchIndexException {
-    IndexSchema indexSchema = getIndexSchema(indexName);
-    if (indexSchema != null) {
-      List<IndexSchema> list = new ArrayList<>();
-      list.add(indexSchema);
-      storageProvider.updateIndexStatus(list, IndexStatus.ENABLED);
-    }
-  }
-
-  public static void dropIndex(String indexName) throws IOException, NoSuchIndexException {
-    IndexSchema indexSchema = getIndexSchema(indexName);
-    if (indexSchema != null) {
-      List<IndexSchema> list = new ArrayList<>();
-      list.add(indexSchema);
-      storageProvider.updateIndexStatus(list, IndexStatus.DROPPED);
-    }
-  }
-
-  public static IndexSchema getIndexSchema(String indexName)
-      throws IOException, NoSuchIndexException {
-    return IndexStoreManager.getInstance().getIndexSchema(indexName);
-  }
-
-  /**
-   * This method will remove all segments of index table in case of Insert-Overwrite/Update/Delete
-   * operations on main table
-   *
-   * @param allIndexSchemas of main carbon table
-   * @throws IOException
-   */
-  public static void truncateIndex(List<IndexSchema> allIndexSchemas)
-      throws IOException, NoSuchIndexException {
-    for (IndexSchema indexSchema : allIndexSchemas) {
-      if (!indexSchema.isLazy()) {
-        disableIndex(indexSchema.getIndexName());
-      }
-      RelationIdentifier indexRelationIdentifier = indexSchema.getRelationIdentifier();
-      SegmentStatusManager segmentStatusManager = new SegmentStatusManager(AbsoluteTableIdentifier
-          .from(indexRelationIdentifier.getTablePath(),
-              indexRelationIdentifier.getDatabaseName(),
-              indexRelationIdentifier.getTableName()));
-      ICarbonLock carbonLock = segmentStatusManager.getTableStatusLock();
-      try {
-        if (carbonLock.lockWithRetries()) {
-          LOGGER.info("Acquired lock for table" + indexRelationIdentifier.getDatabaseName() + "."
-              + indexRelationIdentifier.getTableName() + " for table status updation");
-          String metaDataPath =
-              CarbonTablePath.getMetadataPath(indexRelationIdentifier.getTablePath());
-          LoadMetadataDetails[] loadMetadataDetails =
-              SegmentStatusManager.readLoadMetadata(metaDataPath);
-          for (LoadMetadataDetails entry : loadMetadataDetails) {
-            entry.setSegmentStatus(SegmentStatus.MARKED_FOR_DELETE);
-          }
-          SegmentStatusManager.writeLoadDetailsIntoFile(
-              CarbonTablePath.getTableStatusFilePath(indexRelationIdentifier.getTablePath()),
-              loadMetadataDetails);
-        } else {
-          LOGGER.error("Not able to acquire the lock for Table status updation for table "
-              + indexRelationIdentifier.getDatabaseName() + "." + indexRelationIdentifier
-              .getTableName());
-        }
-      } finally {
-        if (carbonLock.unlock()) {
-          LOGGER.info(
-              "Table unlocked successfully after table status updation" + indexRelationIdentifier
-                  .getDatabaseName() + "." + indexRelationIdentifier.getTableName());
-        } else {
-          LOGGER.error(
-              "Unable to unlock Table lock for table" + indexRelationIdentifier.getDatabaseName()
-                  + "." + indexRelationIdentifier.getTableName()
-                  + " during table status updation");
-        }
-      }
-    }
-  }
-
-  public static IndexStatusStorageProvider getIndexStatusStorageProvider() {
-    String providerProperties = CarbonProperties.getIndexStorageProvider();
-    switch (providerProperties) {
-      case CarbonCommonConstants.CARBON_INDEX_SCHEMA_STORAGE_DATABASE:
-        return new DatabaseIndexStatusProvider();
-      case CarbonCommonConstants.CARBON_INDEX_SCHEMA_STORAGE_DISK:
-      default:
-        return new DiskBasedIndexStatusProvider();
-    }
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusStorageProvider.java b/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusStorageProvider.java
deleted file mode 100644
index 5bc8a0c..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/status/IndexStatusStorageProvider.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.core.index.status;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-
-/**
- * It updates the index status to the storage. It will have 2 implementations one will be disk
- * based and another would be DB based
- *
- * @version 1.4
- */
-public interface IndexStatusStorageProvider {
-
-  /**
-   * It reads and returns all index status details from storage.
-   *
-   * @return IndexStatusDetail[] all index status details
-   * @throws IOException
-   */
-  IndexStatusDetail[] getIndexStatusDetails() throws IOException;
-
-  /**
-   * Update the status of the given indexes to the passed index status.
-   *
-   * @param indexSchemas schemas of which are need to be updated in index status
-   * @param indexStatus  status to be updated for the index schemas
-   * @throws IOException
-   */
-  void updateIndexStatus(List<IndexSchema> indexSchemas, IndexStatus indexStatus)
-      throws IOException;
-
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/index/status/MVSegmentStatusUtil.java b/core/src/main/java/org/apache/carbondata/core/index/status/MVSegmentStatusUtil.java
deleted file mode 100644
index 379781a..0000000
--- a/core/src/main/java/org/apache/carbondata/core/index/status/MVSegmentStatusUtil.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.core.index.status;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-import org.apache.carbondata.core.metadata.schema.table.RelationIdentifier;
-import org.apache.carbondata.core.statusmanager.LoadMetadataDetails;
-import org.apache.carbondata.core.statusmanager.SegmentStatus;
-
-import com.google.gson.Gson;
-
-/**
- * Utility class to get updated segment mapping for index table
- */
-public class MVSegmentStatusUtil {
-
-  /**
-   * This method will convert string to map and return segmentMap
-   */
-  public static Map<String, List<String>> getSegmentMap(String segmentMap) {
-    Gson gson = new Gson();
-    return gson.fromJson(segmentMap, Map.class);
-  }
-
-  /**
-   * In case of compaction on index table,this method will merge the segment list of main table
-   * and return updated segment mapping
-   *
-   * @param mergedLoadName      to find which all segments are merged to new compacted segment
-   * @param indexSchema       of index table
-   * @param loadMetadataDetails of index table
-   * @return updated segment map after merging segment list
-   */
-  public static String getUpdatedSegmentMap(String mergedLoadName, IndexSchema indexSchema,
-      LoadMetadataDetails[] loadMetadataDetails) {
-    Map<String, List<String>> segmentMapping = new HashMap<>();
-    List<RelationIdentifier> relationIdentifiers = indexSchema.getParentTables();
-    for (RelationIdentifier relationIdentifier : relationIdentifiers) {
-      for (LoadMetadataDetails loadMetadataDetail : loadMetadataDetails) {
-        if (loadMetadataDetail.getSegmentStatus() == SegmentStatus.COMPACTED) {
-          if (mergedLoadName.equalsIgnoreCase(loadMetadataDetail.getMergedLoadName())) {
-            if (segmentMapping.isEmpty()) {
-              segmentMapping.putAll(getSegmentMap(loadMetadataDetail.getExtraInfo()));
-            } else {
-              segmentMapping.get(relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT
-                  + relationIdentifier.getTableName()).addAll(
-                  getSegmentMap(loadMetadataDetail.getExtraInfo()).get(
-                      relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT
-                          + relationIdentifier.getTableName()));
-            }
-          }
-        }
-      }
-    }
-    Gson gson = new Gson();
-    return gson.toJson(segmentMapping);
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/index/IndexClassProvider.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/index/IndexClassProvider.java
deleted file mode 100644
index 93e2f16..0000000
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/index/IndexClassProvider.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.core.metadata.schema.index;
-
-/**
- * Please refer {{org.apache.spark.sql.parser.CarbonSpark2SqlParser}}
- */
-public enum IndexClassProvider {
-  LUCENE("org.apache.carbondata.index.lucene.LuceneFineGrainIndexFactory", "lucene"),
-  BLOOMFILTER("org.apache.carbondata.index.bloom.BloomCoarseGrainIndexFactory", "bloomfilter"),
-  MV("org.apache.carbondata.core.index.MVDataMap", "mv");
-
-  /**
-   * Fully qualified class name of index
-   */
-  private String className;
-
-  /**
-   * Short name representation of index
-   */
-  private String shortName;
-
-  IndexClassProvider(String className, String shortName) {
-    this.className = className;
-    this.shortName = shortName;
-  }
-
-  public String getClassName() {
-    return className;
-  }
-
-  public String getShortName() {
-    return shortName;
-  }
-
-  private boolean isEqual(String indexClass) {
-    return (indexClass != null &&
-        (indexClass.equals(className) ||
-            indexClass.equalsIgnoreCase(shortName)));
-  }
-
-  public static IndexClassProvider get(String indexProviderName) {
-    if (LUCENE.isEqual(indexProviderName)) {
-      return LUCENE;
-    } else if (BLOOMFILTER.isEqual(indexProviderName)) {
-      return BLOOMFILTER;
-    } else {
-      throw new UnsupportedOperationException("Unknown index provider" + indexProviderName);
-    }
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/index/MVProviderName.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/index/MVProviderName.java
deleted file mode 100644
index d62c7e8..0000000
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/index/MVProviderName.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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.core.metadata.schema.index;
-
-public class MVProviderName {
-  public static final String NAME = "mv";
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/CarbonTable.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/CarbonTable.java
index bef4cb1..11e1c53 100644
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/CarbonTable.java
+++ b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/CarbonTable.java
@@ -48,7 +48,6 @@ import org.apache.carbondata.core.metadata.datatype.DataTypes;
 import org.apache.carbondata.core.metadata.schema.BucketingInfo;
 import org.apache.carbondata.core.metadata.schema.PartitionInfo;
 import org.apache.carbondata.core.metadata.schema.SchemaReader;
-import org.apache.carbondata.core.metadata.schema.index.IndexClassProvider;
 import org.apache.carbondata.core.metadata.schema.indextable.IndexMetadata;
 import org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo;
 import org.apache.carbondata.core.metadata.schema.partition.PartitionType;
@@ -871,33 +870,6 @@ public class CarbonTable implements Serializable, Writable {
   }
 
   /**
-   * Return true if MV created on this table
-   */
-  public boolean hasMVCreated() throws IOException {
-    List<IndexSchema> schemas = IndexStoreManager.getInstance().getIndexSchemasOfTable(this);
-    return schemas.stream().anyMatch(schema ->
-        schema.getProviderName().equalsIgnoreCase(IndexClassProvider.MV.toString()));
-  }
-
-  /**
-   * Return true if this table is a MV table (child table of other table)
-   */
-  public boolean isMVTable() {
-    String parentTables = tableInfo.getFactTable().getTableProperties()
-        .get(CarbonCommonConstants.PARENT_TABLES);
-    return null != parentTables && !parentTables.isEmpty();
-  }
-
-  /**
-   * Return true if this table is a MV table (child table of other table)
-   */
-  public boolean isChildTableForMV() {
-    return null != tableInfo.getFactTable().getTableProperties()
-        .get(CarbonCommonConstants.PARENT_TABLES) && !tableInfo.getFactTable().getTableProperties()
-        .get(CarbonCommonConstants.PARENT_TABLES).isEmpty();
-  }
-
-  /**
    * Return true if this table is a MV table (child table of other table)
    */
   public boolean isMV() {
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/DatabaseIndexSchemaStorageProvider.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/DatabaseIndexSchemaStorageProvider.java
deleted file mode 100644
index b59c517..0000000
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/DatabaseIndexSchemaStorageProvider.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.core.metadata.schema.table;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.carbondata.common.exceptions.sql.NoSuchIndexException;
-
-/**
- * Stores index schema in database
- */
-public class DatabaseIndexSchemaStorageProvider implements IndexSchemaStorageProvider {
-
-  public DatabaseIndexSchemaStorageProvider() {
-  }
-
-  @Override
-  public void saveSchema(IndexSchema indexSchema) {
-    throw new UnsupportedOperationException("not support saving Index schema into database");
-  }
-
-  @Override
-  public IndexSchema retrieveSchema(String indexName) throws NoSuchIndexException {
-    throw new NoSuchIndexException(indexName);
-  }
-
-  @Override
-  public List<IndexSchema> retrieveSchemas(CarbonTable carbonTable) {
-    return new ArrayList<>(0);
-  }
-
-  @Override
-  public List<IndexSchema> retrieveAllSchemas() {
-    return new ArrayList<>(0);
-  }
-
-  @Override
-  public void dropSchema(String indexName) {
-    throw new UnsupportedOperationException("not support dropping Index schema from database");
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/DiskBasedIndexSchemaStorageProvider.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/DiskBasedIndexSchemaStorageProvider.java
deleted file mode 100644
index b7db89d..0000000
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/DiskBasedIndexSchemaStorageProvider.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * 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.core.metadata.schema.table;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.carbondata.common.exceptions.sql.NoSuchIndexException;
-import org.apache.carbondata.common.logging.LogServiceFactory;
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.datastore.filesystem.CarbonFile;
-import org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter;
-import org.apache.carbondata.core.datastore.impl.FileFactory;
-import org.apache.carbondata.core.util.CarbonUtil;
-
-import com.google.gson.Gson;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.hadoop.fs.permission.FsAction;
-import org.apache.hadoop.fs.permission.FsPermission;
-import org.apache.log4j.Logger;
-
-/**
- * Stores index schema in disk as json format
- */
-public class DiskBasedIndexSchemaStorageProvider implements IndexSchemaStorageProvider {
-
-  private Logger LOG = LogServiceFactory.getLogService(this.getClass().getCanonicalName());
-
-  private String storePath;
-
-  private String mdtFilePath;
-
-  private long lastModifiedTime;
-
-  private Set<IndexSchema> indexSchemas = new HashSet<>();
-
-  public DiskBasedIndexSchemaStorageProvider(String storePath) {
-    this.storePath = CarbonUtil.checkAndAppendHDFSUrl(storePath);
-    this.mdtFilePath = storePath + CarbonCommonConstants.FILE_SEPARATOR + "index.mdtfile";
-  }
-
-  @Override
-  public void saveSchema(IndexSchema indexSchema) throws IOException {
-    BufferedWriter brWriter = null;
-    DataOutputStream dataOutputStream = null;
-    Gson gsonObjectToWrite = new Gson();
-    String schemaPath = getSchemaPath(storePath, indexSchema.getIndexName());
-    if (FileFactory.isFileExist(schemaPath)) {
-      throw new IOException(
-              "Index with name " + indexSchema.getIndexName() + " already exists in storage");
-    }
-    // write the index schema in json format.
-    try {
-      FileFactory.mkdirs(storePath);
-      FileFactory.createNewFile(schemaPath);
-      dataOutputStream =
-          FileFactory.getDataOutputStream(schemaPath);
-      brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream,
-          Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
-
-      String metadataInstance = gsonObjectToWrite.toJson(indexSchema);
-      brWriter.write(metadataInstance);
-    } finally {
-      if (null != brWriter) {
-        brWriter.flush();
-      }
-      indexSchemas.add(indexSchema);
-      CarbonUtil.closeStreams(dataOutputStream, brWriter);
-      checkAndReloadIndexSchemas(true);
-      touchMDTFile();
-    }
-  }
-
-  @Override
-  public IndexSchema retrieveSchema(String indexName) throws IOException, NoSuchIndexException {
-    checkAndReloadIndexSchemas(true);
-    for (IndexSchema indexSchema : indexSchemas) {
-      if (indexSchema.getIndexName().equalsIgnoreCase(indexName)) {
-        return indexSchema;
-      }
-    }
-    throw new NoSuchIndexException(indexName);
-  }
-
-  @Override
-  public List<IndexSchema> retrieveSchemas(CarbonTable carbonTable) throws IOException {
-    checkAndReloadIndexSchemas(false);
-    List<IndexSchema> indexSchemas = new ArrayList<>();
-    for (IndexSchema indexSchema : this.indexSchemas) {
-      List<RelationIdentifier> parentTables = indexSchema.getParentTables();
-      for (RelationIdentifier identifier : parentTables) {
-        if (StringUtils.isNotEmpty(identifier.getTableId())) {
-          if (identifier.getTableId().equalsIgnoreCase(carbonTable.getTableId())) {
-            indexSchemas.add(indexSchema);
-            break;
-          }
-        } else if (identifier.getTableName().equalsIgnoreCase(carbonTable.getTableName()) &&
-            identifier.getDatabaseName().equalsIgnoreCase(carbonTable.getDatabaseName())) {
-          indexSchemas.add(indexSchema);
-          break;
-        }
-      }
-    }
-    return indexSchemas;
-  }
-
-  @Override
-  public List<IndexSchema> retrieveAllSchemas() throws IOException {
-    checkAndReloadIndexSchemas(true);
-    return new ArrayList<>(indexSchemas);
-  }
-
-  private Set<IndexSchema> retrieveAllSchemasInternal() throws IOException {
-    Set<IndexSchema> indexSchemas = new HashSet<>();
-    CarbonFile carbonFile = FileFactory.getCarbonFile(storePath);
-    CarbonFile[] carbonFiles = carbonFile.listFiles(new CarbonFileFilter() {
-      @Override
-      public boolean accept(CarbonFile file) {
-        return file.getName().endsWith(".dmschema");
-      }
-    });
-
-    for (CarbonFile file :carbonFiles) {
-      Gson gsonObjectToRead = new Gson();
-      DataInputStream dataInputStream = null;
-      BufferedReader buffReader = null;
-      InputStreamReader inStream = null;
-      try {
-        String absolutePath = file.getAbsolutePath();
-        dataInputStream =
-            FileFactory.getDataInputStream(
-                absolutePath);
-        inStream = new InputStreamReader(dataInputStream,
-            Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
-        buffReader = new BufferedReader(inStream);
-        indexSchemas.add(gsonObjectToRead.fromJson(buffReader, IndexSchema.class));
-      } finally {
-        CarbonUtil.closeStreams(buffReader, inStream, dataInputStream);
-      }
-    }
-    return indexSchemas;
-  }
-
-  @Override
-  public void dropSchema(String indexName)
-      throws IOException {
-    String schemaPath = getSchemaPath(storePath, indexName);
-    if (!FileFactory.isFileExist(schemaPath)) {
-      throw new IOException("Index with name " + indexName + " does not exists in storage");
-    }
-
-    LOG.info(String.format("Trying to delete Index %s schema", indexName));
-
-    indexSchemas.removeIf(schema -> schema.getIndexName().equalsIgnoreCase(indexName));
-    touchMDTFile();
-    if (!FileFactory.deleteFile(schemaPath)) {
-      throw new IOException("Index with name " + indexName + " cannot be deleted");
-    }
-    LOG.info(String.format("Index %s schema is deleted", indexName));
-  }
-
-  private void checkAndReloadIndexSchemas(boolean touchFile) throws IOException {
-    if (FileFactory.isFileExist(mdtFilePath)) {
-      long lastModifiedTime = FileFactory.getCarbonFile(mdtFilePath).getLastModifiedTime();
-      if (this.lastModifiedTime != lastModifiedTime) {
-        indexSchemas = retrieveAllSchemasInternal();
-        touchMDTFile();
-      }
-    } else {
-      indexSchemas = retrieveAllSchemasInternal();
-      if (touchFile) {
-        touchMDTFile();
-      }
-    }
-  }
-
-  private void touchMDTFile() throws IOException {
-    if (!FileFactory.isFileExist(storePath)) {
-      FileFactory.createDirectoryAndSetPermission(
-          storePath,
-          new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
-    }
-    if (!FileFactory.isFileExist(mdtFilePath)) {
-      FileFactory.createNewFile(
-          mdtFilePath,
-          new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
-    }
-    long lastModifiedTime = System.currentTimeMillis();
-    FileFactory.getCarbonFile(mdtFilePath).setLastModifiedTime(lastModifiedTime);
-    this.lastModifiedTime = lastModifiedTime;
-  }
-
-  /**
-   * it returns the schema path for the index
-   * @param storePath
-   * @param indexName
-   * @return
-   */
-  public static String getSchemaPath(String storePath, String indexName) {
-    String schemaPath =  storePath + CarbonCommonConstants.FILE_SEPARATOR + indexName
-        + ".dmschema";
-    return schemaPath;
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchema.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchema.java
index dcd88ff..c128271 100644
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchema.java
+++ b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchema.java
@@ -22,28 +22,14 @@ import java.io.DataOutput;
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.Set;
 
-import org.apache.carbondata.common.Strings;
 import org.apache.carbondata.common.exceptions.sql.MalformedIndexCommandException;
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.index.IndexUtil;
-import org.apache.carbondata.core.index.status.IndexStatus;
-import org.apache.carbondata.core.index.status.IndexStatusDetail;
-import org.apache.carbondata.core.index.status.IndexStatusManager;
-import org.apache.carbondata.core.index.status.MVSegmentStatusUtil;
 import org.apache.carbondata.core.metadata.schema.index.IndexProperty;
-import org.apache.carbondata.core.statusmanager.LoadMetadataDetails;
-import org.apache.carbondata.core.statusmanager.SegmentStatus;
-import org.apache.carbondata.core.statusmanager.SegmentStatusManager;
-import org.apache.carbondata.core.util.path.CarbonTablePath;
 
 import static org.apache.carbondata.core.constants.CarbonCommonConstants.INDEX_COLUMNS;
 
-import com.google.gson.Gson;
 import com.google.gson.annotations.SerializedName;
 import org.apache.commons.lang.StringUtils;
 
@@ -71,40 +57,15 @@ public class IndexSchema implements Serializable, Writable {
   protected RelationIdentifier relationIdentifier;
 
   /**
-   * SQL query string used to create MV
-   */
-  protected String ctasQuery;
-
-  /**
    * Properties provided by user
    */
   protected Map<String, String> properties;
 
   /**
-   * Identifiers of parent tables of the MV
-   */
-  protected List<RelationIdentifier> parentTables;
-
-  /**
    * child table schema
    */
   protected TableSchema childSchema;
 
-  /**
-   * main table column list mapped to index table
-   */
-  private Map<String, Set<String>> mainTableColumnList;
-
-  /**
-   * Index table column order map as per Select query
-   */
-  private Map<Integer, String> columnsOrderMap;
-
-  /**
-   * timeseries query
-   */
-  private boolean isTimeSeries;
-
   public IndexSchema(String indexName, String providerName) {
     this.indexName = indexName;
     this.providerName = providerName;
@@ -133,14 +94,6 @@ public class IndexSchema implements Serializable, Writable {
     this.relationIdentifier = relationIdentifier;
   }
 
-  public String getCtasQuery() {
-    return ctasQuery;
-  }
-
-  public void setCtasQuery(String ctasQuery) {
-    this.ctasQuery = ctasQuery;
-  }
-
   public Map<String, String> getProperties() {
     return properties;
   }
@@ -149,22 +102,6 @@ public class IndexSchema implements Serializable, Writable {
     this.properties = properties;
   }
 
-  public void setParentTables(List<RelationIdentifier> parentTables) {
-    this.parentTables = parentTables;
-  }
-
-  public List<RelationIdentifier> getParentTables() {
-    return parentTables;
-  }
-
-  public TableSchema getChildSchema() {
-    return childSchema;
-  }
-
-  public void setChildSchema(TableSchema childSchema) {
-    this.childSchema = childSchema;
-  }
-
   /**
    * Return true if this is an Index
    * @return
@@ -261,96 +198,4 @@ public class IndexSchema implements Serializable, Writable {
     return Objects.hash(indexName);
   }
 
-  public Map<String, Set<String>> getMainTableColumnList() {
-    return mainTableColumnList;
-  }
-
-  public void setMainTableColumnList(Map<String, Set<String>> mainTableColumnList) {
-    this.mainTableColumnList = mainTableColumnList;
-  }
-
-  public Map<Integer, String> getColumnsOrderMap() {
-    return columnsOrderMap;
-  }
-
-  public void setColumnsOrderMap(Map<Integer, String> columnsOrderMap) {
-    this.columnsOrderMap = columnsOrderMap;
-  }
-
-  public boolean isTimeSeries() {
-    return isTimeSeries;
-  }
-
-  public void setTimeSeries(boolean timeSeries) {
-    isTimeSeries = timeSeries;
-  }
-
-  /**
-   * Return true if this Index can support incremental build
-   */
-  public boolean canBeIncrementalBuild() {
-    String prop = getProperties().get(IndexProperty.FULL_REFRESH);
-    return prop == null || prop.equalsIgnoreCase("false");
-  }
-
-  public String getPropertiesAsString() {
-    String[] properties = getProperties().entrySet().stream()
-        // ignore internal used property
-        .filter(p ->
-            !p.getKey().equalsIgnoreCase(IndexProperty.DEFERRED_REBUILD) &&
-            !p.getKey().equalsIgnoreCase(IndexProperty.FULL_REFRESH))
-        .map(p -> "'" + p.getKey() + "'='" + p.getValue() + "'")
-        .sorted()
-        .toArray(String[]::new);
-    return Strings.mkString(properties, ",");
-  }
-
-  public String getUniqueTableName() {
-    return relationIdentifier.getDatabaseName() + CarbonCommonConstants.POINT +
-        relationIdentifier.getTableName();
-  }
-
-  public IndexStatus getStatus() throws IOException {
-    IndexStatusDetail[] details = IndexStatusManager.getEnabledIndexStatusDetails();
-    for (IndexStatusDetail detail : details) {
-      if (detail.getIndexName().equalsIgnoreCase(this.getIndexName())) {
-        return IndexStatus.ENABLED;
-      }
-    }
-    return IndexStatus.DISABLED;
-  }
-
-  public String getSyncStatus() {
-    LoadMetadataDetails[] loads =
-        SegmentStatusManager.readLoadMetadata(
-            CarbonTablePath.getMetadataPath(this.getRelationIdentifier().getTablePath()));
-    if (!isIndex() && loads.length > 0) {
-      for (int i = loads.length - 1; i >= 0; i--) {
-        LoadMetadataDetails load = loads[i];
-        if (load.getSegmentStatus().equals(SegmentStatus.SUCCESS)) {
-          Map<String, List<String>> segmentMaps =
-              MVSegmentStatusUtil.getSegmentMap(load.getExtraInfo());
-          Map<String, String> syncInfoMap = new HashMap<>();
-          for (Map.Entry<String, List<String>> entry : segmentMaps.entrySet()) {
-            // when in join scenario, one table is loaded and one more is not loaded,
-            // then put value as NA
-            if (entry.getValue().isEmpty()) {
-              syncInfoMap.put(entry.getKey(), "NA");
-            } else {
-              syncInfoMap.put(entry.getKey(), IndexUtil.getMaxSegmentID(entry.getValue()));
-            }
-          }
-          String loadEndTime;
-          if (load.getLoadEndTime() == CarbonCommonConstants.SEGMENT_LOAD_TIME_DEFAULT) {
-            loadEndTime = "NA";
-          } else {
-            loadEndTime = new java.sql.Timestamp(load.getLoadEndTime()).toString();
-          }
-          syncInfoMap.put(CarbonCommonConstants.LOAD_SYNC_TIME, loadEndTime);
-          return new Gson().toJson(syncInfoMap);
-        }
-      }
-    }
-    return "NA";
-  }
 }
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchemaFactory.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchemaFactory.java
deleted file mode 100644
index 2d90904..0000000
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchemaFactory.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.core.metadata.schema.table;
-
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.util.CarbonProperties;
-
-public class IndexSchemaFactory {
-  public static final IndexSchemaFactory INSTANCE = new IndexSchemaFactory();
-
-  public static IndexSchemaStorageProvider getIndexSchemaStorageProvider() {
-    String provider = CarbonProperties.getIndexStorageProvider();
-    switch (provider) {
-      case CarbonCommonConstants.CARBON_INDEX_SCHEMA_STORAGE_DATABASE:
-        return new DatabaseIndexSchemaStorageProvider();
-      case CarbonCommonConstants.CARBON_INDEX_SCHEMA_STORAGE_DISK:
-      default:
-        return new DiskBasedIndexSchemaStorageProvider(
-            CarbonProperties.getInstance().getSystemFolderLocation());
-    }
-  }
-}
diff --git a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchemaStorageProvider.java b/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchemaStorageProvider.java
deleted file mode 100644
index 3320bc2..0000000
--- a/core/src/main/java/org/apache/carbondata/core/metadata/schema/table/IndexSchemaStorageProvider.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.core.metadata.schema.table;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.carbondata.common.annotations.InterfaceAudience;
-import org.apache.carbondata.common.exceptions.sql.NoSuchIndexException;
-
-/**
- *It is used to save/retreive/drop index schema from storage medium like disk or DB.
- * Here index name must be unique across whole store.
- *
- * @since 1.4.0
- */
-@InterfaceAudience.Internal
-public interface IndexSchemaStorageProvider {
-
-  /**
-   * Save the schema to storage medium.
-   * @param indexSchema
-   */
-  void saveSchema(IndexSchema indexSchema) throws IOException;
-
-  /**
-   * Retrieve the schema by using index name.
-   * @param indexName
-   */
-  IndexSchema retrieveSchema(String indexName) throws IOException, NoSuchIndexException;
-
-  /**
-   * Retrieve schemas of the given table.
-   * @param table
-   * @return
-   * @throws IOException
-   */
-  List<IndexSchema> retrieveSchemas(CarbonTable table) throws IOException;
-
-  /**
-   * Retrieve all index schemas from store.
-   * @return
-   * @throws IOException
-   */
-  List<IndexSchema> retrieveAllSchemas() throws IOException;
-
-  /**
-   * Drop the schema from the storage by using index name.
-   * @param indexName
-   */
-  void dropSchema(String indexName) throws IOException;
-
-}
diff --git a/core/src/test/java/org/apache/carbondata/core/metadata/schema/table/DiskBasedDMSchemaStoraheProviderSuite.java b/core/src/test/java/org/apache/carbondata/core/metadata/schema/table/DiskBasedDMSchemaStoraheProviderSuite.java
deleted file mode 100644
index 2c2db80..0000000
--- a/core/src/test/java/org/apache/carbondata/core/metadata/schema/table/DiskBasedDMSchemaStoraheProviderSuite.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * 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.core.metadata.schema.table;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.carbondata.common.exceptions.sql.NoSuchIndexException;
-import org.apache.carbondata.core.constants.CarbonCommonConstants;
-import org.apache.carbondata.core.datastore.filesystem.CarbonFile;
-import org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter;
-import org.apache.carbondata.core.datastore.impl.FileFactory;
-import org.apache.carbondata.core.util.CarbonProperties;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class DiskBasedDMSchemaStoraheProviderSuite {
-
-  @BeforeClass public static void setUp() throws IOException {
-    String path =
-        new File(DiskBasedDMSchemaStoraheProviderSuite.class.getResource("/").getPath() + "../")
-            .getCanonicalPath().replaceAll("\\\\", "/");
-
-    CarbonProperties.getInstance()
-        .addProperty(CarbonCommonConstants.CARBON_SYSTEM_FOLDER_LOCATION, path);
-    FileFactory.deleteAllCarbonFilesOfDir(
-        FileFactory.getCarbonFile(CarbonProperties.getInstance().getSystemFolderLocation()));
-  }
-
-  @AfterClass public static void tearDown() {
-    FileFactory.deleteAllCarbonFilesOfDir(
-        FileFactory.getCarbonFile(CarbonProperties.getInstance().getSystemFolderLocation()));
-  }
-
-  private DiskBasedIndexSchemaStorageProvider provider = new DiskBasedIndexSchemaStorageProvider(
-      CarbonProperties.getInstance().getSystemFolderLocation());
-
-  @Test public void testSaveSchema() throws IOException, NoSuchIndexException {
-    IndexSchema indexSchema = createIndexSchema("dm1", "table1");
-    provider.saveSchema(indexSchema);
-    CarbonFile[] schemaFilesFromLocation = getSchemaFilesFromLocation();
-    assert (existsSchema(indexSchema, schemaFilesFromLocation));
-    IndexSchema indexSchema1 = provider.retrieveSchema("dm1");
-    assert (indexSchema.getIndexName().equals(indexSchema1.getIndexName()));
-  }
-
-  @Test public void testDropSchema() throws IOException {
-    IndexSchema indexSchema = createIndexSchema("dm2", "table1");
-    provider.saveSchema(indexSchema);
-    provider.dropSchema("dm2");
-    CarbonFile[] schemaFilesFromLocation = getSchemaFilesFromLocation();
-    for (CarbonFile file : schemaFilesFromLocation) {
-      assert (!file.getName().contains("dm2"));
-    }
-    try {
-      provider.retrieveSchema("dm2");
-      assert (false);
-    } catch (NoSuchIndexException e) {
-      // Ignore
-    }
-  }
-
-  @Test public void testRetriveAllSchemas() throws IOException {
-    IndexSchema indexSchema1 = createIndexSchema("dm3", "table1");
-    IndexSchema indexSchema2 = createIndexSchema("dm4", "table1");
-    IndexSchema indexSchema3 = createIndexSchema("dm5", "table1");
-    provider.saveSchema(indexSchema1);
-    provider.saveSchema(indexSchema2);
-    provider.saveSchema(indexSchema3);
-
-    List<IndexSchema> indexSchemas = provider.retrieveAllSchemas();
-    assert (existsSchema(indexSchema1, indexSchemas));
-    assert (existsSchema(indexSchema2, indexSchemas));
-    assert (existsSchema(indexSchema3, indexSchemas));
-  }
-
-  @Test public void testWithOtherProvider() throws IOException, InterruptedException {
-    IndexSchema indexSchema1 = createIndexSchema("dm6", "table1");
-    IndexSchema indexSchema2 = createIndexSchema("dm7", "table1");
-    IndexSchema indexSchema3 = createIndexSchema("dm8", "table1");
-    provider.saveSchema(indexSchema1);
-    Thread.sleep(400);
-    provider.saveSchema(indexSchema2);
-    Thread.sleep(400);
-    DiskBasedIndexSchemaStorageProvider provider1 = new DiskBasedIndexSchemaStorageProvider(
-        CarbonProperties.getInstance().getSystemFolderLocation());
-    provider1.saveSchema(indexSchema3);
-    Thread.sleep(400);
-
-    List<IndexSchema> indexSchemas = provider1.retrieveAllSchemas();
-    assert (existsSchema(indexSchema1, indexSchemas));
-    assert (existsSchema(indexSchema2, indexSchemas));
-    assert (existsSchema(indexSchema3, indexSchemas));
-
-    List<IndexSchema> indexSchemas1 = provider.retrieveAllSchemas();
-    assert (existsSchema(indexSchema1, indexSchemas1));
-    assert (existsSchema(indexSchema2, indexSchemas1));
-    assert (existsSchema(indexSchema3, indexSchemas1));
-  }
-
-  @Test public void testDropWithOtherProvider() throws IOException, InterruptedException {
-    IndexSchema indexSchema1 = createIndexSchema("dm9", "table1");
-    IndexSchema indexSchema2 = createIndexSchema("dm10", "table1");
-    IndexSchema indexSchema3 = createIndexSchema("dm11", "table1");
-    provider.saveSchema(indexSchema1);
-    Thread.sleep(400);
-    provider.saveSchema(indexSchema2);
-    Thread.sleep(400);
-    provider.saveSchema(indexSchema3);
-    Thread.sleep(400);
-
-    DiskBasedIndexSchemaStorageProvider provider1 = new DiskBasedIndexSchemaStorageProvider(
-        CarbonProperties.getInstance().getSystemFolderLocation());
-    provider1.dropSchema(indexSchema3.getIndexName());
-    Thread.sleep(400);
-
-    List<IndexSchema> indexSchemas = provider1.retrieveAllSchemas();
-    assert (existsSchema(indexSchema1, indexSchemas));
-    assert (existsSchema(indexSchema2, indexSchemas));
-    assert (!existsSchema(indexSchema3, indexSchemas));
-
-    List<IndexSchema> indexSchemas1 = provider.retrieveAllSchemas();
-    assert (existsSchema(indexSchema1, indexSchemas1));
-    assert (existsSchema(indexSchema2, indexSchemas1));
-    assert (!existsSchema(indexSchema3, indexSchemas1));
-  }
-
-  private boolean existsSchema(IndexSchema schema, List<IndexSchema> indexSchemas) {
-    for (IndexSchema indexSchema : indexSchemas) {
-      if (indexSchema.getIndexName().equals(schema.getIndexName())) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  private boolean existsSchema(IndexSchema schema, CarbonFile[] carbonFiles) {
-    for (CarbonFile indexSchema : carbonFiles) {
-      if (indexSchema.getName().contains(schema.getIndexName())) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  private IndexSchema createIndexSchema(String name, String table) {
-    IndexSchema mapSchema = new IndexSchema(name, "index");
-    RelationIdentifier identifier = new RelationIdentifier("default", table, "");
-
-    ArrayList<RelationIdentifier> parentTables = new ArrayList<>();
-    parentTables.add(identifier);
-    mapSchema.setParentTables(parentTables);
-    mapSchema.setRelationIdentifier(identifier);
-    return mapSchema;
-  }
-
-  private CarbonFile[] getSchemaFilesFromLocation() {
-    CarbonFile carbonFile =
-        FileFactory.getCarbonFile(CarbonProperties.getInstance().getSystemFolderLocation());
-    CarbonFile[] carbonFiles = carbonFile.listFiles(new CarbonFileFilter() {
-      @Override
-      public boolean accept(CarbonFile file) {
-        return file.getName().endsWith(".dmschema");
-      }
-    });
-    return carbonFiles;
-  }
-
-}
diff --git a/integration/spark/src/main/java/org/apache/carbondata/index/IndexManager.java b/integration/spark/src/main/java/org/apache/carbondata/index/IndexManager.java
deleted file mode 100644
index 720f529..0000000
--- a/integration/spark/src/main/java/org/apache/carbondata/index/IndexManager.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.index;
-
-import org.apache.carbondata.common.exceptions.sql.MalformedIndexCommandException;
-import org.apache.carbondata.core.index.CarbonIndexProvider;
-import org.apache.carbondata.core.metadata.schema.index.IndexClassProvider;
-import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema;
-import org.apache.carbondata.spark.util.CarbonScalaUtil;
-
-import org.apache.spark.sql.SparkSession;
-
-public class IndexManager {
-
-  private static IndexManager INSTANCE;
-
-  private IndexManager() { }
-
-  public static synchronized IndexManager get() {
-    if (INSTANCE == null) {
-      INSTANCE = new IndexManager();
-    }
-    return INSTANCE;
-  }
-
-  /**
-   * Return a IndexClassProvider instance for specified indexSchema.
-   */
-  public CarbonIndexProvider getIndexProvider(CarbonTable mainTable, IndexSchema indexSchema,
-      SparkSession sparkSession) throws MalformedIndexCommandException {
-    org.apache.carbondata.core.index.CarbonIndexProvider provider;
-    if (indexSchema.getProviderName().equalsIgnoreCase(IndexClassProvider.MV.toString())) {
-      provider = (org.apache.carbondata.core.index.CarbonIndexProvider) CarbonScalaUtil
-          .createIndexProvider("org.apache.carbondata.mv.extension.MVDataMapProvider",
-              sparkSession, mainTable, indexSchema);
-    } else {
-      provider =
-          new org.apache.carbondata.index.IndexProvider(mainTable, indexSchema, sparkSession);
-    }
-    return provider;
-  }
-
-}
diff --git a/integration/spark/src/main/java/org/apache/carbondata/index/IndexProvider.java b/integration/spark/src/main/java/org/apache/carbondata/index/IndexProvider.java
index 23490f9..436ba55 100644
--- a/integration/spark/src/main/java/org/apache/carbondata/index/IndexProvider.java
+++ b/integration/spark/src/main/java/org/apache/carbondata/index/IndexProvider.java
@@ -17,14 +17,11 @@
 
 package org.apache.carbondata.index;
 
-import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.carbondata.common.annotations.InterfaceAudience;
 import org.apache.carbondata.common.exceptions.MetadataProcessException;
 import org.apache.carbondata.common.exceptions.sql.MalformedIndexCommandException;
-import org.apache.carbondata.core.index.CarbonIndexProvider;
 import org.apache.carbondata.core.index.IndexRegistry;
 import org.apache.carbondata.core.index.dev.Index;
 import org.apache.carbondata.core.index.dev.IndexFactory;
@@ -38,7 +35,10 @@ import org.apache.spark.sql.SparkSession;
  * Interface to manipulate the index, All index should implement this interface.
  */
 @InterfaceAudience.Internal
-public class IndexProvider extends CarbonIndexProvider {
+public class IndexProvider {
+
+  private CarbonTable mainTable;
+  private IndexSchema indexSchema;
 
   private SparkSession sparkSession;
   private IndexFactory<? extends Index> indexFactory;
@@ -46,34 +46,29 @@ public class IndexProvider extends CarbonIndexProvider {
 
   public IndexProvider(CarbonTable table, IndexSchema schema, SparkSession sparkSession)
       throws MalformedIndexCommandException {
-    super(table, schema);
+    this.mainTable = table;
+    this.indexSchema = schema;
     this.sparkSession = sparkSession;
     this.indexFactory = createIndexFactory();
     this.indexedColumns = table.getIndexedColumns(schema.getIndexColumns());
   }
 
-  public void setMainTable(CarbonTable carbonTable) {
-    super.setMainTable(carbonTable);
-  }
-
-  public List<CarbonColumn> getIndexedColumns() {
-    return indexedColumns;
+  protected final CarbonTable getMainTable() {
+    return mainTable;
   }
 
-  @Override
-  public void initMeta(String ctasSqlStatement)
-      throws MalformedIndexCommandException, IOException {
+  public final IndexSchema getIndexSchema() {
+    return indexSchema;
   }
 
-  @Override
-  public void cleanMeta() throws IOException {
+  public void setMainTable(CarbonTable carbonTable) {
+    this.mainTable = carbonTable;
   }
 
-  @Override
-  public void cleanData() {
+  public List<CarbonColumn> getIndexedColumns() {
+    return indexedColumns;
   }
 
-  @Override
   public boolean rebuild() {
     IndexRebuildRDD.rebuildIndex(sparkSession, getMainTable(), getIndexSchema());
     return true;
@@ -100,19 +95,12 @@ public class IndexProvider extends CarbonIndexProvider {
     return indexFactory;
   }
 
-  @Override
   public IndexFactory getIndexFactory() {
     return indexFactory;
   }
 
-  @Override
   public boolean supportRebuild() {
     return indexFactory.supportRebuild();
   }
 
-  @Override
-  public boolean rebuildInternal(String newLoadName, Map<String, List<String>> segmentMap,
-      CarbonTable carbonTable) {
-    return false;
-  }
 }
diff --git a/integration/spark/src/main/scala/org/apache/carbondata/spark/rdd/CarbonDataRDDFactory.scala b/integration/spark/src/main/scala/org/apache/carbondata/spark/rdd/CarbonDataRDDFactory.scala
index 958de68..8b67bd4 100644
--- a/integration/spark/src/main/scala/org/apache/carbondata/spark/rdd/CarbonDataRDDFactory.scala
+++ b/integration/spark/src/main/scala/org/apache/carbondata/spark/rdd/CarbonDataRDDFactory.scala
@@ -52,12 +52,11 @@ import org.apache.carbondata.core.datastore.filesystem.CarbonFile
 import org.apache.carbondata.core.datastore.impl.FileFactory
 import org.apache.carbondata.core.exception.ConcurrentOperationException
 import org.apache.carbondata.core.index.{IndexStoreManager, Segment}
-import org.apache.carbondata.core.index.status.IndexStatusManager
 import org.apache.carbondata.core.locks.{CarbonLockFactory, ICarbonLock, LockUsage}
 import org.apache.carbondata.core.metadata.{CarbonTableIdentifier, ColumnarFormatVersion, SegmentFileStore}
 import org.apache.carbondata.core.metadata.schema.table.CarbonTable
 import org.apache.carbondata.core.mutate.CarbonUpdateUtil
-import org.apache.carbondata.core.segmentmeta.{SegmentMetaDataInfo, SegmentMetaDataInfoStats}
+import org.apache.carbondata.core.segmentmeta.SegmentMetaDataInfo
 import org.apache.carbondata.core.statusmanager.{LoadMetadataDetails, SegmentStatus, SegmentStatusManager}
 import org.apache.carbondata.core.util.{CarbonProperties, CarbonUtil, ThreadLocalSessionInfo}
 import org.apache.carbondata.core.util.path.CarbonTablePath
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala
index 82b646e..63bc70d 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonEnv.scala
@@ -171,8 +171,7 @@ object CarbonEnv {
       .addListener(classOf[BuildIndexPostExecutionEvent], new MergeBloomIndexEventListener)
       .addListener(classOf[DropTableCacheEvent], DropCacheMVEventListener)
       .addListener(classOf[DropTableCacheEvent], DropCacheBloomEventListener)
-      .addListener(classOf[ShowTableCacheEvent], ShowCachePreMVEventListener)
-      .addListener(classOf[ShowTableCacheEvent], ShowCacheIndexEventListener)
+      .addListener(classOf[ShowTableCacheEvent], ShowCacheEventListener)
       .addListener(classOf[LoadTablePreStatusUpdateEvent], new SILoadEventListener)
       .addListener(classOf[LoadTablePostStatusUpdateEvent],
         new SILoadEventListenerForFailedSegments)
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/CarbonCreateIndexCommand.scala b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/CarbonCreateIndexCommand.scala
index cc1560a..83f593e 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/CarbonCreateIndexCommand.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/CarbonCreateIndexCommand.scala
@@ -85,7 +85,7 @@ case class CarbonCreateIndexCommand(
       throw new MalformedCarbonCommandException("Unsupported operation on non transactional table")
     }
 
-    if (parentTable.isMVTable || parentTable.isIndexTable) {
+    if (parentTable.isMV || parentTable.isIndexTable) {
       throw new MalformedIndexCommandException(
         "Cannot create index on child table `" + indexName + "`")
     }
@@ -212,7 +212,6 @@ case class CarbonCreateIndexCommand(
   override def processData(sparkSession: SparkSession): Seq[Row] = {
     if (provider != null) {
       provider.setMainTable(parentTable)
-      provider.initData()
       if (!deferredRebuild) {
         provider.rebuild()
         // enable bloom or lucene index
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAddLoadCommand.scala b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAddLoadCommand.scala
index 5c66b54..f7e8b42 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAddLoadCommand.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAddLoadCommand.scala
@@ -37,7 +37,6 @@ import org.apache.carbondata.common.logging.LogServiceFactory
 import org.apache.carbondata.core.datastore.impl.FileFactory
 import org.apache.carbondata.core.exception.ConcurrentOperationException
 import org.apache.carbondata.core.index.{IndexStoreManager, Segment}
-import org.apache.carbondata.core.index.status.IndexStatusManager
 import org.apache.carbondata.core.indexstore.{PartitionSpec => CarbonPartitionSpec}
 import org.apache.carbondata.core.metadata.SegmentFileStore
 import org.apache.carbondata.core.metadata.datatype.Field
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAlterTableCompactionCommand.scala b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAlterTableCompactionCommand.scala
index e67c849..aa1d294 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAlterTableCompactionCommand.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonAlterTableCompactionCommand.scala
@@ -37,7 +37,6 @@ import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.datastore.compression.CompressorFactory
 import org.apache.carbondata.core.datastore.impl.FileFactory
 import org.apache.carbondata.core.exception.ConcurrentOperationException
-import org.apache.carbondata.core.index.status.IndexStatusManager
 import org.apache.carbondata.core.locks.{CarbonLockFactory, LockUsage}
 import org.apache.carbondata.core.metadata.ColumnarFormatVersion
 import org.apache.carbondata.core.metadata.schema.table.{CarbonTable, TableInfo}
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForDeleteCommand.scala b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForDeleteCommand.scala
index 8ff67f9..5eed830 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForDeleteCommand.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForDeleteCommand.scala
@@ -17,8 +17,6 @@
 
 package org.apache.spark.sql.execution.command.mutation
 
-import scala.collection.JavaConverters._
-
 import org.apache.spark.sql._
 import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
 import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
@@ -30,8 +28,6 @@ import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandExcepti
 import org.apache.carbondata.common.logging.LogServiceFactory
 import org.apache.carbondata.core.exception.ConcurrentOperationException
 import org.apache.carbondata.core.features.TableOperation
-import org.apache.carbondata.core.index.IndexStoreManager
-import org.apache.carbondata.core.index.status.IndexStatusManager
 import org.apache.carbondata.core.locks.{CarbonLockFactory, CarbonLockUtil, LockUsage}
 import org.apache.carbondata.core.mutate.CarbonUpdateUtil
 import org.apache.carbondata.core.statusmanager.SegmentStatusManager
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForUpdateCommand.scala b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForUpdateCommand.scala
index c1bbf9f..43ef3f3 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForUpdateCommand.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/CarbonProjectForUpdateCommand.scala
@@ -17,8 +17,6 @@
 
 package org.apache.spark.sql.execution.command.mutation
 
-import scala.collection.JavaConverters._
-
 import org.apache.spark.sql._
 import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
 import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project}
@@ -35,8 +33,7 @@ import org.apache.carbondata.common.logging.LogServiceFactory
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.exception.ConcurrentOperationException
 import org.apache.carbondata.core.features.TableOperation
-import org.apache.carbondata.core.index.{IndexStoreManager, Segment}
-import org.apache.carbondata.core.index.status.IndexStatusManager
+import org.apache.carbondata.core.index.Segment
 import org.apache.carbondata.core.locks.{CarbonLockFactory, CarbonLockUtil, LockUsage}
 import org.apache.carbondata.core.mutate.CarbonUpdateUtil
 import org.apache.carbondata.core.statusmanager.SegmentStatusManager
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
index 4c9165f..f0b2287 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
@@ -81,7 +81,7 @@ private[sql] case class CarbonAlterTableRenameCommand(
     }
     // if table have created MV, not support table rename
     if (MVManagerInSpark.get(sparkSession).hasSchemaOnTable(oldCarbonTable) ||
-        oldCarbonTable.hasMVCreated || oldCarbonTable.isMV) {
+        oldCarbonTable.isMV) {
       throw new MalformedCarbonCommandException(
         "alter rename is not supported for MV table or for tables which have child MV")
     }
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/strategy/DDLHelper.scala b/integration/spark/src/main/scala/org/apache/spark/sql/execution/strategy/DDLHelper.scala
index 9b27283..ad81e79 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/strategy/DDLHelper.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/strategy/DDLHelper.scala
@@ -388,10 +388,6 @@ object DDLHelper {
           throw new MalformedCarbonCommandException(
             "The table which has materialized view does not support set streaming property")
         }
-        if (carbonTable.hasMVCreated) {
-          throw new MalformedCarbonCommandException(
-            "The table which has materialized view does not support set streaming property")
-        }
       }
     }
     CarbonAlterTableSetCommand(tableName, properties, setProperties.isView)
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala
index e42e03f..04996a0 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala
@@ -34,8 +34,6 @@ import org.apache.spark.sql.util.CarbonException
 import org.apache.spark.util.CarbonReflectionUtils
 
 import org.apache.carbondata.core.constants.CarbonCommonConstants
-import org.apache.carbondata.core.index.IndexStoreManager
-import org.apache.carbondata.core.index.status.IndexStatusManager
 import org.apache.carbondata.core.view.MVStatus
 import org.apache.carbondata.view.MVManagerInSpark
 
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/listeners/DropCacheEventListeners.scala b/integration/spark/src/main/scala/org/apache/spark/sql/listeners/DropCacheEventListeners.scala
index 91b81cc..3a3d5b2 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/listeners/DropCacheEventListeners.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/listeners/DropCacheEventListeners.scala
@@ -27,10 +27,11 @@ import org.apache.spark.sql.execution.command.cache.{CacheUtil, CarbonDropCacheC
 
 import org.apache.carbondata.common.logging.LogServiceFactory
 import org.apache.carbondata.core.cache.CacheProvider
-import org.apache.carbondata.core.index.IndexStoreManager
 import org.apache.carbondata.core.metadata.index.IndexType
 import org.apache.carbondata.core.metadata.schema.table.IndexSchema
+import org.apache.carbondata.core.view.MVSchema
 import org.apache.carbondata.events.{DropTableCacheEvent, Event, OperationContext, OperationEventListener}
+import org.apache.carbondata.view.MVManagerInSpark
 
 object DropCacheMVEventListener extends OperationEventListener {
 
@@ -49,23 +50,20 @@ object DropCacheMVEventListener extends OperationEventListener {
           throw new UnsupportedOperationException("Operation not allowed on child table.")
         }
 
-        if (carbonTable.hasMVCreated) {
-          val childrenSchemas = IndexStoreManager.getInstance
-            .getIndexSchemasOfTable(carbonTable).asScala
-            .filter(indexSchema => null != indexSchema.getRelationIdentifier &&
-                                   !indexSchema.isIndex)
-          dropCacheForChildTables(sparkSession, childrenSchemas)
+        val mvSchemas = MVManagerInSpark.get(sparkSession).getSchemasOnTable(carbonTable)
+        if (!mvSchemas.isEmpty) {
+          dropCacheForChildTables(sparkSession, mvSchemas.asScala)
         }
     }
   }
 
   private def dropCacheForChildTables(sparkSession: SparkSession,
-      childrenSchemas: mutable.Buffer[IndexSchema]): Unit = {
-    for (childSchema <- childrenSchemas) {
+        mvSchemas: mutable.Buffer[MVSchema]): Unit = {
+    for (mvSchema <- mvSchemas) {
       val childTable =
         CarbonEnv.getCarbonTable(
-          TableIdentifier(childSchema.getRelationIdentifier.getTableName,
-            Some(childSchema.getRelationIdentifier.getDatabaseName)))(sparkSession)
+          TableIdentifier(mvSchema.getIdentifier.getTableName,
+            Some(mvSchema.getIdentifier.getDatabaseName)))(sparkSession)
       try {
         val dropCacheCommandForChildTable =
           CarbonDropCacheCommand(
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/listeners/ShowCacheEventListener.scala b/integration/spark/src/main/scala/org/apache/spark/sql/listeners/ShowCacheEventListener.scala
new file mode 100644
index 0000000..dabdd4e
--- /dev/null
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/listeners/ShowCacheEventListener.scala
@@ -0,0 +1,59 @@
+/*
+* 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.spark.sql.listeners
+
+import scala.collection.JavaConverters._
+
+import org.apache.carbondata.common.logging.LogServiceFactory
+import org.apache.carbondata.events._
+import org.apache.carbondata.view.MVManagerInSpark
+
+object ShowCacheEventListener extends OperationEventListener {
+
+  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
+
+  /**
+   * Called on a specified event occurrence
+   */
+  override protected def onEvent(event: Event, operationContext: OperationContext): Unit = {
+    event match {
+      case showTableCacheEvent: ShowTableCacheEvent =>
+        val carbonTable = showTableCacheEvent.carbonTable
+        val internalCall = showTableCacheEvent.internalCall
+        if (carbonTable.isMV && !internalCall) {
+          throw new UnsupportedOperationException("Operation not allowed on child table.")
+        }
+
+        val childTables = operationContext.getProperty(carbonTable.getTableUniqueName)
+          .asInstanceOf[List[(String, String)]]
+        val views =
+          MVManagerInSpark.get(showTableCacheEvent.sparkSession).getSchemasOnTable(carbonTable)
+        if (!views.isEmpty) {
+          val mvTables = views.asScala.collect {
+            case view =>
+              (
+                s"${view.getIdentifier.getDatabaseName}-${view.getIdentifier.getTableName}",
+                "mv",
+                view.getIdentifier.getTableId
+              )
+          }
+          operationContext.setProperty(carbonTable.getTableUniqueName, childTables ++ mvTables)
+        }
+    }
+  }
+}
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/listeners/ShowCacheEventListeners.scala b/integration/spark/src/main/scala/org/apache/spark/sql/listeners/ShowCacheEventListeners.scala
deleted file mode 100644
index 510a9af..0000000
--- a/integration/spark/src/main/scala/org/apache/spark/sql/listeners/ShowCacheEventListeners.scala
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
-* 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.spark.sql.listeners
-
-import scala.collection.JavaConverters._
-
-import org.apache.carbondata.common.logging.LogServiceFactory
-import org.apache.carbondata.core.index.IndexStoreManager
-import org.apache.carbondata.core.metadata.schema.index.IndexClassProvider
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema
-import org.apache.carbondata.events._
-
-object ShowCachePreMVEventListener extends OperationEventListener {
-
-  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
-
-  /**
-   * Called on a specified event occurrence
-   *
-   * @param event
-   * @param operationContext
-   */
-  override protected def onEvent(event: Event, operationContext: OperationContext): Unit = {
-    event match {
-      case showTableCacheEvent: ShowTableCacheEvent =>
-        val carbonTable = showTableCacheEvent.carbonTable
-        val internalCall = showTableCacheEvent.internalCall
-        if (carbonTable.isMV && !internalCall) {
-          throw new UnsupportedOperationException("Operation not allowed on child table.")
-        }
-    }
-  }
-}
-
-
-object ShowCacheIndexEventListener extends OperationEventListener {
-
-  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
-
-  /**
-   * Called on a specified event occurrence
-   *
-   * @param event
-   * @param operationContext
-   */
-  override protected def onEvent(event: Event, operationContext: OperationContext): Unit = {
-    event match {
-      case showTableCacheEvent: ShowTableCacheEvent =>
-        val carbonTable = showTableCacheEvent.carbonTable
-        val childTables = operationContext.getProperty(carbonTable.getTableUniqueName)
-          .asInstanceOf[List[(String, String)]]
-
-        // Extract all indexes for the table
-        val indexes = IndexStoreManager.getInstance().getIndexSchemasOfTable(carbonTable)
-          .asScala.toList
-
-        val mv = filterMV(indexes, IndexClassProvider.MV.getShortName)
-        operationContext
-          .setProperty(carbonTable.getTableUniqueName, childTables ++ mv)
-    }
-  }
-
-  private def filterMV(indexes: List[IndexSchema],
-                       filter: String): List[(String, String, String)] = {
-    indexes.collect {
-      case index if index.getProviderName
-        .equalsIgnoreCase(filter) =>
-        if (filter.equalsIgnoreCase(IndexClassProvider.BLOOMFILTER.getShortName)) {
-          (s"${ index.getRelationIdentifier.getDatabaseName }-${
-            index.getIndexName}", index.getProviderName,
-            index.getRelationIdentifier.getTableId)
-        } else {
-          (s"${ index.getRelationIdentifier.getDatabaseName }-${
-            index.getRelationIdentifier.getTableName}", index.getProviderName,
-            index.getRelationIdentifier.getTableId)
-        }
-    }
-  }
-}
diff --git a/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexSuite.scala
index 69c993a..b5282cf 100644
--- a/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexSuite.scala
@@ -28,7 +28,7 @@ import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
 
 import org.apache.carbondata.common.exceptions.sql.{MalformedCarbonCommandException, MalformedIndexCommandException}
 import org.apache.carbondata.core.constants.CarbonCommonConstants
-import org.apache.carbondata.core.index.status.{IndexStatus, IndexStatusManager}
+import org.apache.carbondata.core.index.status.IndexStatus
 import org.apache.carbondata.core.metadata.index.IndexType
 import org.apache.carbondata.core.util.CarbonProperties
 
diff --git a/integration/spark/src/test/scala/org/apache/carbondata/index/lucene/LuceneFineGrainIndexSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/index/lucene/LuceneFineGrainIndexSuite.scala
index af44646..e64cd38 100644
--- a/integration/spark/src/test/scala/org/apache/carbondata/index/lucene/LuceneFineGrainIndexSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/index/lucene/LuceneFineGrainIndexSuite.scala
@@ -30,9 +30,8 @@ import org.scalatest.BeforeAndAfterAll
 import org.apache.carbondata.common.exceptions.sql.{MalformedCarbonCommandException, MalformedIndexCommandException}
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.core.index.status.{IndexStatus, IndexStatusManager}
+import org.apache.carbondata.core.index.status.IndexStatus
 import org.apache.carbondata.core.metadata.index.IndexType
-import org.apache.carbondata.index.bloom.IndexStatusUtil
 
 class LuceneFineGrainIndexSuite extends QueryTest with BeforeAndAfterAll {
 
@@ -679,8 +678,6 @@ class LuceneFineGrainIndexSuite extends QueryTest with BeforeAndAfterAll {
          | WITH DEFERRED REFRESH
       """.stripMargin)
     sql(s"LOAD DATA LOCAL INPATH '$file2' INTO TABLE index_test5 OPTIONS('header'='false')")
-    val map = IndexStatusManager.readIndexStatusMap()
-    assert(!map.get("dm").isEnabled)
     sql("REFRESH INDEX dm ON TABLE index_test5")
     checkAnswer(sql("SELECT * FROM index_test5 WHERE TEXT_MATCH('city:c020')"),
       sql(s"SELECT * FROM index_test5 WHERE city='c020'"))
diff --git a/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/RangeFilterAllDataTypesTestCases.scala b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/RangeFilterAllDataTypesTestCases.scala
index 1bd77d1..b830168 100644
--- a/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/RangeFilterAllDataTypesTestCases.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/detailquery/RangeFilterAllDataTypesTestCases.scala
@@ -182,6 +182,9 @@ class RangeFilterMyTests extends QueryTest with BeforeAndAfterAll {
           TimeStampGranularityConstants.TIME_GRAN_SEC.toString
         )
       CarbonProperties.getInstance().addProperty("carbon.direct.dictionary", "true")
+
+      CarbonProperties.getInstance().removeProperty("carbon.timestamp.format")
+
       sql("drop table if exists directDictionaryTable")
       sql("drop table if exists directDictionaryTable_hive")
       sql(
diff --git a/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/index/CGIndexTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/index/CGIndexTestCase.scala
index 40d8d1c..2fd7930 100644
--- a/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/index/CGIndexTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/index/CGIndexTestCase.scala
@@ -40,8 +40,8 @@ import org.apache.carbondata.core.datastore.page.ColumnPage
 import org.apache.carbondata.core.features.TableOperation
 import org.apache.carbondata.core.indexstore.blockletindex.BlockletIndexInputSplit
 import org.apache.carbondata.core.indexstore.{Blocklet, PartitionSpec}
-import org.apache.carbondata.core.metadata.schema.table.{CarbonTable, IndexSchema, DiskBasedIndexSchemaStorageProvider}
-import org.apache.carbondata.core.metadata.{AbsoluteTableIdentifier, CarbonMetadata}
+import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier
+import org.apache.carbondata.core.metadata.schema.table.{CarbonTable, IndexSchema}
 import org.apache.carbondata.core.scan.expression.Expression
 import org.apache.carbondata.core.scan.expression.conditional.EqualToExpression
 import org.apache.carbondata.core.scan.filter.executer.FilterExecuter
diff --git a/integration/spark/src/test/scala/org/apache/carbondata/view/MVTest.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/MVTest.scala
index 48c076e..98c0130 100644
--- a/integration/spark/src/test/scala/org/apache/carbondata/view/MVTest.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/MVTest.scala
@@ -1,3 +1,19 @@
+/*
+ * 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.view
 
 import java.io.File
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/ExtractJoinConditionsSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/ExtractJoinConditionsSuite.scala
similarity index 96%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/plans/ExtractJoinConditionsSuite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/plans/ExtractJoinConditionsSuite.scala
index 34ee2ed..5e51e97 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/ExtractJoinConditionsSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/ExtractJoinConditionsSuite.scala
@@ -15,16 +15,15 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.plans
+package org.apache.carbondata.view.plans
 
+import org.apache.carbondata.mv.dsl.Plans._
+import org.apache.carbondata.view.testutil.ModularPlanTest
 import org.apache.spark.sql.catalyst.dsl.expressions._
 import org.apache.spark.sql.catalyst.dsl.plans._
 import org.apache.spark.sql.catalyst.plans.logical.LocalRelation
 import org.apache.spark.sql.catalyst.plans.{Inner, _}
 
-import org.apache.carbondata.mv.dsl.Plans._
-import org.apache.carbondata.mv.testutil.ModularPlanTest
-
 class ExtractJoinConditionsSuite extends ModularPlanTest {
   val testRelation0 = LocalRelation('a.int, 'b.int, 'c.int)
   val testRelation1 = LocalRelation('d.int)
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/IsSPJGHSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/IsSPJGHSuite.scala
similarity index 95%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/plans/IsSPJGHSuite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/plans/IsSPJGHSuite.scala
index 2e7bfed..c5f1047 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/IsSPJGHSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/IsSPJGHSuite.scala
@@ -15,16 +15,15 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.plans
+package org.apache.carbondata.view.plans
 
+import org.apache.carbondata.mv.dsl.Plans._
+import org.apache.carbondata.mv.plans.modular.ModularPlan
+import org.apache.carbondata.view.testutil.ModularPlanTest
 import org.apache.spark.sql.catalyst.dsl.expressions._
 import org.apache.spark.sql.catalyst.dsl.plans._
 import org.apache.spark.sql.catalyst.plans.logical.LocalRelation
 
-import org.apache.carbondata.mv.dsl.Plans._
-import org.apache.carbondata.mv.plans.modular.ModularPlan
-import org.apache.carbondata.mv.testutil.ModularPlanTest
-
 /**
  * Tests for the isSPJGH function of [[ModularPlan]].
  */
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/LogicalToModularPlanSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/LogicalToModularPlanSuite.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/plans/LogicalToModularPlanSuite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/plans/LogicalToModularPlanSuite.scala
index e5ea307..a358dd3 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/LogicalToModularPlanSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/LogicalToModularPlanSuite.scala
@@ -15,8 +15,12 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.plans
+package org.apache.carbondata.view.plans
 
+import org.apache.carbondata.mv.dsl.Plans._
+import org.apache.carbondata.mv.plans.modular.Flags._
+import org.apache.carbondata.mv.plans.modular.{JoinEdge, ModularRelation}
+import org.apache.carbondata.view.testutil.ModularPlanTest
 import org.apache.spark.sql.catalyst._
 import org.apache.spark.sql.catalyst.dsl.expressions._
 import org.apache.spark.sql.catalyst.dsl.plans._
@@ -24,11 +28,6 @@ import org.apache.spark.sql.catalyst.expressions.aggregate.Count
 import org.apache.spark.sql.catalyst.plans.logical._
 import org.apache.spark.sql.catalyst.plans.{LeftOuter, RightOuter, _}
 
-import org.apache.carbondata.mv.dsl.Plans._
-import org.apache.carbondata.mv.plans.modular.Flags._
-import org.apache.carbondata.mv.plans.modular.{JoinEdge, ModularRelation}
-import org.apache.carbondata.mv.testutil.ModularPlanTest
-
 class LogicalToModularPlanSuite extends ModularPlanTest {
 
   val testRelation0 = LocalRelation('a.int, 'b.int, 'c.int)
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/ModularToSQLSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/ModularToSQLSuite.scala
similarity index 95%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/plans/ModularToSQLSuite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/plans/ModularToSQLSuite.scala
index 8933677..c585aec 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/ModularToSQLSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/ModularToSQLSuite.scala
@@ -15,17 +15,15 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.plans
-
-import org.apache.spark.sql.hive.CarbonSessionCatalogUtil
-import org.scalatest.BeforeAndAfter
+package org.apache.carbondata.view.plans
 
 import org.apache.carbondata.mv.dsl.Plans._
-import org.apache.carbondata.mv.testutil.ModularPlanTest
+import org.apache.carbondata.view.testutil.ModularPlanTest
+import org.scalatest.BeforeAndAfter
 
 class ModularToSQLSuite extends ModularPlanTest with BeforeAndAfter {
 
-  import org.apache.carbondata.mv.testutil.TestSQLBatch._
+  import org.apache.carbondata.view.testutil.TestSQLBatch._
 
   val spark = sqlContext
   val testHive = sqlContext.sparkSession
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/SignatureSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/SignatureSuite.scala
similarity index 92%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/plans/SignatureSuite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/plans/SignatureSuite.scala
index 0153e5a..896e01e 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/plans/SignatureSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/plans/SignatureSuite.scala
@@ -15,18 +15,16 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.plans
-
-import org.apache.spark.sql.catalyst.util._
-import org.apache.spark.sql.hive.CarbonSessionCatalogUtil
-import org.scalatest.BeforeAndAfterAll
+package org.apache.carbondata.view.plans
 
 import org.apache.carbondata.mv.dsl.Plans._
 import org.apache.carbondata.mv.plans.modular.ModularPlanSignatureGenerator
-import org.apache.carbondata.mv.testutil.ModularPlanTest
+import org.apache.carbondata.view.testutil.ModularPlanTest
+import org.apache.spark.sql.catalyst.util._
+import org.scalatest.BeforeAndAfterAll
 
 class SignatureSuite extends ModularPlanTest with BeforeAndAfterAll {
-  import org.apache.carbondata.mv.testutil.TestSQLBatch._
+  import org.apache.carbondata.view.testutil.TestSQLBatch._
 
   val spark = sqlContext
   val testHive = sqlContext.sparkSession
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCoalesceTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCoalesceTestCase.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCoalesceTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCoalesceTestCase.scala
index c3d9c0f..a94687b 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCoalesceTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCoalesceTestCase.scala
@@ -14,7 +14,7 @@
 	 * See the License for the specific language governing permissions and
 	 * limitations under the License.
 	 */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.spark.sql.Row
 import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCountAndCaseTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCountAndCaseTestCase.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCountAndCaseTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCountAndCaseTestCase.scala
index 44e029f..e7acee9 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCountAndCaseTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCountAndCaseTestCase.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.spark.sql.test.util.QueryTest
 import org.scalatest.BeforeAndAfterAll
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCreateTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCreateTestCase.scala
similarity index 99%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCreateTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCreateTestCase.scala
index 3fcb6b3..d5b11fd 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCreateTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCreateTestCase.scala
@@ -14,21 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import java.io.File
 import java.nio.file.{Files, Paths}
 
-import org.apache.spark.sql.{CarbonEnv, Row}
-import org.apache.spark.sql.test.util.QueryTest
-import org.scalatest.BeforeAndAfterAll
-
 import org.apache.carbondata.common.exceptions.sql.MalformedMVCommandException
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.datastore.impl.FileFactory
 import org.apache.carbondata.core.util.CarbonProperties
 import org.apache.carbondata.core.util.path.CarbonTablePath
 import org.apache.carbondata.spark.exception.ProcessMetaDataException
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.sql.{CarbonEnv, Row}
+import org.scalatest.BeforeAndAfterAll
 
 class MVCreateTestCase extends QueryTest with BeforeAndAfterAll {
 
@@ -907,7 +906,7 @@ class MVCreateTestCase extends QueryTest with BeforeAndAfterAll {
 //    sql("show materialized views").show()
 //    val frame = sql(
 //      "select empname, sum(utilization) from fact_table1 group by empname")
-//    assert(TestUtil.verifyMVDataMap(frame.queryExecution.optimizedPlan, "MV_exp1"))
+//    assert(TestUtil.verifyMV(frame.queryExecution.optimizedPlan, "MV_exp1"))
 //    sql("drop materialized view if exists MV_exp1")
 //    sql("drop materialized view if exists MV_exp2")
 //  }
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVExceptionTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVExceptionTestCase.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVExceptionTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVExceptionTestCase.scala
index 24ebc27..fadadb2 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVExceptionTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVExceptionTestCase.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.carbondata.common.exceptions.sql.{MalformedCarbonCommandException, MalformedMVCommandException}
 import org.apache.spark.sql.AnalysisException
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVFilterAndJoinTest.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVFilterAndJoinTest.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVFilterAndJoinTest.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVFilterAndJoinTest.scala
index d5e87fa..899b5c0 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVFilterAndJoinTest.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVFilterAndJoinTest.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.spark.sql.Row
 import org.apache.spark.sql.test.util.QueryTest
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVIncrementalLoadingTestcase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVIncrementalLoadingTestcase.scala
similarity index 92%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVIncrementalLoadingTestcase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVIncrementalLoadingTestcase.scala
index 05c9a18..bc88baa 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVIncrementalLoadingTestcase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVIncrementalLoadingTestcase.scala
@@ -15,20 +15,21 @@
 * limitations under the License.
 */
 
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
-import org.apache.spark.sql.{CarbonEnv, Row}
-import org.apache.spark.sql.test.util.QueryTest
-import org.scalatest.BeforeAndAfterAll
+import java.util
+
+import com.google.gson.Gson
 import org.apache.carbondata.core.constants.CarbonCommonConstants
-import org.apache.carbondata.core.index.status.MVSegmentStatusUtil
 import org.apache.carbondata.core.metadata.CarbonMetadata
 import org.apache.carbondata.core.statusmanager.{SegmentStatus, SegmentStatusManager}
-import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.sql.{CarbonEnv, Row}
+import org.scalatest.BeforeAndAfterAll
 
 
 /**
- * Test Class to verify Incremental Load on the MV table
+ * Test Class to verify Incremental Load on MV
  */
 class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
 
@@ -60,12 +61,12 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     val df1 = sql(s"$query")
     assert(!TestUtil.verifyMVHit(df1.queryExecution.optimizedPlan, "mv1"))
     sql(s"refresh materialized view mv1")
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1"
     )
-    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    var segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(0).getExtraInfo)
+    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    var segmentMap = getSegmentMap(loadMetadataDetails(0).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0")
     assert(segmentList.containsAll( segmentMap.get("default.test_table")))
@@ -74,8 +75,8 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     loadDataToFactTable("test_table")
     loadDataToFactTable("test_table1")
     sql(s"refresh materialized view mv1")
-    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(1).getExtraInfo)
+    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    segmentMap = getSegmentMap(loadMetadataDetails(1).getExtraInfo)
     segmentList.clear()
     segmentList.add("1")
     assert(segmentList.containsAll( segmentMap.get("default.test_table")))
@@ -106,11 +107,12 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     loadDataToFactTable("test_table")
     loadDataToFactTable("test_table1")
     sql(s"refresh materialized view mv1")
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1")
-    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    val segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(0).getExtraInfo)
+    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    
+    val segmentMap = getSegmentMap(loadMetadataDetails(0).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("1")
     segmentList.add("2")
@@ -140,15 +142,15 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
       sql(" select a, sum(b) from main_table group by a"))
     sql("update main_table set(a) = ('aaa') where b = 'abc'").show(false)
     sql("update testtable set(a) = ('aaa') where b = 'abc'").show(false)
-    val mvTable = CarbonEnv.getCarbonTable(
+    val viewTable = CarbonEnv.getCarbonTable(
       Option(CarbonCommonConstants.DATABASE_DEFAULT_NAME),
       "mv1")(sqlContext.sparkSession)
-    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
+    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
     assert(loadMetadataDetails(0).getSegmentStatus == SegmentStatus.MARKED_FOR_DELETE)
     checkAnswer(sql("select * from main_table"), sql("select * from testtable"))
     sql(s"refresh materialized view mv1")
-    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    val segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(1).getExtraInfo)
+    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    val segmentMap = getSegmentMap(loadMetadataDetails(1).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0")
     segmentList.add("1")
@@ -175,12 +177,12 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     loadDataToFactTable("test_table")
     sql(s"refresh materialized view mv1")
     sql("alter table mv1 compact 'major'")
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1"
     )
-    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    val segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(3).getExtraInfo)
+    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    val segmentMap = getSegmentMap(loadMetadataDetails(3).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0")
     segmentList.add("1")
@@ -214,11 +216,11 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     sql(s"refresh materialized view mv1")
     sql("clean files for table mv1")
     sql("clean files for table test_table")
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1")
-    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    val segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(2).getExtraInfo)
+    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    val segmentMap = getSegmentMap(loadMetadataDetails(2).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0.1")
     segmentList.add("4")
@@ -239,15 +241,15 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     sql(s"refresh materialized view mv1")
     checkAnswer(sql(" select a, sum(b) from test_table  group by a"), Seq(Row("a", null), Row("b", null)))
     sql("insert overwrite table test_table select 'd','abc',3")
-    val mvTable = CarbonEnv.getCarbonTable(
+    val viewTable = CarbonEnv.getCarbonTable(
       Option(CarbonCommonConstants.DATABASE_DEFAULT_NAME),
       "mv1")(sqlContext.sparkSession)
-    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
+    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
     assert(loadMetadataDetails(0).getSegmentStatus == SegmentStatus.MARKED_FOR_DELETE)
     checkAnswer(sql(" select a, sum(b) from test_table  group by a"), Seq(Row("d", null)))
     sql(s"refresh materialized view mv1")
-    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    val segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(1).getExtraInfo)
+    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    val segmentMap = getSegmentMap(loadMetadataDetails(1).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("2")
     assert(segmentList.containsAll( segmentMap.get("default.test_table")))
@@ -338,13 +340,13 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     sql("insert into main_table values('b','bcd',2)")
     sql("refresh materialized view mv1")
     sql("alter table mv1 compact 'custom' where segment.id in (0,1)")
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1")
-    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
+    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
     assert(loadMetadataDetails(0).getSegmentStatus == SegmentStatus.COMPACTED)
     assert(loadMetadataDetails(1).getSegmentStatus == SegmentStatus.COMPACTED)
-    var segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(2).getExtraInfo)
+    var segmentMap = getSegmentMap(loadMetadataDetails(2).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0")
     segmentList.add("1")
@@ -385,12 +387,12 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
       "create materialized view mv1  as select empname, designation " +
       "from test_table")
     val query: String = "select empname from test_table"
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1"
     )
-    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    var segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(0).getExtraInfo)
+    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    var segmentMap = getSegmentMap(loadMetadataDetails(0).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0")
     assert(segmentList.containsAll( segmentMap.get("default.test_table")))
@@ -398,8 +400,8 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     assert(TestUtil.verifyMVHit(df2.queryExecution.optimizedPlan, "mv1"))
     loadDataToFactTable("test_table")
     loadDataToFactTable("test_table1")
-    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
-    segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(1).getExtraInfo)
+    loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
+    segmentMap = getSegmentMap(loadMetadataDetails(1).getExtraInfo)
     segmentList.clear()
     segmentList.add("1")
     assert(segmentList.containsAll( segmentMap.get("default.test_table")))
@@ -432,12 +434,12 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
       sql(" select a, sum(b) from main_table group by a"))
     sql("update main_table set(a) = ('aaa') where b = 'abc'").show(false)
     sql("update testtable set(a) = ('aaa') where b = 'abc'").show(false)
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1")
-    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
+    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
     assert(loadMetadataDetails(0).getSegmentStatus == SegmentStatus.MARKED_FOR_DELETE)
-    var segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(1).getExtraInfo)
+    var segmentMap = getSegmentMap(loadMetadataDetails(1).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0")
     segmentList.add("1")
@@ -467,12 +469,12 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
       sql(" select a, sum(b) from main_table group by a"))
     sql("delete from  main_table  where b = 'abc'").show(false)
     sql("delete from  testtable  where b = 'abc'").show(false)
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1")
-    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
+    var loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
     assert(loadMetadataDetails(0).getSegmentStatus == SegmentStatus.MARKED_FOR_DELETE)
-    var segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(1).getExtraInfo)
+    var segmentMap = getSegmentMap(loadMetadataDetails(1).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0")
     segmentList.add("1")
@@ -507,10 +509,10 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     sql("drop materialized view if exists mv1")
     sql("create materialized view mv1  as select a, sum(b) from main_table group by a")
     sql("delete from  main_table  where b = 'abc'").show(false)
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1")
-    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
+    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
     assert(loadMetadataDetails.length == 1)
     assert(loadMetadataDetails(0).getSegmentStatus == SegmentStatus.MARKED_FOR_DELETE)
   }
@@ -539,12 +541,12 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
     sql(s"refresh materialized view mv1")
     sql("alter table test_table compact 'major'")
     sql(s"refresh materialized view mv1")
-    val mvTable = CarbonMetadata.getInstance().getCarbonTable(
+    val viewTable = CarbonMetadata.getInstance().getCarbonTable(
       CarbonCommonConstants.DATABASE_DEFAULT_NAME,
       "mv1")
-    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(mvTable.getMetadataPath)
+    val loadMetadataDetails = SegmentStatusManager.readLoadMetadata(viewTable.getMetadataPath)
     assert(loadMetadataDetails.length == 1)
-    var segmentMap = MVSegmentStatusUtil.getSegmentMap(loadMetadataDetails(0).getExtraInfo)
+    var segmentMap = getSegmentMap(loadMetadataDetails(0).getExtraInfo)
     val segmentList = new java.util.ArrayList[String]()
     segmentList.add("0.1")
     assert(segmentList.containsAll(segmentMap.get("default.test_table")))
@@ -653,4 +655,8 @@ class MVIncrementalLoadingTestcase extends QueryTest with BeforeAndAfterAll {
       s"""LOAD DATA local inpath '$resourcesPath/data_big.csv' INTO TABLE $tableName  OPTIONS
          |('DELIMITER'= ',', 'QUOTECHAR'= '"')""".stripMargin)
   }
+  
+  private def getSegmentMap(extraInfo: String): util.Map[String, util.List[String]] = {
+    new Gson().fromJson(extraInfo, classOf[util.Map[_, _]])
+  }
 }
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVInvalidTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVInvalidTestCase.scala
similarity index 97%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVInvalidTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVInvalidTestCase.scala
index 3d3933e..e5aee5f 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVInvalidTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVInvalidTestCase.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.spark.sql.test.util.QueryTest
 import org.scalatest.BeforeAndAfterAll
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVMultiJoinTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVMultiJoinTestCase.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVMultiJoinTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVMultiJoinTestCase.scala
index afd125a..0e8068b 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVMultiJoinTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVMultiJoinTestCase.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.spark.sql.Row
 import org.apache.spark.sql.test.util.QueryTest
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVRewriteTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVRewriteTestCase.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVRewriteTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVRewriteTestCase.scala
index f37ba75..396fde5 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVRewriteTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVRewriteTestCase.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.spark.sql.test.util.QueryTest
 import org.scalatest.BeforeAndAfterAll
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVSampleTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVSampleTestCase.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVSampleTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVSampleTestCase.scala
index dcd9ede..43c435e 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVSampleTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVSampleTestCase.scala
@@ -14,16 +14,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import java.io.File
 
-import org.apache.spark.sql.test.util.QueryTest
-import org.scalatest.BeforeAndAfterAll
-
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.mv.rewrite.matching.TestSQLBatch._
+import org.apache.carbondata.view.rewrite.matching.TestSQLBatch._
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
 
 class MVSampleTestCase extends QueryTest with BeforeAndAfterAll {
 
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVTPCDSTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVTPCDSTestCase.scala
similarity index 96%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVTPCDSTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVTPCDSTestCase.scala
index 2cafc77..154ccf6 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVTPCDSTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVTPCDSTestCase.scala
@@ -14,17 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import java.io.File
 
-import org.apache.spark.sql.test.util.QueryTest
-import org.scalatest.BeforeAndAfterAll
-
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.mv.rewrite.matching.TestTPCDS_1_4_Batch._
-import org.apache.carbondata.mv.testutil.Tpcds_1_4_Tables.tpcds1_4Tables
+import org.apache.carbondata.view.rewrite.matching.TestTPCDS_1_4_Batch._
+import org.apache.carbondata.view.testutil.Tpcds_1_4_Tables.tpcds1_4Tables
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
 
 class MVTPCDSTestCase extends QueryTest with BeforeAndAfterAll {
 
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVTpchTestCase.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVTpchTestCase.scala
similarity index 99%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVTpchTestCase.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVTpchTestCase.scala
index 10ad411..4ddb02e 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVTpchTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVTpchTestCase.scala
@@ -14,11 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import java.io.File
 
-import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression
 import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, LogicalPlan}
 import org.apache.spark.sql.test.util.QueryTest
 import org.scalatest.BeforeAndAfterAll
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/SelectAllColumnsSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/SelectAllColumnsSuite.scala
similarity index 97%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/SelectAllColumnsSuite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/SelectAllColumnsSuite.scala
index 11cb8ee..70b6332 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/SelectAllColumnsSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/SelectAllColumnsSuite.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
 import org.apache.spark.sql.Row
 import org.apache.spark.sql.test.util.QueryTest
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestAllOperationsOnMV.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestAllOperationsOnMV.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestAllOperationsOnMV.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestAllOperationsOnMV.scala
index d9b4042..680c21e 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestAllOperationsOnMV.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestAllOperationsOnMV.scala
@@ -15,22 +15,23 @@
 * limitations under the License.
 */
 
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
-import scala.collection.JavaConverters._
 import java.util
 
-import org.apache.spark.sql.{CarbonEnv, Row}
-import org.apache.spark.sql.catalyst.TableIdentifier
-import org.apache.spark.sql.test.util.QueryTest
-import org.scalatest.BeforeAndAfterEach
-
 import org.apache.carbondata.common.exceptions.sql.{MalformedCarbonCommandException, MalformedMVCommandException}
 import org.apache.carbondata.core.cache.CacheProvider
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.datastore.impl.FileFactory
 import org.apache.carbondata.core.metadata.CarbonMetadata
+import org.apache.carbondata.core.util.CarbonProperties
 import org.apache.carbondata.spark.exception.ProcessMetaDataException
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.sql.{CarbonEnv, Row}
+import org.scalatest.BeforeAndAfterEach
+
+import scala.collection.JavaConverters._
 
 /**
  * Test Class for MV materialized view to verify all scenerios
@@ -328,7 +329,7 @@ class TestAllOperationsOnMV extends QueryTest with BeforeAndAfterEach {
     sql("create materialized view dm1 with deferred refresh as select price from maintable")
     intercept[ProcessMetaDataException] {
       sql("drop table dm1")
-    }.getMessage.contains("Child table which is related with materialized view cannot be dropped, use DROP materialized view command to drop")
+    }.getMessage.contains("Child table which is associated with materialized view cannot be dropped, use DROP materialized view command to drop")
     sql("drop table IF EXISTS maintable")
   }
 
@@ -409,14 +410,14 @@ class TestAllOperationsOnMV extends QueryTest with BeforeAndAfterEach {
     sql("drop table IF EXISTS maintable")
   }
 
-  test("validate dmproperties") {
+  test("validate properties") {
     sql("drop table IF EXISTS maintable")
     sql("create table maintable(name string, c_code int, price int) STORED AS carbondata")
     sql("insert into table maintable select 'abc',21,2000")
     sql("drop materialized view if exists dm ")
     intercept[MalformedCarbonCommandException] {
       sql("create materialized view dm properties('dictionary_include'='name', 'sort_columns'='name') as select name from maintable")
-    }.getMessage.contains("DMProperties dictionary_include,sort_columns are not allowed for this materialized view")
+    }.getMessage.contains("Properties dictionary_include,sort_columns are not allowed for this materialized view")
   }
 
   test("test todate UDF function with mv") {
@@ -469,6 +470,7 @@ class TestAllOperationsOnMV extends QueryTest with BeforeAndAfterEach {
   }
 
   test("test sort_scope if sort_columns are provided") {
+    CarbonProperties.getInstance().removeProperty("carbon.load.sort.scope")
     sql("drop table IF EXISTS maintable")
     sql("create table maintable(name string, c_code int, price int) STORED AS carbondata tblproperties('sort_columns'='name')")
     sql("insert into table maintable select 'abc',21,2000")
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestPartitionWithMV.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestPartitionWithMV.scala
similarity index 99%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestPartitionWithMV.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestPartitionWithMV.scala
index ddb07ba..ab23d10 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestPartitionWithMV.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestPartitionWithMV.scala
@@ -15,16 +15,16 @@
 * limitations under the License.
 */
 
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
-import scala.collection.JavaConverters._
-
-import org.apache.spark.sql.test.util.QueryTest
-import org.apache.spark.sql.{CarbonEnv, Row}
 import org.apache.carbondata.core.datastore.impl.FileFactory
 import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.sql.{CarbonEnv, Row}
 import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
 
+import scala.collection.JavaConverters._
+
 /**
  * Test class for MV to verify partition scenarios
  */
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestSQLSuite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestSQLSuite.scala
similarity index 83%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestSQLSuite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestSQLSuite.scala
index 90cf7af..21a5000 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestSQLSuite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/TestSQLSuite.scala
@@ -15,15 +15,16 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
+import org.apache.carbondata.view.MVCatalogInSpark
+import org.apache.carbondata.view.testutil.ModularPlanTest
 import org.apache.spark.sql.catalyst.util._
-import org.apache.spark.sql.hive.CarbonSessionCatalogUtil
+import org.apache.spark.sql.optimizer.MVRewrite
 import org.scalatest.BeforeAndAfter
-import org.apache.carbondata.mv.testutil.ModularPlanTest
 
 class TestSQLSuite extends ModularPlanTest with BeforeAndAfter { 
-  import org.apache.carbondata.mv.rewrite.matching.TestSQLBatch._
+  import org.apache.carbondata.view.rewrite.matching.TestSQLBatch._
 
   val spark = sqlContext
   val testHive = sqlContext.sparkSession
@@ -75,12 +76,12 @@ class TestSQLSuite extends ModularPlanTest with BeforeAndAfter {
         
     sampleTestCases.foreach { testcase =>
       if (testcase._1 == dest) {
-        val mvSession = new SummaryDatasetCatalog(testHive)
+        val mvSession = new MVCatalogInSpark(testHive)
         val summary = testHive.sql(testcase._2)
-        mvSession.registerSummaryDataset(summary)
+        mvSession.registerSchema(summary)
         val rewrittenSQL =
-          mvSession.mvSession.rewrite(mvSession.mvSession.sparkSession.sql(
-            testcase._3).queryExecution.optimizedPlan).toCompactSQL.trim
+          new MVRewrite(mvSession, mvSession.session.sql(
+            testcase._3).queryExecution.optimizedPlan, mvSession.session).toCompactSQL.trim
 
         if (!rewrittenSQL.trim.equals(testcase._4)) {
           fail(
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/Tpcds_1_4_Suite.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/Tpcds_1_4_Suite.scala
similarity index 82%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/Tpcds_1_4_Suite.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/Tpcds_1_4_Suite.scala
index 9ae601b..581b555 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/Tpcds_1_4_Suite.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/Tpcds_1_4_Suite.scala
@@ -15,19 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.rewrite
+package org.apache.carbondata.view.rewrite
 
+import org.apache.carbondata.view.MVCatalogInSpark
+import org.apache.carbondata.view.testutil.ModularPlanTest
 import org.apache.spark.sql.catalyst.util._
-import org.apache.spark.sql.hive.CarbonSessionCatalogUtil
+import org.apache.spark.sql.optimizer.MVRewrite
 import org.scalatest.BeforeAndAfter
-import org.apache.carbondata.mv.testutil.ModularPlanTest
-import org.apache.spark.sql.util.SparkSQLUtil
 //import org.apache.spark.sql.catalyst.SQLBuilder
 import java.io.{File, PrintWriter}
 
 class Tpcds_1_4_Suite extends ModularPlanTest with BeforeAndAfter {
-  import org.apache.carbondata.mv.rewrite.matching.TestTPCDS_1_4_Batch._
-  import org.apache.carbondata.mv.testutil.Tpcds_1_4_Tables._
+  import org.apache.carbondata.view.rewrite.matching.TestTPCDS_1_4_Batch._
+  import org.apache.carbondata.view.testutil.Tpcds_1_4_Tables._
 
   val spark = sqlContext
   val testHive = sqlContext.sparkSession
@@ -48,13 +48,13 @@ class Tpcds_1_4_Suite extends ModularPlanTest with BeforeAndAfter {
     
     tpcds_1_4_testCases.foreach { testcase =>
       if (testcase._1 == dest) { /** to run single case, uncomment out this **/
-        val mvSession = new SummaryDatasetCatalog(testHive)
+        val mvSession = new MVCatalogInSpark(testHive)
         val summaryDF = testHive.sql(testcase._2)
-        mvSession.registerSummaryDataset(summaryDF)
+        mvSession.registerSchema(summaryDF)
 
         writer.print(s"\n\n==== ${testcase._1} ====\n\n==== mv ====\n\n${testcase._2}\n\n==== original query ====\n\n${testcase._3}\n")
         
-        val rewriteSQL = mvSession.mvSession.rewriteToSQL(mvSession.mvSession.sparkSession.sql(testcase._3).queryExecution.optimizedPlan)
+        val rewriteSQL = new MVRewrite(mvSession, mvSession.session.sql(testcase._3).queryExecution.optimizedPlan, mvSession.session).toCompactSQL.trim
         LOGGER.info(s"\n\n\n\n===== Rewritten query for ${testcase._1} =====\n\n${rewriteSQL}\n")
         
         if (!rewriteSQL.trim.equals(testcase._4)) {
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/matching/TestSQLBatch.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/matching/TestSQLBatch.scala
similarity index 85%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/matching/TestSQLBatch.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/matching/TestSQLBatch.scala
index 07cd232..b879d5e 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/matching/TestSQLBatch.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/matching/TestSQLBatch.scala
@@ -14,8 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package org.apache.carbondata.mv.rewrite.matching
+package org.apache.carbondata.view.rewrite.matching
 
 object TestSQLBatch {
 
@@ -33,7 +32,7 @@ object TestSQLBatch {
         |WHERE i_item_sk = 1 and i_item_id > 0
      """.stripMargin.trim,
      s"""
-        |SELECT item.`i_item_id`, item.`i_item_sk` 
+        |SELECT item.`i_item_id`, item.`i_item_sk`
         |FROM
         |  item
         |WHERE
@@ -51,7 +50,7 @@ object TestSQLBatch {
         |WHERE i_item_sk = 1 or i_item_id > 0
      """.stripMargin.trim,
      s"""
-        |SELECT item.`i_item_id`, item.`i_item_sk` 
+        |SELECT item.`i_item_id`, item.`i_item_sk`
         |FROM
         |  item
         |WHERE
@@ -67,9 +66,9 @@ object TestSQLBatch {
         |FROM Fact
      """.stripMargin.trim,
      s"""
-        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`flid`, year(CAST(gen_subsumer_0.`date` AS DATE)) AS `year` 
+        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`flid`, year(CAST(gen_subsumer_0.`date` AS DATE)) AS `year`
         |FROM
-        |  (SELECT fact.`faid`, fact.`flid`, fact.`date` 
+        |  (SELECT fact.`faid`, fact.`flid`, fact.`date`
         |  FROM
         |    fact) gen_subsumer_0
      """.stripMargin.trim),
@@ -84,11 +83,11 @@ object TestSQLBatch {
         |WHERE year(date) = 2000
      """.stripMargin.trim,
      s"""
-        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`flid` 
+        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`flid`
         |FROM
-        |  (SELECT fact.`faid`, fact.`flid`, fact.`date` 
+        |  (SELECT fact.`faid`, fact.`flid`, fact.`date`
         |  FROM
-        |    fact) gen_subsumer_0 
+        |    fact) gen_subsumer_0
         |WHERE
         |  (year(CAST(gen_subsumer_0.`date` AS DATE)) = 2000)
      """.stripMargin.trim),
@@ -104,13 +103,13 @@ object TestSQLBatch {
         |WHERE year(date) = 2000
      """.stripMargin.trim,
      s"""
-        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`flid` 
+        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`flid`
         |FROM
-        |  (SELECT fact.`faid`, fact.`flid`, fact.`date` 
+        |  (SELECT fact.`faid`, fact.`flid`, fact.`date`
         |  FROM
         |    fact
         |  WHERE
-        |    (year(CAST(fact.`date` AS DATE)) = 2000)) gen_subsumer_0 
+        |    (year(CAST(fact.`date` AS DATE)) = 2000)) gen_subsumer_0
         |WHERE
         |  (year(CAST(gen_subsumer_0.`date` AS DATE)) = 2000)
      """.stripMargin.trim),
@@ -126,7 +125,7 @@ object TestSQLBatch {
         |WHERE year(date) = 2000
      """.stripMargin.trim,
      s"""
-        |SELECT fact.`faid`, fact.`flid` 
+        |SELECT fact.`faid`, fact.`flid`
         |FROM
         |  fact
         |WHERE
@@ -145,12 +144,12 @@ object TestSQLBatch {
         |HAVING count(*) > 2
      """.stripMargin.trim,
      s"""
-        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`year` AS `year`, sum(gen_subsumer_0.`cnt`) AS `cnt` 
+        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`year` AS `year`, sum(gen_subsumer_0.`cnt`) AS `cnt`
         |FROM
-        |  (SELECT fact.`faid`, fact.`flid`, year(CAST(fact.`date` AS DATE)) AS `year`, count(1) AS `cnt` 
+        |  (SELECT fact.`faid`, fact.`flid`, year(CAST(fact.`date` AS DATE)) AS `year`, count(1) AS `cnt`
         |  FROM
         |    fact
-        |  GROUP BY fact.`faid`, fact.`flid`, year(CAST(fact.`date` AS DATE))) gen_subsumer_0 
+        |  GROUP BY fact.`faid`, fact.`flid`, year(CAST(fact.`date` AS DATE))) gen_subsumer_0
         |GROUP BY gen_subsumer_0.`faid`, gen_subsumer_0.`year`
         |HAVING (sum(gen_subsumer_0.`cnt`) > 2L)
      """.stripMargin.trim),
@@ -164,9 +163,9 @@ object TestSQLBatch {
         |FROM Fact
      """.stripMargin.trim,
      s"""
-        |SELECT year(CAST(gen_subsumer_0.`date` AS DATE)) AS `year(CAST(date AS DATE))` 
+        |SELECT year(CAST(gen_subsumer_0.`date` AS DATE)) AS `year(CAST(date AS DATE))`
         |FROM
-        |  (SELECT fact.`date` 
+        |  (SELECT fact.`date`
         |  FROM
         |    fact) gen_subsumer_0
      """.stripMargin.trim),
@@ -182,13 +181,13 @@ object TestSQLBatch {
         |WHERE faid > 0 AND flid > 0
      """.stripMargin.trim,
      s"""
-        |SELECT gen_subsumer_0.`faid` 
+        |SELECT gen_subsumer_0.`faid`
         |FROM
-        |  (SELECT fact.`faid`, fact.`flid` 
+        |  (SELECT fact.`faid`, fact.`flid`
         |  FROM
         |    fact
         |  WHERE
-        |    (fact.`faid` > 0)) gen_subsumer_0 
+        |    (fact.`faid` > 0)) gen_subsumer_0
         |WHERE
         |  (gen_subsumer_0.`faid` > 0) AND (gen_subsumer_0.`flid` > 0)
      """.stripMargin.trim),
@@ -204,7 +203,7 @@ object TestSQLBatch {
         |WHERE faid > 0 OR flid > 0
      """.stripMargin.trim,
      s"""
-        |SELECT fact.`faid` 
+        |SELECT fact.`faid`
         |FROM
         |  fact
         |WHERE
@@ -223,13 +222,13 @@ object TestSQLBatch {
         |GROUP BY faid
      """.stripMargin.trim,
      s"""
-        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`count(flid)` AS `count(flid)` 
+        |SELECT gen_subsumer_0.`faid`, gen_subsumer_0.`count(flid)` AS `count(flid)`
         |FROM
-        |  (SELECT fact.`faid`, count(fact.`flid`) AS `count(flid)` 
+        |  (SELECT fact.`faid`, count(fact.`flid`) AS `count(flid)`
         |  FROM
         |    fact
-        |  GROUP BY fact.`faid`) gen_subsumer_0 
+        |  GROUP BY fact.`faid`) gen_subsumer_0
         |WHERE
         |  (gen_subsumer_0.`faid` = 3)
      """.stripMargin.trim))
-}
\ No newline at end of file
+}
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/matching/TestTPCDS_1_4_Batch.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/matching/TestTPCDS_1_4_Batch.scala
similarity index 95%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/matching/TestTPCDS_1_4_Batch.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/matching/TestTPCDS_1_4_Batch.scala
index 23b1554..9e0a9d3 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/matching/TestTPCDS_1_4_Batch.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/matching/TestTPCDS_1_4_Batch.scala
@@ -1,4 +1,20 @@
-package org.apache.carbondata.mv.rewrite.matching
+/*
+ * 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.view.rewrite.matching
 
 object TestTPCDS_1_4_Batch {
   val tpcds_1_4_testCases = Seq(
@@ -15,7 +31,7 @@ object TestTPCDS_1_4_Batch {
         |FROM item
         |WHERE i_item_sk IN (2, 3, 5, 7, 11, 13, 17, 19)
         """.stripMargin.trim,
-       """ 
+       """
        """.stripMargin.trim),
       // test case 2: test SELECT-SELECT-EXACT_MATCH with SELECT containing join (derive from q64)
       // cross_sales not in Tpcds_1_4_Tables.scala
@@ -65,14 +81,14 @@ object TestTPCDS_1_4_Batch {
        """
         |SELECT count(ss_sold_date_sk) as not_null_total,
         |       max(ss_sold_date_sk) as max_ss_sold_date_sk,
-        |       ss_item_sk, ss_store_sk  
+        |       ss_item_sk, ss_store_sk
         |FROM store_sales
         |GROUP BY ss_item_sk, ss_store_sk
         """.stripMargin.trim,
        """
-        |SELECT gen_subsumer_0.`not_null_total` AS `not_null_total`, gen_subsumer_0.`max_ss_sold_date_sk` AS `max_ss_sold_date_sk`, gen_subsumer_0.`ss_item_sk`, gen_subsumer_0.`ss_store_sk` 
+        |SELECT gen_subsumer_0.`not_null_total` AS `not_null_total`, gen_subsumer_0.`max_ss_sold_date_sk` AS `max_ss_sold_date_sk`, gen_subsumer_0.`ss_item_sk`, gen_subsumer_0.`ss_store_sk`
         |FROM
-        |  (SELECT count(store_sales.`ss_sold_date_sk`) AS `not_null_total`, max(store_sales.`ss_sold_date_sk`) AS `max_ss_sold_date_sk`, max(store_sales.`ss_sold_time_sk`) AS `max_ss_sold_time_sk`, store_sales.`ss_item_sk`, store_sales.`ss_store_sk` 
+        |  (SELECT count(store_sales.`ss_sold_date_sk`) AS `not_null_total`, max(store_sales.`ss_sold_date_sk`) AS `max_ss_sold_date_sk`, max(store_sales.`ss_sold_time_sk`) AS `max_ss_sold_time_sk`, store_sales.`ss_item_sk`, store_sales.`ss_store_sk`
         |  FROM
         |    store_sales
         |  GROUP BY store_sales.`ss_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0
@@ -92,7 +108,7 @@ object TestTPCDS_1_4_Batch {
         |GROUP BY ss_store_sk, ss_item_sk
         """.stripMargin.trim,
        """
-        |SELECT store_sales.`ss_store_sk`, store_sales.`ss_item_sk`, sum(store_sales.`ss_sales_price`) AS `revenue` 
+        |SELECT store_sales.`ss_store_sk`, store_sales.`ss_item_sk`, sum(store_sales.`ss_sales_price`) AS `revenue`
         |FROM
         |  store_sales
         |  INNER JOIN date_dim ON (date_dim.`d_month_seq` >= 1176) AND (date_dim.`d_month_seq` <= 1187) AND (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
@@ -127,14 +143,14 @@ object TestTPCDS_1_4_Batch {
         | LIMIT 100
         """.stripMargin.trim,
        """
-        |SELECT gen_subsumer_0.`d_year`, gen_subsumer_0.`i_brand_id` AS `brand_id`, gen_subsumer_0.`i_brand` AS `brand`, sum(gen_subsumer_0.`sum_agg`) AS `sum_agg` 
+        |SELECT gen_subsumer_0.`d_year`, gen_subsumer_0.`i_brand_id` AS `brand_id`, gen_subsumer_0.`i_brand` AS `brand`, sum(gen_subsumer_0.`sum_agg`) AS `sum_agg`
         |FROM
-        |  (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2))))  [...]
+        |  (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2))))  [...]
         |  FROM
-        |    date_dim dt 
+        |    date_dim dt
         |    INNER JOIN store_sales ON (dt.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |    INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
-        |  GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0 
+        |  GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0
         |WHERE
         |  (gen_subsumer_0.`d_moy` = 11) AND (gen_subsumer_0.`i_manufact_id` = 128)
         |GROUP BY gen_subsumer_0.`d_year`, gen_subsumer_0.`i_brand`, gen_subsumer_0.`i_brand_id`
@@ -200,49 +216,49 @@ object TestTPCDS_1_4_Batch {
         | limit 100
         """.stripMargin.trim,
        """
-        |SELECT sum(gen_subquery_4.`sales`) AS `sum(sales)` 
+        |SELECT sum(gen_subquery_4.`sales`) AS `sum(sales)`
         |FROM
-        |  (SELECT (CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(catalog_sales.`cs_list_price` AS DECIMAL(12,2))) AS `sales` 
+        |  (SELECT (CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(catalog_sales.`cs_list_price` AS DECIMAL(12,2))) AS `sales`
         |  FROM
         |    catalog_sales
-        |    LEFT SEMI JOIN (SELECT gen_subsumer_0.`i_item_sk` AS `item_sk`, sum(gen_subsumer_0.`number_sales`) AS `count(1)` 
+        |    LEFT SEMI JOIN (SELECT gen_subsumer_0.`i_item_sk` AS `item_sk`, sum(gen_subsumer_0.`number_sales`) AS `count(1)`
         |    FROM
-        |      (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2) [...]
+        |      (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2) [...]
         |      FROM
-        |        date_dim dt 
+        |        date_dim dt
         |        INNER JOIN store_sales ON (dt.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |        INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
-        |      GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0 
+        |      GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0
         |    WHERE
         |      (gen_subsumer_0.`d_year` IN (2000, 2001, 2002, 2003))
         |    GROUP BY gen_subsumer_0.`itemdesc`, gen_subsumer_0.`i_item_sk`, gen_subsumer_0.`d_date`) gen_subquery_0  ON (gen_subquery_0.`count(1)` > 4L) AND (catalog_sales.`cs_item_sk` = gen_subquery_0.`item_sk`)
-        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#271 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#274 as decimal(12,2)))), DecimalType(18,2)))` 
+        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#271 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#274 as decimal(12,2)))), DecimalType(18,2)))`
         |    FROM
         |      store_sales
         |      INNER JOIN customer ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |    GROUP BY customer.`c_customer_sk`) gen_subquery_1  ON (CAST(gen_subquery_1.`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#271 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#274 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_0_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales [...]
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (catalog_sales.`cs_sold_date_sk` = date_dim.`d_date_sk`)
         |  UNION ALL
-        |  SELECT (CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2))) AS `sales` 
+        |  SELECT (CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2))) AS `sales`
         |  FROM
         |    web_sales
-        |    LEFT SEMI JOIN (SELECT gen_subsumer_1.`i_item_sk` AS `item_sk`, sum(gen_subsumer_1.`number_sales`) AS `count(1)` 
+        |    LEFT SEMI JOIN (SELECT gen_subsumer_1.`i_item_sk` AS `item_sk`, sum(gen_subsumer_1.`number_sales`) AS `count(1)`
         |    FROM
-        |      (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2) [...]
+        |      (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2) [...]
         |      FROM
-        |        date_dim dt 
+        |        date_dim dt
         |        INNER JOIN store_sales ON (dt.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |        INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
-        |      GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_1 
+        |      GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_manufact_id`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_1
         |    WHERE
         |      (gen_subsumer_1.`d_year` IN (2000, 2001, 2002, 2003))
         |    GROUP BY gen_subsumer_1.`itemdesc`, gen_subsumer_1.`i_item_sk`, gen_subsumer_1.`d_date`) gen_subquery_2  ON (gen_subquery_2.`count(1)` > 4L) AND (web_sales.`ws_item_sk` = gen_subquery_2.`item_sk`)
-        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#271 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#274 as decimal(12,2)))), DecimalType(18,2)))` 
+        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#271 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#274 as decimal(12,2)))), DecimalType(18,2)))`
         |    FROM
         |      store_sales
         |      INNER JOIN customer ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |    GROUP BY customer.`c_customer_sk`) gen_subquery_3  ON (CAST(gen_subquery_3.`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#271 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#274 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_1_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales [...]
-        |    INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)) gen_subquery_4 
+        |    INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)) gen_subquery_4
         |LIMIT 100
         """.stripMargin.trim),
       // q14a
@@ -373,14 +389,14 @@ object TestTPCDS_1_4_Batch {
         | limit 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subsumer_0.`i_brand_id` AS `brand_id`, gen_subsumer_0.`i_brand` AS `brand`, sum(gen_subsumer_0.`sum_agg`) AS `ext_price` 
+        |SELECT gen_subsumer_0.`i_brand_id` AS `brand_id`, gen_subsumer_0.`i_brand` AS `brand`, sum(gen_subsumer_0.`sum_agg`) AS `ext_price`
         |FROM
-        |  (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_manager_id`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2)))) A [...]
+        |  (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_manager_id`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2)))) A [...]
         |  FROM
-        |    date_dim dt 
+        |    date_dim dt
         |    INNER JOIN store_sales ON (dt.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |    INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
-        |  GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0 
+        |  GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0
         |WHERE
         |  (gen_subsumer_0.`d_moy` = 11) AND (gen_subsumer_0.`d_year` = 1999) AND (gen_subsumer_0.`i_manager_id` = 28)
         |GROUP BY gen_subsumer_0.`i_brand`, gen_subsumer_0.`i_brand_id`
@@ -422,25 +438,25 @@ object TestTPCDS_1_4_Batch {
         |   i_category, i_class, i_item_id, i_item_desc, revenueratio
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_1.`i_item_desc`, gen_subquery_1.`i_category`, gen_subquery_1.`i_class`, gen_subquery_1.`i_current_price`, gen_subquery_1.`itemrevenue`, ((gen_subquery_1.`_w0` * 100.00BD) / CAST(gen_subquery_1.`_we0` AS DECIMAL(28,2))) AS `revenueratio` 
+        |SELECT gen_subquery_1.`i_item_desc`, gen_subquery_1.`i_category`, gen_subquery_1.`i_class`, gen_subquery_1.`i_current_price`, gen_subquery_1.`itemrevenue`, ((gen_subquery_1.`_w0` * 100.00BD) / CAST(gen_subquery_1.`_we0` AS DECIMAL(28,2))) AS `revenueratio`
         |FROM
-        |  (SELECT gen_subquery_0.`i_item_desc`, gen_subquery_0.`i_category`, gen_subquery_0.`i_class`, gen_subquery_0.`i_current_price`, gen_subquery_0.`itemrevenue`, gen_subquery_0.`_w0`, gen_subquery_0.`_w1`, gen_subquery_0.`i_item_id`, sum(gen_subquery_0.`_w1`) OVER (PARTITION BY gen_subquery_0.`i_class` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `_we0` 
+        |  (SELECT gen_subquery_0.`i_item_desc`, gen_subquery_0.`i_category`, gen_subquery_0.`i_class`, gen_subquery_0.`i_current_price`, gen_subquery_0.`itemrevenue`, gen_subquery_0.`_w0`, gen_subquery_0.`_w1`, gen_subquery_0.`i_item_id`, sum(gen_subquery_0.`_w1`) OVER (PARTITION BY gen_subquery_0.`i_class` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `_we0`
         |  FROM
-        |    (SELECT gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`, sum(gen_subsumer_0.`sum_agg`) AS `itemrevenue`, sum(gen_subsumer_0.`sum_agg`) AS `_w0`, sum(gen_subsumer_0.`sum_agg`) AS `_w1`, gen_subsumer_0.`i_item_id` 
+        |    (SELECT gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`, sum(gen_subsumer_0.`sum_agg`) AS `itemrevenue`, sum(gen_subsumer_0.`sum_agg`) AS `_w0`, sum(gen_subsumer_0.`sum_agg`) AS `_w1`, gen_subsumer_0.`i_item_id`
         |    FROM
-        |      (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_manager_id`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2)) [...]
+        |      (SELECT dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, item.`i_category`, item.`i_class`, item.`i_manager_id`, item.`i_current_price`, item.`i_item_sk`, store_sales.`ss_store_sk`, sum(store_sales.`ss_ext_sales_price`) AS `sum_agg`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_list_price` AS DECIMAL(12,2)) [...]
         |      FROM
-        |        date_dim dt 
+        |        date_dim dt
         |        INNER JOIN store_sales ON (dt.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |        INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
-        |      GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0 
+        |      GROUP BY dt.`d_date`, dt.`d_moy`, dt.`d_year`, item.`i_brand`, item.`i_brand_id`, item.`i_item_id`, item.`i_item_desc`, substring(item.`i_item_desc`, 1, 30), item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_class_id`, item.`i_current_price`, item.`i_manager_id`, item.`i_item_sk`, store_sales.`ss_store_sk`) gen_subsumer_0
         |    WHERE
         |      (gen_subsumer_0.`i_category` IN ('Sports', 'Books', 'Home')) AND (gen_subsumer_0.`d_date` >= DATE '1999-02-22') AND (gen_subsumer_0.`d_date` <= DATE '1999-03-24')
-        |    GROUP BY gen_subsumer_0.`i_item_id`, gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`) gen_subquery_0 ) gen_subquery_1 
+        |    GROUP BY gen_subsumer_0.`i_item_id`, gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`) gen_subquery_0 ) gen_subquery_1
         |ORDER BY gen_subquery_1.`i_category` ASC NULLS FIRST, gen_subquery_1.`i_class` ASC NULLS FIRST, gen_subquery_1.`i_item_id` ASC NULLS FIRST, gen_subquery_1.`i_item_desc` ASC NULLS FIRST, `revenueratio` ASC NULLS FIRST
         """.stripMargin.trim),
-      // q76 
-      // this case requires a rule of PushAggregateThroughUnion for rewrite to work, which is not implemented for now 
+      // q76
+      // this case requires a rule of PushAggregateThroughUnion for rewrite to work, which is not implemented for now
       ("case_10",
        """
         |SELECT dt.d_date, dt.d_moy, dt.d_year, dt.d_qoy, item.i_brand, item.i_brand_id, item.i_item_id, item.i_item_desc,
@@ -496,13 +512,13 @@ object TestTPCDS_1_4_Batch {
        """
         |SELECT cs_ship_addr_sk , d_date, d_year, d_qoy, d_moy, i_category, cs_ship_addr_sk,i_item_sk, i_item_id,
         |       i_item_desc, i_class, i_current_price, i_brand_id, i_class_id, i_category_id, i_manufact_id,
-        |       SUM(cs_ext_sales_price) sales_amt, 
+        |       SUM(cs_ext_sales_price) sales_amt,
         |       SUM(cs_quantity*cs_list_price) sales,
         |       SUM(cs_ext_discount_amt) as `excess discount amount`,
         |       count(*) number_sales
         |FROM catalog_sales, item, date_dim
         |WHERE cs_item_sk = i_item_sk
-        |  AND cs_sold_date_sk = d_date_sk      
+        |  AND cs_sold_date_sk = d_date_sk
         |GROUP BY i_brand_id, i_class_id, i_category_id, i_item_id, i_item_desc, i_category, i_class,
         |         i_current_price, i_manufact_id, d_date, d_moy, d_qoy, d_year, cs_ship_addr_sk, i_item_sk
        """.stripMargin.trim,
@@ -525,21 +541,21 @@ object TestTPCDS_1_4_Batch {
         | limit 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_1.`i_item_desc`, gen_subquery_1.`i_category`, gen_subquery_1.`i_class`, gen_subquery_1.`i_current_price`, gen_subquery_1.`itemrevenue`, ((gen_subquery_1.`_w0` * 100.00BD) / CAST(gen_subquery_1.`_we0` AS DECIMAL(28,2))) AS `revenueratio` 
+        |SELECT gen_subquery_1.`i_item_desc`, gen_subquery_1.`i_category`, gen_subquery_1.`i_class`, gen_subquery_1.`i_current_price`, gen_subquery_1.`itemrevenue`, ((gen_subquery_1.`_w0` * 100.00BD) / CAST(gen_subquery_1.`_we0` AS DECIMAL(28,2))) AS `revenueratio`
         |FROM
-        |  (SELECT gen_subquery_0.`i_item_desc`, gen_subquery_0.`i_category`, gen_subquery_0.`i_class`, gen_subquery_0.`i_current_price`, gen_subquery_0.`itemrevenue`, gen_subquery_0.`_w0`, gen_subquery_0.`_w1`, gen_subquery_0.`i_item_id`, sum(gen_subquery_0.`_w1`) OVER (PARTITION BY gen_subquery_0.`i_class` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `_we0` 
+        |  (SELECT gen_subquery_0.`i_item_desc`, gen_subquery_0.`i_category`, gen_subquery_0.`i_class`, gen_subquery_0.`i_current_price`, gen_subquery_0.`itemrevenue`, gen_subquery_0.`_w0`, gen_subquery_0.`_w1`, gen_subquery_0.`i_item_id`, sum(gen_subquery_0.`_w1`) OVER (PARTITION BY gen_subquery_0.`i_class` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `_we0`
         |  FROM
-        |    (SELECT gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`, sum(gen_subsumer_0.`sales_amt`) AS `itemrevenue`, sum(gen_subsumer_0.`sales_amt`) AS `_w0`, sum(gen_subsumer_0.`sales_amt`) AS `_w1`, gen_subsumer_0.`i_item_id` 
+        |    (SELECT gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`, sum(gen_subsumer_0.`sales_amt`) AS `itemrevenue`, sum(gen_subsumer_0.`sales_amt`) AS `_w0`, sum(gen_subsumer_0.`sales_amt`) AS `_w1`, gen_subsumer_0.`i_item_id`
         |    FROM
-        |      (SELECT catalog_sales.`cs_ship_addr_sk`, date_dim.`d_date`, date_dim.`d_year`, date_dim.`d_qoy`, date_dim.`d_moy`, item.`i_category`, catalog_sales.`cs_ship_addr_sk`, item.`i_item_sk`, item.`i_item_id`, item.`i_item_desc`, item.`i_class`, item.`i_current_price`, item.`i_brand_id`, item.`i_class_id`, item.`i_category_id`, item.`i_manufact_id`, sum(catalog_sales.`cs_ext_sales_price`) AS `sales_amt`, sum((CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2 [...]
+        |      (SELECT catalog_sales.`cs_ship_addr_sk`, date_dim.`d_date`, date_dim.`d_year`, date_dim.`d_qoy`, date_dim.`d_moy`, item.`i_category`, catalog_sales.`cs_ship_addr_sk`, item.`i_item_sk`, item.`i_item_id`, item.`i_item_desc`, item.`i_class`, item.`i_current_price`, item.`i_brand_id`, item.`i_class_id`, item.`i_category_id`, item.`i_manufact_id`, sum(catalog_sales.`cs_ext_sales_price`) AS `sales_amt`, sum((CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2 [...]
         |      FROM
         |        catalog_sales
         |        INNER JOIN item ON (catalog_sales.`cs_item_sk` = item.`i_item_sk`)
         |        INNER JOIN date_dim ON (catalog_sales.`cs_sold_date_sk` = date_dim.`d_date_sk`)
-        |      GROUP BY item.`i_brand_id`, item.`i_class_id`, item.`i_category_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_manufact_id`, date_dim.`d_date`, date_dim.`d_moy`, date_dim.`d_qoy`, date_dim.`d_year`, catalog_sales.`cs_ship_addr_sk`, item.`i_item_sk`) gen_subsumer_0 
+        |      GROUP BY item.`i_brand_id`, item.`i_class_id`, item.`i_category_id`, item.`i_item_id`, item.`i_item_desc`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_manufact_id`, date_dim.`d_date`, date_dim.`d_moy`, date_dim.`d_qoy`, date_dim.`d_year`, catalog_sales.`cs_ship_addr_sk`, item.`i_item_sk`) gen_subsumer_0
         |    WHERE
         |      (gen_subsumer_0.`i_category` IN ('Sports', 'Books', 'Home')) AND (gen_subsumer_0.`d_date` >= DATE '1999-02-22') AND (gen_subsumer_0.`d_date` <= DATE '1999-03-24')
-        |    GROUP BY gen_subsumer_0.`i_item_id`, gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`) gen_subquery_0 ) gen_subquery_1 
+        |    GROUP BY gen_subsumer_0.`i_item_id`, gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`) gen_subquery_0 ) gen_subquery_1
         |ORDER BY gen_subquery_1.`i_category` ASC NULLS FIRST, gen_subquery_1.`i_class` ASC NULLS FIRST, gen_subquery_1.`i_item_id` ASC NULLS FIRST, gen_subquery_1.`i_item_desc` ASC NULLS FIRST, `revenueratio` ASC NULLS FIRST
         |LIMIT 100
        """.stripMargin.trim),
@@ -548,13 +564,13 @@ object TestTPCDS_1_4_Batch {
        """
         |SELECT cs_ship_addr_sk , d_date, d_year, d_qoy, d_moy, i_category, cs_ship_addr_sk,i_item_sk, i_item_id,
         |       i_item_desc, i_class, i_current_price, i_brand_id, i_class_id, i_category_id, i_manufact_id,
-        |       SUM(cs_ext_sales_price) sales_amt, 
+        |       SUM(cs_ext_sales_price) sales_amt,
         |       SUM(cs_quantity*cs_list_price) sales,
         |       SUM(cs_ext_discount_amt) as `excess discount amount`,
         |       count(*) number_sales
         |FROM catalog_sales, item, date_dim
         |WHERE cs_item_sk = i_item_sk
-        |  AND cs_sold_date_sk = d_date_sk      
+        |  AND cs_sold_date_sk = d_date_sk
         |GROUP BY i_brand_id, i_class_id, i_category_id, i_item_id, i_item_desc, i_category, i_class,
         |         i_current_price, i_manufact_id, d_date, d_moy, d_qoy, d_year, cs_ship_addr_sk, i_item_sk
        """.stripMargin.trim,
@@ -582,7 +598,7 @@ object TestTPCDS_1_4_Batch {
        """
         |SELECT cs_ship_addr_sk , d_date, d_year, d_qoy, d_moy, i_category, cs_ext_sales_price, cs_ship_addr_sk, i_item_sk, i_item_id,
         |       i_item_desc, i_class, i_current_price, i_brand_id, i_class_id, i_category_id, i_manufact_id,
-        |       SUM(cs_ext_sales_price) sales_amt, 
+        |       SUM(cs_ext_sales_price) sales_amt,
         |       SUM(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over
         |          (partition by i_class) as revenueratio,
         |       SUM(cs_quantity*cs_list_price) sales,
@@ -590,7 +606,7 @@ object TestTPCDS_1_4_Batch {
         |       count(*) number_sales
         |FROM catalog_sales, item, date_dim
         |WHERE cs_item_sk = i_item_sk
-        |  AND cs_sold_date_sk = d_date_sk      
+        |  AND cs_sold_date_sk = d_date_sk
         |GROUP BY i_brand_id, i_class_id, i_category_id, i_item_id, i_item_desc, i_category, i_class,
         |         i_current_price, i_manufact_id, d_date, d_moy, d_qoy, d_year, cs_ext_sales_price, cs_ship_addr_sk, i_item_sk
        """.stripMargin.trim,
@@ -656,13 +672,13 @@ object TestTPCDS_1_4_Batch {
        """
         |SELECT cs_ship_addr_sk , d_date, d_year, d_qoy, d_moy, i_category, cs_ext_sales_price, cs_ship_addr_sk, i_item_sk, i_item_id,
         |       i_item_desc, i_class, i_current_price, i_brand_id, i_class_id, i_category_id, i_manufact_id,
-        |       SUM(cs_ext_sales_price) sales_amt, 
+        |       SUM(cs_ext_sales_price) sales_amt,
         |       SUM(cs_quantity*cs_list_price) sales,
         |       SUM(cs_ext_discount_amt) as `excess discount amount`,
         |       count(*) number_sales
         |FROM catalog_sales, item, date_dim
         |WHERE cs_item_sk = i_item_sk
-        |  AND cs_sold_date_sk = d_date_sk      
+        |  AND cs_sold_date_sk = d_date_sk
         |GROUP BY i_brand_id, i_class_id, i_category_id, i_item_id, i_item_desc, i_category, i_class,
         |         i_current_price, i_manufact_id, d_date, d_moy, d_qoy, d_year, cs_ship_addr_sk, i_item_sk,
         |         cs_ext_sales_price
@@ -754,18 +770,18 @@ object TestTPCDS_1_4_Batch {
         | limit 100
        """.stripMargin.trim,
        """
-        |SELECT sum(gen_subquery_4.`sales`) AS `sum(sales)` 
+        |SELECT sum(gen_subquery_4.`sales`) AS `sum(sales)`
         |FROM
-        |  (SELECT (CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(catalog_sales.`cs_list_price` AS DECIMAL(12,2))) AS `sales` 
+        |  (SELECT (CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(catalog_sales.`cs_list_price` AS DECIMAL(12,2))) AS `sales`
         |  FROM
         |    catalog_sales
-        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)` 
+        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)`
         |    FROM
         |      store_sales
         |      INNER JOIN date_dim ON (date_dim.`d_year` IN (2000, 2001, 2002, 2003)) AND (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
         |      INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
         |    GROUP BY substring(item.`i_item_desc`, 1, 30), item.`i_item_sk`, date_dim.`d_date`) gen_subquery_0  ON (gen_subquery_0.`count(1)` > 4L) AND (catalog_sales.`cs_item_sk` = gen_subquery_0.`item_sk`)
-        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales` 
+        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
@@ -774,23 +790,23 @@ object TestTPCDS_1_4_Batch {
         |  WHERE
         |    (CAST(`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#219 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#222 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_0_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`   FROM  store_sales  INNER JO [...]
         |  UNION ALL
-        |  SELECT (CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2))) AS `sales` 
+        |  SELECT (CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2))) AS `sales`
         |  FROM
         |    web_sales
-        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)` 
+        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)`
         |    FROM
         |      store_sales
         |      INNER JOIN date_dim ON (date_dim.`d_year` IN (2000, 2001, 2002, 2003)) AND (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
         |      INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
         |    GROUP BY substring(item.`i_item_desc`, 1, 30), item.`i_item_sk`, date_dim.`d_date`) gen_subquery_2  ON (gen_subquery_2.`count(1)` > 4L) AND (web_sales.`ws_item_sk` = gen_subquery_2.`item_sk`)
-        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales` 
+        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |    GROUP BY customer.`c_customer_sk`) gen_subquery_3  ON (web_sales.`ws_bill_customer_sk` = gen_subquery_3.`c_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
         |  WHERE
-        |    (CAST(`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#219 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#222 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_1_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`   FROM  store_sales  INNER JO [...]
+        |    (CAST(`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#219 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#222 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_1_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`   FROM  store_sales  INNER JO [...]
         |LIMIT 100
        """.stripMargin.trim),
       // q23b
@@ -851,20 +867,20 @@ object TestTPCDS_1_4_Batch {
         | limit 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_6.`c_last_name`, gen_subquery_6.`c_first_name`, gen_subquery_6.`sales` 
+        |SELECT gen_subquery_6.`c_last_name`, gen_subquery_6.`c_first_name`, gen_subquery_6.`sales`
         |FROM
-        |  (SELECT gen_subquery_2.`c_last_name`, gen_subquery_2.`c_first_name`, sum((CAST(CAST(gen_subquery_2.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(gen_subquery_2.`cs_list_price` AS DECIMAL(12,2)))) AS `sales` 
+        |  (SELECT gen_subquery_2.`c_last_name`, gen_subquery_2.`c_first_name`, sum((CAST(CAST(gen_subquery_2.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(gen_subquery_2.`cs_list_price` AS DECIMAL(12,2)))) AS `sales`
         |  FROM
-        |    (SELECT `cs_quantity`, `cs_list_price`, `c_first_name`, `c_last_name` 
+        |    (SELECT `cs_quantity`, `cs_list_price`, `c_first_name`, `c_last_name`
         |    FROM
         |      catalog_sales
-        |      LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)` 
+        |      LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)`
         |      FROM
         |        store_sales
         |        INNER JOIN date_dim ON (date_dim.`d_year` IN (2000, 2001, 2002, 2003)) AND (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
         |        INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
         |      GROUP BY substring(item.`i_item_desc`, 1, 30), item.`i_item_sk`, date_dim.`d_date`) gen_subquery_0  ON (gen_subquery_0.`count(1)` > 4L) AND (catalog_sales.`cs_item_sk` = gen_subquery_0.`item_sk`)
-        |      LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales` 
+        |      LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`
         |      FROM
         |        customer
         |        INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
@@ -872,21 +888,21 @@ object TestTPCDS_1_4_Batch {
         |      INNER JOIN customer ON (catalog_sales.`cs_bill_customer_sk` = customer.`c_customer_sk`)
         |      INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (catalog_sales.`cs_sold_date_sk` = date_dim.`d_date_sk`)
         |    WHERE
-        |      (CAST(`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#219 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#222 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_0_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`   FROM  store_sales  INNER  [...]
+        |      (CAST(`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#219 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#222 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_0_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`   FROM  store_sales  INNER  [...]
         |  GROUP BY gen_subquery_2.`c_last_name`, gen_subquery_2.`c_first_name`
         |  UNION ALL
-        |  SELECT gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`, sum((CAST(CAST(gen_subquery_5.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(gen_subquery_5.`ws_list_price` AS DECIMAL(12,2)))) AS `sales` 
+        |  SELECT gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`, sum((CAST(CAST(gen_subquery_5.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(gen_subquery_5.`ws_list_price` AS DECIMAL(12,2)))) AS `sales`
         |  FROM
-        |    (SELECT `ws_quantity`, `ws_list_price`, `c_first_name`, `c_last_name` 
+        |    (SELECT `ws_quantity`, `ws_list_price`, `c_first_name`, `c_last_name`
         |    FROM
         |      web_sales
-        |      LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)` 
+        |      LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)`
         |      FROM
         |        store_sales
         |        INNER JOIN date_dim ON (date_dim.`d_year` IN (2000, 2001, 2002, 2003)) AND (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
         |        INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
         |      GROUP BY substring(item.`i_item_desc`, 1, 30), item.`i_item_sk`, date_dim.`d_date`) gen_subquery_3  ON (gen_subquery_3.`count(1)` > 4L) AND (web_sales.`ws_item_sk` = gen_subquery_3.`item_sk`)
-        |      LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales` 
+        |      LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`
         |      FROM
         |        customer
         |        INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
@@ -894,8 +910,8 @@ object TestTPCDS_1_4_Batch {
         |      INNER JOIN customer ON (web_sales.`ws_bill_customer_sk` = customer.`c_customer_sk`)
         |      INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
         |    WHERE
-        |      (CAST(`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#219 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#222 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_1_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`   FROM  store_sales  INNER  [...]
-        |  GROUP BY gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`) gen_subquery_6 
+        |      (CAST(`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#219 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#222 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_1_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `csales`   FROM  store_sales  INNER  [...]
+        |  GROUP BY gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`) gen_subquery_6
         |ORDER BY gen_subquery_6.`c_last_name` ASC NULLS FIRST, gen_subquery_6.`c_first_name` ASC NULLS FIRST, gen_subquery_6.`sales` ASC NULLS FIRST
         |LIMIT 100
        """.stripMargin.trim),
@@ -1037,22 +1053,22 @@ object TestTPCDS_1_4_Batch {
         | LIMIT 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_1.`customer_id`, gen_subquery_1.`customer_first_name`, gen_subquery_1.`customer_last_name`, gen_subquery_1.`customer_preferred_cust_flag`, gen_subquery_1.`customer_birth_country`, gen_subquery_1.`customer_login`, gen_subquery_1.`customer_email_address` 
+        |SELECT gen_subquery_1.`customer_id`, gen_subquery_1.`customer_first_name`, gen_subquery_1.`customer_last_name`, gen_subquery_1.`customer_preferred_cust_flag`, gen_subquery_1.`customer_birth_country`, gen_subquery_1.`customer_login`, gen_subquery_1.`customer_email_address`
         |FROM
-        |  (SELECT gen_subsumer_0.`customer_id` AS `customer_id`, sum(gen_subsumer_0.`year_total`) AS `year_total` 
+        |  (SELECT gen_subsumer_0.`customer_id` AS `customer_id`, sum(gen_subsumer_0.`year_total`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_0 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_0
         |  WHERE
         |    (gen_subsumer_0.`dyear` = 2001)
         |  GROUP BY gen_subsumer_0.`customer_id`, gen_subsumer_0.`customer_first_name`, gen_subsumer_0.`customer_last_name`, gen_subsumer_0.`customer_preferred_cust_flag`, gen_subsumer_0.`customer_birth_country`, gen_subsumer_0.`customer_login`, gen_subsumer_0.`customer_email_address`, gen_subsumer_0.`dyear`
         |  HAVING (sum(gen_subsumer_0.`year_total`) > 0E-13BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN catalog_sales ON (customer.`c_customer_sk` = catalog_sales.`cs_bill_customer_sk`)
@@ -1062,7 +1078,7 @@ object TestTPCDS_1_4_Batch {
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  HAVING (`year_total` > 0E-13BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
@@ -1070,20 +1086,20 @@ object TestTPCDS_1_4_Batch {
         |  WHERE
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
-        |  HAVING (`year_total` > 0E-13BD)) gen_subquery_0 
-        |  INNER JOIN (SELECT gen_subsumer_1.`customer_id` AS `customer_id`, gen_subsumer_1.`customer_first_name` AS `customer_first_name`, gen_subsumer_1.`customer_last_name` AS `customer_last_name`, gen_subsumer_1.`customer_preferred_cust_flag` AS `customer_preferred_cust_flag`, gen_subsumer_1.`customer_birth_country` AS `customer_birth_country`, gen_subsumer_1.`customer_login` AS `customer_login`, gen_subsumer_1.`customer_email_address` AS `customer_email_address`, sum(gen_subsumer_1. [...]
+        |  HAVING (`year_total` > 0E-13BD)) gen_subquery_0
+        |  INNER JOIN (SELECT gen_subsumer_1.`customer_id` AS `customer_id`, gen_subsumer_1.`customer_first_name` AS `customer_first_name`, gen_subsumer_1.`customer_last_name` AS `customer_last_name`, gen_subsumer_1.`customer_preferred_cust_flag` AS `customer_preferred_cust_flag`, gen_subsumer_1.`customer_birth_country` AS `customer_birth_country`, gen_subsumer_1.`customer_login` AS `customer_login`, gen_subsumer_1.`customer_email_address` AS `customer_email_address`, sum(gen_subsumer_1. [...]
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_1 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_1
         |  WHERE
         |    (gen_subsumer_1.`dyear` = 2002)
         |  GROUP BY gen_subsumer_1.`customer_id`, gen_subsumer_1.`customer_first_name`, gen_subsumer_1.`customer_last_name`, gen_subsumer_1.`customer_preferred_cust_flag`, gen_subsumer_1.`customer_birth_country`, gen_subsumer_1.`customer_login`, gen_subsumer_1.`customer_email_address`, gen_subsumer_1.`dyear`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` [...]
+        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` [...]
         |  FROM
         |    customer
         |    INNER JOIN catalog_sales ON (customer.`c_customer_sk` = catalog_sales.`cs_bill_customer_sk`)
@@ -1092,7 +1108,7 @@ object TestTPCDS_1_4_Batch {
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECI [...]
+        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECI [...]
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
@@ -1100,20 +1116,20 @@ object TestTPCDS_1_4_Batch {
         |  WHERE
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_1  ON (gen_subquery_1.`customer_id` = gen_subquery_0.`customer_id`)
-        |  INNER JOIN (SELECT gen_subsumer_2.`customer_id` AS `customer_id`, sum(gen_subsumer_2.`year_total`) AS `year_total` 
+        |  INNER JOIN (SELECT gen_subsumer_2.`customer_id` AS `customer_id`, sum(gen_subsumer_2.`year_total`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_2 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_2
         |  WHERE
         |    false
         |  GROUP BY gen_subsumer_2.`customer_id`, gen_subsumer_2.`customer_first_name`, gen_subsumer_2.`customer_last_name`, gen_subsumer_2.`customer_preferred_cust_flag`, gen_subsumer_2.`customer_birth_country`, gen_subsumer_2.`customer_login`, gen_subsumer_2.`customer_email_address`, gen_subsumer_2.`dyear`
         |  HAVING (sum(gen_subsumer_2.`year_total`) > 0E-13BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN catalog_sales ON (customer.`c_customer_sk` = catalog_sales.`cs_bill_customer_sk`)
@@ -1121,7 +1137,7 @@ object TestTPCDS_1_4_Batch {
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  HAVING (`year_total` > 0E-13BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
@@ -1130,47 +1146,47 @@ object TestTPCDS_1_4_Batch {
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  HAVING (`year_total` > 0E-13BD)) gen_subquery_2  ON (gen_subquery_0.`customer_id` = gen_subquery_2.`customer_id`)
-        |  INNER JOIN (SELECT gen_subsumer_3.`customer_id` AS `customer_id`, sum(gen_subsumer_3.`year_total`) AS `year_total` 
+        |  INNER JOIN (SELECT gen_subsumer_3.`customer_id` AS `customer_id`, sum(gen_subsumer_3.`year_total`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_3 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_3
         |  WHERE
         |    false
         |  GROUP BY gen_subsumer_3.`customer_id`, gen_subsumer_3.`customer_first_name`, gen_subsumer_3.`customer_last_name`, gen_subsumer_3.`customer_preferred_cust_flag`, gen_subsumer_3.`customer_birth_country`, gen_subsumer_3.`customer_login`, gen_subsumer_3.`customer_email_address`, gen_subsumer_3.`dyear`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN catalog_sales ON (customer.`c_customer_sk` = catalog_sales.`cs_bill_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2002) AND (catalog_sales.`cs_sold_date_sk` = date_dim.`d_date_sk`)
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
         |    INNER JOIN date_dim ON (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
         |  WHERE
         |    false
-        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_3 
-        |  INNER JOIN (SELECT gen_subsumer_4.`customer_id` AS `customer_id`, sum(gen_subsumer_4.`year_total`) AS `year_total` 
+        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_3
+        |  INNER JOIN (SELECT gen_subsumer_4.`customer_id` AS `customer_id`, sum(gen_subsumer_4.`year_total`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_4 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_4
         |  WHERE
         |    false
         |  GROUP BY gen_subsumer_4.`customer_id`, gen_subsumer_4.`customer_first_name`, gen_subsumer_4.`customer_last_name`, gen_subsumer_4.`customer_preferred_cust_flag`, gen_subsumer_4.`customer_birth_country`, gen_subsumer_4.`customer_login`, gen_subsumer_4.`customer_email_address`, gen_subsumer_4.`dyear`
         |  HAVING (sum(gen_subsumer_4.`year_total`) > 0E-13BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN catalog_sales ON (customer.`c_customer_sk` = catalog_sales.`cs_bill_customer_sk`)
@@ -1180,26 +1196,26 @@ object TestTPCDS_1_4_Batch {
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  HAVING (`year_total` > 0E-13BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2001) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  HAVING (`year_total` > 0E-13BD)) gen_subquery_4  ON (gen_subquery_0.`customer_id` = gen_subquery_4.`customer_id`)
-        |  INNER JOIN (SELECT gen_subsumer_5.`customer_id` AS `customer_id`, sum(gen_subsumer_5.`year_total`) AS `year_total` 
+        |  INNER JOIN (SELECT gen_subsumer_5.`customer_id` AS `customer_id`, sum(gen_subsumer_5.`year_total`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_5 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_5
         |  WHERE
         |    false
         |  GROUP BY gen_subsumer_5.`customer_id`, gen_subsumer_5.`customer_first_name`, gen_subsumer_5.`customer_last_name`, gen_subsumer_5.`customer_preferred_cust_flag`, gen_subsumer_5.`customer_birth_country`, gen_subsumer_5.`customer_login`, gen_subsumer_5.`customer_email_address`, gen_subsumer_5.`dyear`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(catalog_sales.`cs_ext_list_price` AS DECIMAL(8,2)) - CAST(catalog_sales.`cs_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(catalog_sales.`cs_ext_discount_amt` AS DECIMAL(8,2))) + CAST(catalog_sales.`cs_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN catalog_sales ON (customer.`c_customer_sk` = catalog_sales.`cs_bill_customer_sk`)
@@ -1208,12 +1224,12 @@ object TestTPCDS_1_4_Batch {
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST((((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_wholesale_cost` AS DECIMAL(8,2))) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2))) + CAST(web_sales.`ws_ext_sales_price` AS DECIMAL(8,2))) AS DECIMAL(12,2)) / 2.00BD)) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2002) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
-        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_5 
+        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_5
         |WHERE
         |  (gen_subquery_0.`customer_id` = gen_subquery_3.`customer_id`) AND (CASE WHEN (gen_subquery_2.`year_total` > 0E-13BD) THEN (gen_subquery_3.`year_total` / gen_subquery_2.`year_total`) ELSE CAST(NULL AS DECIMAL(38,23)) END > CASE WHEN (gen_subquery_0.`year_total` > 0E-13BD) THEN (gen_subquery_1.`year_total` / gen_subquery_0.`year_total`) ELSE CAST(NULL AS DECIMAL(38,23)) END) AND (gen_subquery_0.`customer_id` = gen_subquery_5.`customer_id`) AND (CASE WHEN (gen_subquery_2.`year_to [...]
         |ORDER BY gen_subquery_1.`customer_id` ASC NULLS FIRST, gen_subquery_1.`customer_first_name` ASC NULLS FIRST, gen_subquery_1.`customer_last_name` ASC NULLS FIRST, gen_subquery_1.`customer_preferred_cust_flag` ASC NULLS FIRST, gen_subquery_1.`customer_birth_country` ASC NULLS FIRST, gen_subquery_1.`customer_login` ASC NULLS FIRST, gen_subquery_1.`customer_email_address` ASC NULLS FIRST
@@ -1313,22 +1329,22 @@ object TestTPCDS_1_4_Batch {
         | LIMIT 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_1.`customer_preferred_cust_flag` 
+        |SELECT gen_subquery_1.`customer_preferred_cust_flag`
         |FROM
-        |  (SELECT gen_subsumer_0.`customer_id` AS `customer_id`, sum(gen_subsumer_0.`year_total1`) AS `year_total` 
+        |  (SELECT gen_subsumer_0.`customer_id` AS `customer_id`, sum(gen_subsumer_0.`year_total1`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_0 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_0
         |  WHERE
         |    (gen_subsumer_0.`dyear` = 2001)
         |  GROUP BY gen_subsumer_0.`customer_id`, gen_subsumer_0.`customer_first_name`, gen_subsumer_0.`customer_last_name`, gen_subsumer_0.`dyear`, gen_subsumer_0.`customer_preferred_cust_flag`, gen_subsumer_0.`customer_birth_country`, gen_subsumer_0.`customer_login`, gen_subsumer_0.`customer_email_address`
         |  HAVING (sum(gen_subsumer_0.`year_total1`) > 0.00BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
@@ -1336,20 +1352,20 @@ object TestTPCDS_1_4_Batch {
         |  WHERE
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
-        |  HAVING (`year_total` > 0.00BD)) gen_subquery_0 
-        |  INNER JOIN (SELECT gen_subsumer_1.`customer_id` AS `customer_id`, gen_subsumer_1.`customer_preferred_cust_flag` AS `customer_preferred_cust_flag`, sum(gen_subsumer_1.`year_total1`) AS `year_total` 
+        |  HAVING (`year_total` > 0.00BD)) gen_subquery_0
+        |  INNER JOIN (SELECT gen_subsumer_1.`customer_id` AS `customer_id`, gen_subsumer_1.`customer_preferred_cust_flag` AS `customer_preferred_cust_flag`, sum(gen_subsumer_1.`year_total1`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_1 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_1
         |  WHERE
         |    (gen_subsumer_1.`dyear` = 2002)
         |  GROUP BY gen_subsumer_1.`customer_id`, gen_subsumer_1.`customer_first_name`, gen_subsumer_1.`customer_last_name`, gen_subsumer_1.`dyear`, gen_subsumer_1.`customer_preferred_cust_flag`, gen_subsumer_1.`customer_birth_country`, gen_subsumer_1.`customer_login`, gen_subsumer_1.`customer_email_address`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
@@ -1357,44 +1373,44 @@ object TestTPCDS_1_4_Batch {
         |  WHERE
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_1  ON (gen_subquery_1.`customer_id` = gen_subquery_0.`customer_id`)
-        |  INNER JOIN (SELECT gen_subsumer_2.`customer_id` AS `customer_id`, sum(gen_subsumer_2.`year_total1`) AS `year_total` 
+        |  INNER JOIN (SELECT gen_subsumer_2.`customer_id` AS `customer_id`, sum(gen_subsumer_2.`year_total1`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_2 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_2
         |  WHERE
         |    false
         |  GROUP BY gen_subsumer_2.`customer_id`, gen_subsumer_2.`customer_first_name`, gen_subsumer_2.`customer_last_name`, gen_subsumer_2.`dyear`, gen_subsumer_2.`customer_preferred_cust_flag`, gen_subsumer_2.`customer_birth_country`, gen_subsumer_2.`customer_login`, gen_subsumer_2.`customer_email_address`
         |  HAVING (sum(gen_subsumer_2.`year_total1`) > 0.00BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2001) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`
         |  HAVING (`year_total` > 0.00BD)) gen_subquery_2  ON (gen_subquery_0.`customer_id` = gen_subquery_2.`customer_id`)
-        |  INNER JOIN (SELECT gen_subsumer_3.`customer_id` AS `customer_id`, sum(gen_subsumer_3.`year_total1`) AS `year_total` 
+        |  INNER JOIN (SELECT gen_subsumer_3.`customer_id` AS `customer_id`, sum(gen_subsumer_3.`year_total1`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, sum((CAST((((CAST(store_sales.`ss_ext_list_price`  [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_3 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`) gen_subsumer_3
         |  WHERE
         |    false
         |  GROUP BY gen_subsumer_3.`customer_id`, gen_subsumer_3.`customer_first_name`, gen_subsumer_3.`customer_last_name`, gen_subsumer_3.`dyear`, gen_subsumer_3.`customer_preferred_cust_flag`, gen_subsumer_3.`customer_birth_country`, gen_subsumer_3.`customer_login`, gen_subsumer_3.`customer_email_address`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum((CAST(web_sales.`ws_ext_list_price` AS DECIMAL(8,2)) - CAST(web_sales.`ws_ext_discount_amt` AS DECIMAL(8,2)))) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2002) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
-        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_3 
+        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`) gen_subquery_3
         |WHERE
         |  (gen_subquery_0.`customer_id` = gen_subquery_3.`customer_id`) AND (CASE WHEN (gen_subquery_2.`year_total` > 0.00BD) THEN (gen_subquery_3.`year_total` / gen_subquery_2.`year_total`) ELSE CAST(NULL AS DECIMAL(38,20)) END > CASE WHEN (gen_subquery_0.`year_total` > 0.00BD) THEN (gen_subquery_1.`year_total` / gen_subquery_0.`year_total`) ELSE CAST(NULL AS DECIMAL(38,20)) END)
         |ORDER BY gen_subquery_1.`customer_preferred_cust_flag` ASC NULLS FIRST
@@ -1530,22 +1546,22 @@ object TestTPCDS_1_4_Batch {
         | limit 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_1.`customer_id`, gen_subquery_1.`customer_first_name`, gen_subquery_1.`customer_last_name` 
+        |SELECT gen_subquery_1.`customer_id`, gen_subquery_1.`customer_first_name`, gen_subquery_1.`customer_last_name`
         |FROM
-        |  (SELECT gen_subsumer_0.`customer_id` AS `customer_id`, sum(gen_subsumer_0.`year_total_74`) AS `year_total` 
+        |  (SELECT gen_subsumer_0.`customer_id` AS `customer_id`, sum(gen_subsumer_0.`year_total_74`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_0 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_0
         |  WHERE
         |    (gen_subsumer_0.`dyear` IN (2001, 2002)) AND (gen_subsumer_0.`dyear` = 2001)
         |  GROUP BY gen_subsumer_0.`customer_id`, gen_subsumer_0.`customer_first_name`, gen_subsumer_0.`customer_last_name`, gen_subsumer_0.`dyear`
         |  HAVING (sum(gen_subsumer_0.`year_total_74`) > 0.00BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum(web_sales.`ws_net_paid`) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum(web_sales.`ws_net_paid`) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
@@ -1553,20 +1569,20 @@ object TestTPCDS_1_4_Batch {
         |  WHERE
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, date_dim.`d_year`
-        |  HAVING (`year_total` > 0.00BD)) gen_subquery_0 
-        |  INNER JOIN (SELECT gen_subsumer_1.`customer_id` AS `customer_id`, gen_subsumer_1.`customer_first_name` AS `customer_first_name`, gen_subsumer_1.`customer_last_name` AS `customer_last_name`, sum(gen_subsumer_1.`year_total_74`) AS `year_total` 
+        |  HAVING (`year_total` > 0.00BD)) gen_subquery_0
+        |  INNER JOIN (SELECT gen_subsumer_1.`customer_id` AS `customer_id`, gen_subsumer_1.`customer_first_name` AS `customer_first_name`, gen_subsumer_1.`customer_last_name` AS `customer_last_name`, sum(gen_subsumer_1.`year_total_74`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_1 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_1
         |  WHERE
         |    (gen_subsumer_1.`dyear` IN (2001, 2002)) AND (gen_subsumer_1.`dyear` = 2002)
         |  GROUP BY gen_subsumer_1.`customer_id`, gen_subsumer_1.`customer_first_name`, gen_subsumer_1.`customer_last_name`, gen_subsumer_1.`dyear`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, sum(web_sales.`ws_net_paid`) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, sum(web_sales.`ws_net_paid`) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
@@ -1574,44 +1590,44 @@ object TestTPCDS_1_4_Batch {
         |  WHERE
         |    false
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, date_dim.`d_year`) gen_subquery_1  ON (gen_subquery_1.`customer_id` = gen_subquery_0.`customer_id`)
-        |  INNER JOIN (SELECT gen_subsumer_2.`customer_id` AS `customer_id`, sum(gen_subsumer_2.`year_total_74`) AS `year_total` 
+        |  INNER JOIN (SELECT gen_subsumer_2.`customer_id` AS `customer_id`, sum(gen_subsumer_2.`year_total_74`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_2 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_2
         |  WHERE
         |    false AND (gen_subsumer_2.`dyear` IN (2001, 2002))
         |  GROUP BY gen_subsumer_2.`customer_id`, gen_subsumer_2.`customer_first_name`, gen_subsumer_2.`customer_last_name`, gen_subsumer_2.`dyear`
         |  HAVING (sum(gen_subsumer_2.`year_total_74`) > 0.00BD)
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum(web_sales.`ws_net_paid`) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum(web_sales.`ws_net_paid`) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` IN (2001, 2002)) AND (date_dim.`d_year` = 2001) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
         |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, date_dim.`d_year`
         |  HAVING (`year_total` > 0.00BD)) gen_subquery_2  ON (gen_subquery_0.`customer_id` = gen_subquery_2.`customer_id`)
-        |  INNER JOIN (SELECT gen_subsumer_3.`customer_id` AS `customer_id`, sum(gen_subsumer_3.`year_total_74`) AS `year_total` 
+        |  INNER JOIN (SELECT gen_subsumer_3.`customer_id` AS `customer_id`, sum(gen_subsumer_3.`year_total_74`) AS `year_total`
         |  FROM
-        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
+        |    (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST(store_sa [...]
         |    FROM
         |      customer
         |      INNER JOIN store_sales ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |      INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_3 
+        |    GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_3
         |  WHERE
         |    false AND (gen_subsumer_3.`dyear` IN (2001, 2002))
         |  GROUP BY gen_subsumer_3.`customer_id`, gen_subsumer_3.`customer_first_name`, gen_subsumer_3.`customer_last_name`, gen_subsumer_3.`dyear`
         |  UNION ALL
-        |  SELECT customer.`c_customer_id` AS `customer_id`, sum(web_sales.`ws_net_paid`) AS `year_total` 
+        |  SELECT customer.`c_customer_id` AS `customer_id`, sum(web_sales.`ws_net_paid`) AS `year_total`
         |  FROM
         |    customer
         |    INNER JOIN web_sales ON (customer.`c_customer_sk` = web_sales.`ws_bill_customer_sk`)
         |    INNER JOIN date_dim ON (date_dim.`d_year` IN (2001, 2002)) AND (date_dim.`d_year` = 2002) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
-        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, date_dim.`d_year`) gen_subquery_3 
+        |  GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, date_dim.`d_year`) gen_subquery_3
         |WHERE
         |  (gen_subquery_0.`customer_id` = gen_subquery_3.`customer_id`) AND (CASE WHEN (gen_subquery_2.`year_total` > 0.00BD) THEN (gen_subquery_3.`year_total` / gen_subquery_2.`year_total`) ELSE CAST(NULL AS DECIMAL(37,20)) END > CASE WHEN (gen_subquery_0.`year_total` > 0.00BD) THEN (gen_subquery_1.`year_total` / gen_subquery_0.`year_total`) ELSE CAST(NULL AS DECIMAL(37,20)) END)
         |ORDER BY gen_subquery_1.`customer_id` ASC NULLS FIRST, gen_subquery_1.`customer_id` ASC NULLS FIRST, gen_subquery_1.`customer_id` ASC NULLS FIRST
@@ -1668,41 +1684,41 @@ object TestTPCDS_1_4_Batch {
         |) cool_cust
        """.stripMargin.trim,
        """
-        |SELECT count(1) AS `count(1)` 
+        |SELECT count(1) AS `count(1)`
         |FROM
-        |  (SELECT gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`, gen_subquery_5.`d_date` 
+        |  (SELECT gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`, gen_subquery_5.`d_date`
         |  FROM
-        |    (SELECT gen_subquery_3.`c_last_name`, gen_subquery_3.`c_first_name`, gen_subquery_3.`d_date` 
+        |    (SELECT gen_subquery_3.`c_last_name`, gen_subquery_3.`c_first_name`, gen_subquery_3.`d_date`
         |    FROM
-        |      (SELECT gen_subquery_2.`c_last_name`, gen_subquery_2.`c_first_name`, gen_subquery_2.`d_date` 
+        |      (SELECT gen_subquery_2.`c_last_name`, gen_subquery_2.`c_first_name`, gen_subquery_2.`d_date`
         |      FROM
-        |        (SELECT gen_subquery_0.`c_last_name`, gen_subquery_0.`c_first_name`, gen_subquery_0.`d_date` 
+        |        (SELECT gen_subquery_0.`c_last_name`, gen_subquery_0.`c_first_name`, gen_subquery_0.`d_date`
         |        FROM
-        |          (SELECT gen_subsumer_0.`customer_last_name` AS `c_last_name`, gen_subsumer_0.`customer_first_name` AS `c_first_name`, gen_subsumer_0.`ddate` AS `d_date` 
+        |          (SELECT gen_subsumer_0.`customer_last_name` AS `c_last_name`, gen_subsumer_0.`customer_first_name` AS `c_first_name`, gen_subsumer_0.`ddate` AS `d_date`
         |          FROM
-        |            (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST( [...]
+        |            (SELECT customer.`c_customer_id` AS `customer_id`, customer.`c_first_name` AS `customer_first_name`, customer.`c_last_name` AS `customer_last_name`, customer.`c_preferred_cust_flag` AS `customer_preferred_cust_flag`, customer.`c_birth_country` AS `customer_birth_country`, customer.`c_login` AS `customer_login`, customer.`c_email_address` AS `customer_email_address`, date_dim.`d_year` AS `dyear`, date_dim.`d_date` AS `ddate`, date_dim.`d_month_seq`, sum((CAST((((CAST( [...]
         |            FROM
         |              customer
         |              INNER JOIN store_sales ON (customer.`c_customer_sk` = store_sales.`ss_customer_sk`)
         |              INNER JOIN date_dim ON (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
-        |            GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_0 
+        |            GROUP BY customer.`c_customer_id`, customer.`c_first_name`, customer.`c_last_name`, customer.`c_preferred_cust_flag`, customer.`c_birth_country`, customer.`c_login`, customer.`c_email_address`, date_dim.`d_year`, date_dim.`d_date`, date_dim.`d_month_seq`) gen_subsumer_0
         |          WHERE
         |            (gen_subsumer_0.`d_month_seq` >= 1200) AND (gen_subsumer_0.`d_month_seq` <= 1211)
-        |          GROUP BY gen_subsumer_0.`customer_last_name`, gen_subsumer_0.`customer_first_name`, gen_subsumer_0.`ddate`) gen_subquery_0 
-        |          LEFT ANTI JOIN (SELECT customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date` 
+        |          GROUP BY gen_subsumer_0.`customer_last_name`, gen_subsumer_0.`customer_first_name`, gen_subsumer_0.`ddate`) gen_subquery_0
+        |          LEFT ANTI JOIN (SELECT customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date`
         |          FROM
         |            catalog_sales
         |            INNER JOIN date_dim ON (date_dim.`d_month_seq` >= 1200) AND (date_dim.`d_month_seq` <= 1211) AND (catalog_sales.`cs_sold_date_sk` = date_dim.`d_date_sk`)
         |            INNER JOIN customer ON (catalog_sales.`cs_bill_customer_sk` = customer.`c_customer_sk`)
-        |          GROUP BY customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date`) gen_subquery_1  ON (gen_subquery_0.`c_last_name` <=> gen_subquery_1.`c_last_name`) AND (gen_subquery_0.`c_first_name` <=> gen_subquery_1.`c_first_name`) AND (gen_subquery_0.`d_date` <=> gen_subquery_1.`d_date`)) gen_subquery_2 
-        |      GROUP BY gen_subquery_2.`c_last_name`, gen_subquery_2.`c_first_name`, gen_subquery_2.`d_date`) gen_subquery_3 
-        |      LEFT ANTI JOIN (SELECT customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date` 
+        |          GROUP BY customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date`) gen_subquery_1  ON (gen_subquery_0.`c_last_name` <=> gen_subquery_1.`c_last_name`) AND (gen_subquery_0.`c_first_name` <=> gen_subquery_1.`c_first_name`) AND (gen_subquery_0.`d_date` <=> gen_subquery_1.`d_date`)) gen_subquery_2
+        |      GROUP BY gen_subquery_2.`c_last_name`, gen_subquery_2.`c_first_name`, gen_subquery_2.`d_date`) gen_subquery_3
+        |      LEFT ANTI JOIN (SELECT customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date`
         |      FROM
         |        web_sales
         |        INNER JOIN date_dim ON (date_dim.`d_month_seq` >= 1200) AND (date_dim.`d_month_seq` <= 1211) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
         |        INNER JOIN customer ON (web_sales.`ws_bill_customer_sk` = customer.`c_customer_sk`)
-        |      GROUP BY customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date`) gen_subquery_4  ON (gen_subquery_3.`c_last_name` <=> gen_subquery_4.`c_last_name`) AND (gen_subquery_3.`c_first_name` <=> gen_subquery_4.`c_first_name`) AND (gen_subquery_3.`d_date` <=> gen_subquery_4.`d_date`)) gen_subquery_5 
-        |  GROUP BY gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`, gen_subquery_5.`d_date`) gen_subquery_6 
+        |      GROUP BY customer.`c_last_name`, customer.`c_first_name`, date_dim.`d_date`) gen_subquery_4  ON (gen_subquery_3.`c_last_name` <=> gen_subquery_4.`c_last_name`) AND (gen_subquery_3.`c_first_name` <=> gen_subquery_4.`c_first_name`) AND (gen_subquery_3.`d_date` <=> gen_subquery_4.`d_date`)) gen_subquery_5
+        |  GROUP BY gen_subquery_5.`c_last_name`, gen_subquery_5.`c_first_name`, gen_subquery_5.`d_date`) gen_subquery_6
         """.stripMargin.trim),
       // the following two queries involve an MV of store_sales, date_dim, store
       //q43
@@ -1719,7 +1735,7 @@ object TestTPCDS_1_4_Batch {
         |        sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales
         | from date_dim, store_sales, store
         | where d_date_sk = ss_sold_date_sk and
-        |       s_store_sk = ss_store_sk 
+        |       s_store_sk = ss_store_sk
         | group by s_store_name, s_store_id, s_gmt_offset, d_year, s_state, s_county, d_month_seq
        """.stripMargin.trim,
        """
@@ -1742,14 +1758,14 @@ object TestTPCDS_1_4_Batch {
         | limit 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subsumer_0.`s_store_name`, gen_subsumer_0.`s_store_id`, sum(gen_subsumer_0.`sun_sales`) AS `sun_sales`, sum(gen_subsumer_0.`mon_sales`) AS `mon_sales`, sum(gen_subsumer_0.`tue_sales`) AS `tue_sales`, sum(gen_subsumer_0.`wed_sales`) AS `wed_sales`, sum(gen_subsumer_0.`thu_sales`) AS `thu_sales`, sum(gen_subsumer_0.`fri_sales`) AS `fri_sales`, sum(gen_subsumer_0.`sat_sales`) AS `sat_sales` 
+        |SELECT gen_subsumer_0.`s_store_name`, gen_subsumer_0.`s_store_id`, sum(gen_subsumer_0.`sun_sales`) AS `sun_sales`, sum(gen_subsumer_0.`mon_sales`) AS `mon_sales`, sum(gen_subsumer_0.`tue_sales`) AS `tue_sales`, sum(gen_subsumer_0.`wed_sales`) AS `wed_sales`, sum(gen_subsumer_0.`thu_sales`) AS `thu_sales`, sum(gen_subsumer_0.`fri_sales`) AS `fri_sales`, sum(gen_subsumer_0.`sat_sales`) AS `sat_sales`
         |FROM
-        |  (SELECT store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`, sum(store_sales.`ss_net_profit`) AS `sum(ss_net_profit)`, sum(CASE WHEN (date_dim.`d_day_name` = 'Sunday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `sun_sales`, sum(CASE WHEN (date_dim.`d_day_name` = 'Monday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `mon_sales`, s [...]
+        |  (SELECT store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`, sum(store_sales.`ss_net_profit`) AS `sum(ss_net_profit)`, sum(CASE WHEN (date_dim.`d_day_name` = 'Sunday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `sun_sales`, sum(CASE WHEN (date_dim.`d_day_name` = 'Monday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `mon_sales`, s [...]
         |  FROM
         |    date_dim
         |    INNER JOIN store_sales ON (date_dim.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |    INNER JOIN store ON (store.`s_store_sk` = store_sales.`ss_store_sk`)
-        |  GROUP BY store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`) gen_subsumer_0 
+        |  GROUP BY store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`) gen_subsumer_0
         |WHERE
         |  (gen_subsumer_0.`d_year` = 2000) AND (CAST(gen_subsumer_0.`s_gmt_offset` AS DECIMAL(12,2)) = -5.00BD)
         |GROUP BY gen_subsumer_0.`s_store_name`, gen_subsumer_0.`s_store_id`
@@ -1770,7 +1786,7 @@ object TestTPCDS_1_4_Batch {
         |        sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales
         | from date_dim, store_sales, store
         | where d_date_sk = ss_sold_date_sk and
-        |       s_store_sk = ss_store_sk 
+        |       s_store_sk = ss_store_sk
         | group by s_store_name, s_store_id, s_gmt_offset, d_year, s_state, s_county, d_month_seq
        """.stripMargin.trim,
        """
@@ -1805,35 +1821,35 @@ object TestTPCDS_1_4_Batch {
         | limit 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_5.`total_sum`, gen_subquery_5.`s_state`, gen_subquery_5.`s_county`, gen_subquery_5.`lochierarchy`, gen_subquery_5.`rank_within_parent` 
+        |SELECT gen_subquery_5.`total_sum`, gen_subquery_5.`s_state`, gen_subquery_5.`s_county`, gen_subquery_5.`lochierarchy`, gen_subquery_5.`rank_within_parent`
         |FROM
-        |  (SELECT gen_subquery_4.`total_sum`, gen_subquery_4.`s_state`, gen_subquery_4.`s_county`, gen_subquery_4.`lochierarchy`, gen_subquery_4.`_w1`, gen_subquery_4.`_w2`, gen_subquery_4.`_w3`, RANK() OVER (PARTITION BY gen_subquery_4.`_w1`, gen_subquery_4.`_w2` ORDER BY gen_subquery_4.`_w3` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS `rank_within_parent` 
+        |  (SELECT gen_subquery_4.`total_sum`, gen_subquery_4.`s_state`, gen_subquery_4.`s_county`, gen_subquery_4.`lochierarchy`, gen_subquery_4.`_w1`, gen_subquery_4.`_w2`, gen_subquery_4.`_w3`, RANK() OVER (PARTITION BY gen_subquery_4.`_w1`, gen_subquery_4.`_w2` ORDER BY gen_subquery_4.`_w3` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS `rank_within_parent`
         |  FROM
-        |    (SELECT sum(store_sales.`ss_net_profit`) AS gen_subquery_3.`total_sum`, gen_subquery_3.`s_state`, gen_subquery_3.`s_county`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS gen_subquery_3.`lochierarchy`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS gen_subquery_3.`_w1`, CASE WHEN (CAST(CAST((shiftright(`spark_grouping_id`, 0 [...]
+        |    (SELECT sum(store_sales.`ss_net_profit`) AS gen_subquery_3.`total_sum`, gen_subquery_3.`s_state`, gen_subquery_3.`s_county`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS gen_subquery_3.`lochierarchy`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS gen_subquery_3.`_w1`, CASE WHEN (CAST(CAST((shiftright(`spark_grouping_id`, 0 [...]
         |    FROM
-        |      (SELECT sum(gen_subquery_2.`ss_net_profit`) AS `total_sum`, `s_state`, `s_county`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS `lochierarchy`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS `_w1`, CASE WHEN (CAST(CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT) AS INT) = 0) THEN `s_state` END AS `_w2`, sum(gen_s [...]
+        |      (SELECT sum(gen_subquery_2.`ss_net_profit`) AS `total_sum`, `s_state`, `s_county`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS `lochierarchy`, (CAST((shiftright(`spark_grouping_id`, 1) & 1) AS TINYINT) + CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT)) AS `_w1`, CASE WHEN (CAST(CAST((shiftright(`spark_grouping_id`, 0) & 1) AS TINYINT) AS INT) = 0) THEN `s_state` END AS `_w2`, sum(gen_s [...]
         |      FROM
-        |        (SELECT store_sales.`ss_net_profit`, store.`s_state` AS `s_state`, store.`s_county` AS `s_county` 
+        |        (SELECT store_sales.`ss_net_profit`, store.`s_state` AS `s_state`, store.`s_county` AS `s_county`
         |        FROM
         |          store_sales
         |          INNER JOIN date_dim d1  ON (d1.`d_month_seq` >= 1200) AND (d1.`d_month_seq` <= 1211) AND (d1.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |          INNER JOIN store ON (store.`s_store_sk` = store_sales.`ss_store_sk`)
-        |          LEFT SEMI JOIN (SELECT gen_subquery_0.`s_state`, gen_subquery_0.`s_state`, gen_subquery_0.`_w1`, RANK() OVER (PARTITION BY gen_subquery_0.`s_state` ORDER BY gen_subquery_0.`_w1` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS `ranking` 
+        |          LEFT SEMI JOIN (SELECT gen_subquery_0.`s_state`, gen_subquery_0.`s_state`, gen_subquery_0.`_w1`, RANK() OVER (PARTITION BY gen_subquery_0.`s_state` ORDER BY gen_subquery_0.`_w1` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS `ranking`
         |          FROM
-        |            (SELECT gen_subsumer_0.`s_state` AS `s_state`, gen_subsumer_0.`s_state`, sum(gen_subsumer_0.`sum(ss_net_profit)`) AS `_w1` 
+        |            (SELECT gen_subsumer_0.`s_state` AS `s_state`, gen_subsumer_0.`s_state`, sum(gen_subsumer_0.`sum(ss_net_profit)`) AS `_w1`
         |            FROM
-        |              (SELECT store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`, sum(store_sales.`ss_net_profit`) AS `sum(ss_net_profit)`, sum(CASE WHEN (date_dim.`d_day_name` = 'Sunday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `sun_sales`, sum(CASE WHEN (date_dim.`d_day_name` = 'Monday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `m [...]
+        |              (SELECT store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`, sum(store_sales.`ss_net_profit`) AS `sum(ss_net_profit)`, sum(CASE WHEN (date_dim.`d_day_name` = 'Sunday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `sun_sales`, sum(CASE WHEN (date_dim.`d_day_name` = 'Monday') THEN store_sales.`ss_sales_price` ELSE CAST(NULL AS DECIMAL(7,2)) END) AS `m [...]
         |              FROM
         |                date_dim
         |                INNER JOIN store_sales ON (date_dim.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |                INNER JOIN store ON (store.`s_store_sk` = store_sales.`ss_store_sk`)
-        |              GROUP BY store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`) gen_subsumer_0 
+        |              GROUP BY store.`s_store_name`, store.`s_store_id`, store.`s_gmt_offset`, date_dim.`d_year`, store.`s_state`, store.`s_county`, date_dim.`d_month_seq`) gen_subsumer_0
         |            WHERE
         |              (gen_subsumer_0.`d_month_seq` >= 1200) AND (gen_subsumer_0.`d_month_seq` <= 1211)
         |            GROUP BY gen_subsumer_0.`s_state`) gen_subquery_0 ) gen_subquery_1  ON (store.`s_state` = gen_subquery_1.`s_state`)
         |        WHERE
-        |          (gen_subquery_1.`ranking` <= 5)) gen_subquery_2 
-        |      GROUP BY `s_state`, `s_county`, `spark_grouping_id`) gen_subquery_3 ) gen_subquery_4 ) gen_subquery_5 
+        |          (gen_subquery_1.`ranking` <= 5)) gen_subquery_2
+        |      GROUP BY `s_state`, `s_county`, `spark_grouping_id`) gen_subquery_3 ) gen_subquery_4 ) gen_subquery_5
         |ORDER BY gen_subquery_5.`lochierarchy` DESC NULLS LAST, CASE WHEN (CAST(gen_subquery_5.`lochierarchy` AS INT) = 0) THEN gen_subquery_5.`s_state` END ASC NULLS FIRST, gen_subquery_5.`rank_within_parent` ASC NULLS FIRST
         |LIMIT 100
        """.stripMargin.trim),
@@ -1841,9 +1857,9 @@ object TestTPCDS_1_4_Batch {
       //q12
       ("case_24",
        """
-        | select 
+        | select
         |  i_item_desc, i_item_id, i_category, i_class, i_current_price, i_brand_id, i_class_id, i_category_id,
-        |  ws_ship_customer_sk, d_year, d_qoy, d_date, 
+        |  ws_ship_customer_sk, d_year, d_qoy, d_date,
         |  sum(ws_quantity*ws_list_price) sales, count(*) number_sales,
         |  sum(ws_ext_sales_price) as itemrevenue,
         |  sum(ws_net_paid) as total_sum
@@ -1856,7 +1872,7 @@ object TestTPCDS_1_4_Batch {
         |   i_item_id, i_item_desc, i_category, i_category_id, i_class, i_current_price, i_brand_id,i_class_id,ws_ship_customer_sk,d_year,d_qoy,d_date
        """.stripMargin.trim,
        """
-        | select 
+        | select
         |  i_item_desc, i_category, i_class, i_current_price,
         |  sum(ws_ext_sales_price) as itemrevenue,
         |  sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over
@@ -1876,30 +1892,30 @@ object TestTPCDS_1_4_Batch {
         | LIMIT 100
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_1.`i_item_desc`, gen_subquery_1.`i_category`, gen_subquery_1.`i_class`, gen_subquery_1.`i_current_price`, gen_subquery_1.`itemrevenue`, ((gen_subquery_1.`_w0` * 100.00BD) / CAST(gen_subquery_1.`_we0` AS DECIMAL(28,2))) AS `revenueratio` 
+        |SELECT gen_subquery_1.`i_item_desc`, gen_subquery_1.`i_category`, gen_subquery_1.`i_class`, gen_subquery_1.`i_current_price`, gen_subquery_1.`itemrevenue`, ((gen_subquery_1.`_w0` * 100.00BD) / CAST(gen_subquery_1.`_we0` AS DECIMAL(28,2))) AS `revenueratio`
         |FROM
-        |  (SELECT gen_subquery_0.`i_item_desc`, gen_subquery_0.`i_category`, gen_subquery_0.`i_class`, gen_subquery_0.`i_current_price`, gen_subquery_0.`itemrevenue`, gen_subquery_0.`_w0`, gen_subquery_0.`_w1`, gen_subquery_0.`i_item_id`, sum(gen_subquery_0.`_w1`) OVER (PARTITION BY gen_subquery_0.`i_class` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `_we0` 
+        |  (SELECT gen_subquery_0.`i_item_desc`, gen_subquery_0.`i_category`, gen_subquery_0.`i_class`, gen_subquery_0.`i_current_price`, gen_subquery_0.`itemrevenue`, gen_subquery_0.`_w0`, gen_subquery_0.`_w1`, gen_subquery_0.`i_item_id`, sum(gen_subquery_0.`_w1`) OVER (PARTITION BY gen_subquery_0.`i_class` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `_we0`
         |  FROM
-        |    (SELECT gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`, sum(gen_subsumer_0.`itemrevenue`) AS `itemrevenue`, sum(gen_subsumer_0.`itemrevenue`) AS `_w0`, sum(gen_subsumer_0.`itemrevenue`) AS `_w1`, gen_subsumer_0.`i_item_id` 
+        |    (SELECT gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`, sum(gen_subsumer_0.`itemrevenue`) AS `itemrevenue`, sum(gen_subsumer_0.`itemrevenue`) AS `_w0`, sum(gen_subsumer_0.`itemrevenue`) AS `_w1`, gen_subsumer_0.`i_item_id`
         |    FROM
-        |      (SELECT item.`i_item_desc`, item.`i_item_id`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_brand_id`, item.`i_class_id`, item.`i_category_id`, web_sales.`ws_ship_customer_sk`, date_dim.`d_year`, date_dim.`d_qoy`, date_dim.`d_date`, sum((CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2)))) AS `sales`, count(1) AS `number_sales`, sum(web_sales.`ws_ext_sales_price`) AS `itemrevenue`, s [...]
+        |      (SELECT item.`i_item_desc`, item.`i_item_id`, item.`i_category`, item.`i_class`, item.`i_current_price`, item.`i_brand_id`, item.`i_class_id`, item.`i_category_id`, web_sales.`ws_ship_customer_sk`, date_dim.`d_year`, date_dim.`d_qoy`, date_dim.`d_date`, sum((CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2)))) AS `sales`, count(1) AS `number_sales`, sum(web_sales.`ws_ext_sales_price`) AS `itemrevenue`, s [...]
         |      FROM
         |        web_sales
         |        INNER JOIN item ON (web_sales.`ws_item_sk` = item.`i_item_sk`)
         |        INNER JOIN date_dim ON (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)
-        |      GROUP BY item.`i_item_id`, item.`i_item_desc`, item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_current_price`, item.`i_brand_id`, item.`i_class_id`, web_sales.`ws_ship_customer_sk`, date_dim.`d_year`, date_dim.`d_qoy`, date_dim.`d_date`) gen_subsumer_0 
+        |      GROUP BY item.`i_item_id`, item.`i_item_desc`, item.`i_category`, item.`i_category_id`, item.`i_class`, item.`i_current_price`, item.`i_brand_id`, item.`i_class_id`, web_sales.`ws_ship_customer_sk`, date_dim.`d_year`, date_dim.`d_qoy`, date_dim.`d_date`) gen_subsumer_0
         |    WHERE
         |      (gen_subsumer_0.`i_category` IN ('Sports', 'Books', 'Home')) AND (gen_subsumer_0.`d_date` >= DATE '1999-02-22') AND (gen_subsumer_0.`d_date` <= DATE '1999-03-24')
-        |    GROUP BY gen_subsumer_0.`i_item_id`, gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`) gen_subquery_0 ) gen_subquery_1 
+        |    GROUP BY gen_subsumer_0.`i_item_id`, gen_subsumer_0.`i_item_desc`, gen_subsumer_0.`i_category`, gen_subsumer_0.`i_class`, gen_subsumer_0.`i_current_price`) gen_subquery_0 ) gen_subquery_1
         |ORDER BY gen_subquery_1.`i_category` ASC NULLS FIRST, gen_subquery_1.`i_class` ASC NULLS FIRST, gen_subquery_1.`i_item_id` ASC NULLS FIRST, gen_subquery_1.`i_item_desc` ASC NULLS FIRST, `revenueratio` ASC NULLS FIRST
         |LIMIT 100
         """.stripMargin.trim),
       //q14a (no modular plan because EXPAND-UNION, need to fix)
       ("case_25",
        """
-        | select 
+        | select
         |  i_item_desc, i_item_id, i_category, i_class, i_current_price, i_brand_id, i_class_id, i_category_id,
-        |  ws_ship_customer_sk, d_year, d_qoy, d_date, 
+        |  ws_ship_customer_sk, d_year, d_qoy, d_date,
         |  sum(ws_quantity*ws_list_price) sales, count(*) number_sales,
         |  sum(ws_ext_sales_price) as itemrevenue,
         |  sum(ws_net_paid) as total_sum
@@ -1996,7 +2012,7 @@ object TestTPCDS_1_4_Batch {
       //q86
       ("case_26",
        """
-        | select 
+        | select
         |  i_item_desc, i_item_id, i_category, i_class, i_current_price, i_brand_id, i_class_id, i_category_id,
         |  ws_ship_customer_sk, d_year, d_qoy, d_date, d_month_seq,
         |  sum(ws_quantity*ws_list_price) sales, count(*) number_sales,
@@ -2035,9 +2051,9 @@ object TestTPCDS_1_4_Batch {
       //q58
       ("case_27",
        """
-        | select 
+        | select
         |  i_item_desc, i_item_id, i_category, i_class, i_current_price, i_brand_id, i_class_id, i_category_id,
-        |  ws_ship_customer_sk, d_week_seq, d_year, d_qoy, 
+        |  ws_ship_customer_sk, d_week_seq, d_year, d_qoy,
         |  sum(ws_quantity*ws_list_price) sales, count(*) number_sales,
         |  sum(ws_ext_sales_price) as itemrevenue,
         |  sum(ws_net_paid) as total_sum
@@ -2109,9 +2125,9 @@ object TestTPCDS_1_4_Batch {
       //q76
       ("case_28",
        """
-        | select 
+        | select
         |  i_item_desc, i_item_id, i_category, i_class, i_current_price, i_brand_id, i_class_id, i_category_id,
-        |  ws_ship_customer_sk, d_year, d_qoy, 
+        |  ws_ship_customer_sk, d_year, d_qoy,
         |  sum(ws_quantity*ws_list_price) sales, count(*) number_sales,
         |  sum(ws_ext_sales_price) as itemrevenue,
         |  sum(ws_net_paid) as total_sum
@@ -2160,7 +2176,7 @@ object TestTPCDS_1_4_Batch {
       // MV constructed from tool
       ("case_29",
        """
-        |SELECT item.`i_brand`, date_dim.`d_date`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, sum(store_sales.`ss_ext_sales_price`) AS `ext_price`, item.`i_item_id`, date_dim.`d_moy`, item.`i_item_desc`, item.`i_manager_id`, item.`i_class`, item.`i_manufact_id`, count(1) AS `cnt`, item.`i_category`, date_dim.`d_year`, item.`i_current_price`, item.`i_item_sk`, item.`i_brand_id` 
+        |SELECT item.`i_brand`, date_dim.`d_date`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, sum(store_sales.`ss_ext_sales_price`) AS `ext_price`, item.`i_item_id`, date_dim.`d_moy`, item.`i_item_desc`, item.`i_manager_id`, item.`i_class`, item.`i_manufact_id`, count(1) AS `cnt`, item.`i_category`, date_dim.`d_year`, item.`i_current_price`, item.`i_item_sk`, item.`i_brand_id`
         |FROM
         |  store_sales
         |  INNER JOIN date_dim ON (date_dim.`d_date_sk` = store_sales.`ss_sold_date_sk`)
@@ -2179,14 +2195,14 @@ object TestTPCDS_1_4_Batch {
         | LIMIT 100
         """.stripMargin.trim,
        """
-        |SELECT gen_subsumer_0.`d_year`, gen_subsumer_0.`i_brand_id` AS `brand_id`, gen_subsumer_0.`i_brand` AS `brand`, sum(gen_subsumer_0.`ext_price`) AS `sum_agg` 
+        |SELECT gen_subsumer_0.`d_year`, gen_subsumer_0.`i_brand_id` AS `brand_id`, gen_subsumer_0.`i_brand` AS `brand`, sum(gen_subsumer_0.`ext_price`) AS `sum_agg`
         |FROM
-        |  (SELECT item.`i_brand`, date_dim.`d_date`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, sum(store_sales.`ss_ext_sales_price`) AS `ext_price`, item.`i_item_id`, date_dim.`d_moy`, item.`i_item_desc`, item.`i_manager_id`, item.`i_class`, item.`i_manufact_id`, count(1) AS `cnt`, item.`i_category`, date_dim.`d_year`, item.`i_current_price`, item.`i_item_sk`, item.`i_brand_id` 
+        |  (SELECT item.`i_brand`, date_dim.`d_date`, substring(item.`i_item_desc`, 1, 30) AS `itemdesc`, sum(store_sales.`ss_ext_sales_price`) AS `ext_price`, item.`i_item_id`, date_dim.`d_moy`, item.`i_item_desc`, item.`i_manager_id`, item.`i_class`, item.`i_manufact_id`, count(1) AS `cnt`, item.`i_category`, date_dim.`d_year`, item.`i_current_price`, item.`i_item_sk`, item.`i_brand_id`
         |  FROM
         |    store_sales
         |    INNER JOIN date_dim ON (date_dim.`d_date_sk` = store_sales.`ss_sold_date_sk`)
         |    INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
-        |  GROUP BY item.`i_brand`, date_dim.`d_date`, substring(item.`i_item_desc`, 1, 30), item.`i_item_id`, date_dim.`d_moy`, item.`i_item_desc`, item.`i_manager_id`, item.`i_class`, item.`i_manufact_id`, item.`i_category`, date_dim.`d_year`, item.`i_current_price`, item.`i_item_sk`, item.`i_brand_id`) gen_subsumer_0 
+        |  GROUP BY item.`i_brand`, date_dim.`d_date`, substring(item.`i_item_desc`, 1, 30), item.`i_item_id`, date_dim.`d_moy`, item.`i_item_desc`, item.`i_manager_id`, item.`i_class`, item.`i_manufact_id`, item.`i_category`, date_dim.`d_year`, item.`i_current_price`, item.`i_item_sk`, item.`i_brand_id`) gen_subsumer_0
         |WHERE
         |  (gen_subsumer_0.`d_moy` = 11) AND (gen_subsumer_0.`i_manufact_id` = 128)
         |GROUP BY gen_subsumer_0.`d_year`, gen_subsumer_0.`i_brand`, gen_subsumer_0.`i_brand_id`
@@ -2196,12 +2212,12 @@ object TestTPCDS_1_4_Batch {
       // scalar sub-query
       ("case_30",
        """
-        |SELECT c_customer_sk,sum(ss_quantity*ss_sales_price) csales, c_customer_id, 
+        |SELECT c_customer_sk,sum(ss_quantity*ss_sales_price) csales, c_customer_id,
         |       c_first_name, c_last_name, d_year, sum(ss_net_paid) year_total
         |FROM store_sales, customer, date_dim
         |WHERE ss_customer_sk = c_customer_sk
         |      AND ss_sold_date_sk = d_date_sk
-        |GROUP BY c_customer_sk, c_customer_id, c_first_name, c_last_name, d_year 
+        |GROUP BY c_customer_sk, c_customer_id, c_first_name, c_last_name, d_year
         """.stripMargin.trim,
        """
         | with frequent_ss_items as
@@ -2246,48 +2262,48 @@ object TestTPCDS_1_4_Batch {
         | limit 100
         """.stripMargin.trim,
        """
-        |SELECT sum(gen_subquery_4.`sales`) AS `sum(sales)` 
+        |SELECT sum(gen_subquery_4.`sales`) AS `sum(sales)`
         |FROM
-        |  (SELECT (CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(catalog_sales.`cs_list_price` AS DECIMAL(12,2))) AS `sales` 
+        |  (SELECT (CAST(CAST(catalog_sales.`cs_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(catalog_sales.`cs_list_price` AS DECIMAL(12,2))) AS `sales`
         |  FROM
         |    catalog_sales
-        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)` 
+        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)`
         |    FROM
         |      store_sales
         |      INNER JOIN date_dim ON (date_dim.`d_year` IN (2000, 2001, 2002, 2003)) AND (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
         |      INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
         |    GROUP BY substring(item.`i_item_desc`, 1, 30), item.`i_item_sk`, date_dim.`d_date`) gen_subquery_0  ON (gen_subquery_0.`count(1)` > 4L) AND (catalog_sales.`cs_item_sk` = gen_subquery_0.`item_sk`)
-        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#256 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#259 as decimal(12,2)))), DecimalType(18,2)))` 
+        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#256 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#259 as decimal(12,2)))), DecimalType(18,2)))`
         |    FROM
         |      store_sales
         |      INNER JOIN customer ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |    GROUP BY customer.`c_customer_sk`) gen_subquery_1  ON (CAST(gen_subquery_1.`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#256 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#259 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_0_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum(gen_subsumer_0.`csales`) AS `csales`   FROM  (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_s [...]
         |    INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (catalog_sales.`cs_sold_date_sk` = date_dim.`d_date_sk`)
         |  UNION ALL
-        |  SELECT (CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2))) AS `sales` 
+        |  SELECT (CAST(CAST(web_sales.`ws_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(web_sales.`ws_list_price` AS DECIMAL(12,2))) AS `sales`
         |  FROM
         |    web_sales
-        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)` 
+        |    LEFT SEMI JOIN (SELECT item.`i_item_sk` AS `item_sk`, count(1) AS `count(1)`
         |    FROM
         |      store_sales
         |      INNER JOIN date_dim ON (date_dim.`d_year` IN (2000, 2001, 2002, 2003)) AND (store_sales.`ss_sold_date_sk` = date_dim.`d_date_sk`)
         |      INNER JOIN item ON (store_sales.`ss_item_sk` = item.`i_item_sk`)
         |    GROUP BY substring(item.`i_item_desc`, 1, 30), item.`i_item_sk`, date_dim.`d_date`) gen_subquery_2  ON (gen_subquery_2.`count(1)` > 4L) AND (web_sales.`ws_item_sk` = gen_subquery_2.`item_sk`)
-        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#256 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#259 as decimal(12,2)))), DecimalType(18,2)))` 
+        |    LEFT SEMI JOIN (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_sales.`ss_quantity` AS DECIMAL(10,0)) AS DECIMAL(12,2)) * CAST(store_sales.`ss_sales_price` AS DECIMAL(12,2)))) AS `sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#256 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#259 as decimal(12,2)))), DecimalType(18,2)))`
         |    FROM
         |      store_sales
         |      INNER JOIN customer ON (store_sales.`ss_customer_sk` = customer.`c_customer_sk`)
         |    GROUP BY customer.`c_customer_sk`) gen_subquery_3  ON (CAST(gen_subquery_3.`sum(CheckOverflow((promote_precision(cast(cast(ss_quantity#256 as decimal(10,0)) as decimal(12,2))) * promote_precision(cast(ss_sales_price#259 as decimal(12,2)))), DecimalType(18,2)))` AS DECIMAL(38,8)) > (0.500000BD * CAST((SELECT max(gen_expression_1_0.`csales`) AS `tpcds_cmax`   FROM  (SELECT sum(gen_subsumer_1.`csales`) AS `csales`   FROM  (SELECT customer.`c_customer_sk`, sum((CAST(CAST(store_s [...]
-        |    INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)) gen_subquery_4 
+        |    INNER JOIN date_dim ON (date_dim.`d_year` = 2000) AND (date_dim.`d_moy` = 2) AND (web_sales.`ws_sold_date_sk` = date_dim.`d_date_sk`)) gen_subquery_4
         |LIMIT 100
         """.stripMargin.trim),
       // harmonization
       ("case_31",
        """
-        |SELECT CAST(((FLOOR(((CAST(sdr_dyn_seq_custer_iot_all_hour_60min.`STARTTIME` AS DOUBLE) + 28800.0D) / 3600.0D)) * 3600L) - 28800L) AS INT) AS `a3600`, dim_apn_iot.`a12575903189`, sdr_dyn_seq_custer_iot_all_hour_60min.`DIM_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`DIM_1`, sum(1L) AS `CUSTER_IOT_GRP_USER_NUM_STREAM_C`, sdr_dyn_seq_custer_iot_all_hour_60min.`STARTTIME`, dim_apn_iot.`a12575847251`, dim_apn_iot.`a12575817396`, dim_apn_iot.`a12575873557` 
+        |SELECT CAST(((FLOOR(((CAST(sdr_dyn_seq_custer_iot_all_hour_60min.`STARTTIME` AS DOUBLE) + 28800.0D) / 3600.0D)) * 3600L) - 28800L) AS INT) AS `a3600`, dim_apn_iot.`a12575903189`, sdr_dyn_seq_custer_iot_all_hour_60min.`DIM_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`DIM_1`, sum(1L) AS `CUSTER_IOT_GRP_USER_NUM_STREAM_C`, sdr_dyn_seq_custer_iot_all_hour_60min.`STARTTIME`, dim_apn_iot.`a12575847251`, dim_apn_iot.`a12575817396`, dim_apn_iot.`a12575873557`
         |FROM
         |  sdr_dyn_seq_custer_iot_all_hour_60min
-        |  INNER JOIN (SELECT dim_apn_iot.`INDUSTRY` AS `a12575903189`, dim_apn_iot.`APN_NAME` AS `a12575817396`, dim_apn_iot.`CITY_ASCRIPTION` AS `a12575873557`, dim_apn_iot.`SERVICE_LEVEL` AS `a12575847251` 
+        |  INNER JOIN (SELECT dim_apn_iot.`INDUSTRY` AS `a12575903189`, dim_apn_iot.`APN_NAME` AS `a12575817396`, dim_apn_iot.`CITY_ASCRIPTION` AS `a12575873557`, dim_apn_iot.`SERVICE_LEVEL` AS `a12575847251`
         |  FROM
         |    dim_apn_iot
         |  WHERE
@@ -2308,7 +2324,7 @@ object TestTPCDS_1_4_Batch {
         |		,MT.a12575903189 AS a12575903189
         |		,SUM(COALESCE(CUSTER_IOT_GRP_USER_NUM_STREAM_C, 0)) AS CUSTER_IOT_GRP_USER_NUM_STREAM_CA
         |		,(
-        |			CASE 
+        |			CASE
         |				WHEN (SUM(COALESCE(CUSTER_IOT_GRP_USER_NUM_STREAM_C, 0))) > 0
         |					THEN 1
         |				ELSE 0
@@ -2399,12 +2415,12 @@ object TestTPCDS_1_4_Batch {
         |	,AT.a12575903189
         |ORDER BY START_TIME ASC
        """.stripMargin.trim,
-       """ 
+       """
        """.stripMargin.trim),
       // single table MV, latest benchmark
       ("case_32",
        """
-        |SELECT tradeflow_all.`b_country`, tradeflow_all.`y_year`, substring(tradeflow_all.`hs_code`, 1, 2) AS `hs1`, sum(CASE WHEN (tradeflow_all.`y_year` = 2016) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2016`, sum(CASE WHEN (tradeflow_all.`y_year` = 2014) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2014`, sum(CASE WHEN (tradeflow_all.`y_year` = 2015) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2015`, tradeflow_all.`country`, tradeflow_all.`imex` 
+        |SELECT tradeflow_all.`b_country`, tradeflow_all.`y_year`, substring(tradeflow_all.`hs_code`, 1, 2) AS `hs1`, sum(CASE WHEN (tradeflow_all.`y_year` = 2016) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2016`, sum(CASE WHEN (tradeflow_all.`y_year` = 2014) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2014`, sum(CASE WHEN (tradeflow_all.`y_year` = 2015) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2015`, tradeflow_all.`country`, tradeflow_all.`imex`
         |FROM
         |  tradeflow_all
         |GROUP BY tradeflow_all.`b_country`, tradeflow_all.`y_year`, substring(tradeflow_all.`hs_code`, 1, 2), tradeflow_all.`country`, tradeflow_all.`imex`
@@ -2475,34 +2491,34 @@ object TestTPCDS_1_4_Batch {
         |	OR colunm_2016 IS NOT NULL
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_3.`country_show_cn`, gen_subquery_3.`country`, gen_subquery_3.`colunm_2014`, gen_subquery_3.`colunm_2015`, gen_subquery_3.`colunm_2016`, gen_subquery_3.`tb`, gen_subquery_3.`dbupdate` 
+        |SELECT gen_subquery_3.`country_show_cn`, gen_subquery_3.`country`, gen_subquery_3.`colunm_2014`, gen_subquery_3.`colunm_2015`, gen_subquery_3.`colunm_2016`, gen_subquery_3.`tb`, gen_subquery_3.`dbupdate`
         |FROM
-        |  (SELECT gen_subquery_2.`country_show_cn`, gen_subquery_2.`country`, CASE WHEN ((up.`startdate` <= '201401') AND (up.`newdate` >= '201412')) THEN CASE WHEN isnan(gen_subquery_2.`colunm_2014`) THEN 0.0D ELSE gen_subquery_2.`colunm_2014` END ELSE CAST(NULL AS DOUBLE) END AS `colunm_2014`, CASE WHEN ((up.`startdate` <= '201501') AND (up.`newdate` >= '201512')) THEN CASE WHEN isnan(gen_subquery_2.`colunm_2015`) THEN 0.0D ELSE gen_subquery_2.`colunm_2015` END ELSE CAST(NULL AS DOUBL [...]
+        |  (SELECT gen_subquery_2.`country_show_cn`, gen_subquery_2.`country`, CASE WHEN ((up.`startdate` <= '201401') AND (up.`newdate` >= '201412')) THEN CASE WHEN isnan(gen_subquery_2.`colunm_2014`) THEN 0.0D ELSE gen_subquery_2.`colunm_2014` END ELSE CAST(NULL AS DOUBLE) END AS `colunm_2014`, CASE WHEN ((up.`startdate` <= '201501') AND (up.`newdate` >= '201512')) THEN CASE WHEN isnan(gen_subquery_2.`colunm_2015`) THEN 0.0D ELSE gen_subquery_2.`colunm_2015` END ELSE CAST(NULL AS DOUBL [...]
         |  FROM
-        |    (SELECT gen_subquery_1.`country` AS `countryid`, gen_subquery_1.`country_cn` AS `country_show_cn`, gen_subquery_1.`country_en` AS `country`, sum(gen_subquery_1.`v2014`) AS `colunm_2014`, sum(gen_subquery_1.`v2015`) AS `colunm_2015`, sum(gen_subquery_1.`v2016`) AS `colunm_2016`, ((sum(gen_subquery_1.`v2016`) - sum(gen_subquery_1.`v2015`)) / sum(gen_subquery_1.`v2015`)) AS `tb` 
+        |    (SELECT gen_subquery_1.`country` AS `countryid`, gen_subquery_1.`country_cn` AS `country_show_cn`, gen_subquery_1.`country_en` AS `country`, sum(gen_subquery_1.`v2014`) AS `colunm_2014`, sum(gen_subquery_1.`v2015`) AS `colunm_2015`, sum(gen_subquery_1.`v2016`) AS `colunm_2016`, ((sum(gen_subquery_1.`v2016`) - sum(gen_subquery_1.`v2015`)) / sum(gen_subquery_1.`v2015`)) AS `tb`
         |    FROM
-        |      (SELECT gen_subquery_0.`Country`, gen_subquery_0.`v2014`, gen_subquery_0.`v2015`, gen_subquery_0.`v2016`, `countryid`, `country_en`, `country_cn` 
+        |      (SELECT gen_subquery_0.`Country`, gen_subquery_0.`v2014`, gen_subquery_0.`v2015`, gen_subquery_0.`v2016`, `countryid`, `country_en`, `country_cn`
         |      FROM
-        |        (SELECT gen_subsumer_0.`b_country` AS `Country`, sum(gen_subsumer_0.`v2014`) AS `v2014`, sum(gen_subsumer_0.`v2015`) AS `v2015`, sum(gen_subsumer_0.`v2016`) AS `v2016` 
+        |        (SELECT gen_subsumer_0.`b_country` AS `Country`, sum(gen_subsumer_0.`v2014`) AS `v2014`, sum(gen_subsumer_0.`v2015`) AS `v2015`, sum(gen_subsumer_0.`v2016`) AS `v2016`
         |        FROM
-        |          (SELECT tradeflow_all.`b_country`, tradeflow_all.`y_year`, substring(tradeflow_all.`hs_code`, 1, 2) AS `hs1`, sum(CASE WHEN (CAST(tradeflow_all.`y_year` AS INT) = 2016) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2016`, sum(CASE WHEN (CAST(tradeflow_all.`y_year` AS INT) = 2014) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2014`, sum(CASE WHEN (CAST(tradeflow_all.`y_year` AS INT) = 2015) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2015`, tra [...]
+        |          (SELECT tradeflow_all.`b_country`, tradeflow_all.`y_year`, substring(tradeflow_all.`hs_code`, 1, 2) AS `hs1`, sum(CASE WHEN (CAST(tradeflow_all.`y_year` AS INT) = 2016) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2016`, sum(CASE WHEN (CAST(tradeflow_all.`y_year` AS INT) = 2014) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2014`, sum(CASE WHEN (CAST(tradeflow_all.`y_year` AS INT) = 2015) THEN tradeflow_all.`dollar_value` ELSE 0.0D END) AS `v2015`, tra [...]
         |          FROM
         |            tradeflow_all
-        |          GROUP BY tradeflow_all.`b_country`, tradeflow_all.`y_year`, substring(tradeflow_all.`hs_code`, 1, 2), tradeflow_all.`country`, tradeflow_all.`imex`) gen_subsumer_0 
+        |          GROUP BY tradeflow_all.`b_country`, tradeflow_all.`y_year`, substring(tradeflow_all.`hs_code`, 1, 2), tradeflow_all.`country`, tradeflow_all.`imex`) gen_subsumer_0
         |        WHERE
         |          (CAST(gen_subsumer_0.`imex` AS INT) = 0) AND (((CAST(gen_subsumer_0.`y_year` AS INT) = 2014) OR (CAST(gen_subsumer_0.`y_year` AS INT) = 2015)) OR (CAST(gen_subsumer_0.`y_year` AS INT) = 2016))
-        |        GROUP BY gen_subsumer_0.`b_country`, gen_subsumer_0.`y_year`) gen_subquery_0 
-        |        LEFT OUTER JOIN country c  ON (gen_subquery_0.`country` = c.`countryid`)) gen_subquery_1 
-        |    GROUP BY gen_subquery_1.`country_cn`, gen_subquery_1.`country`, gen_subquery_1.`countryid`, gen_subquery_1.`country_en`) gen_subquery_2 
+        |        GROUP BY gen_subsumer_0.`b_country`, gen_subsumer_0.`y_year`) gen_subquery_0
+        |        LEFT OUTER JOIN country c  ON (gen_subquery_0.`country` = c.`countryid`)) gen_subquery_1
+        |    GROUP BY gen_subquery_1.`country_cn`, gen_subquery_1.`country`, gen_subquery_1.`countryid`, gen_subquery_1.`country_en`) gen_subquery_2
         |    LEFT OUTER JOIN updatetime up  ON (CAST(up.`imex` AS INT) = 0) AND (gen_subquery_2.`countryid` = up.`countryid`) AND (((CASE WHEN ((up.`startdate` <= '201401') AND (up.`newdate` >= '201412')) THEN CASE WHEN isnan(gen_subquery_2.`colunm_2014`) THEN 0.0D ELSE gen_subquery_2.`colunm_2014` END ELSE CAST(NULL AS DOUBLE) END IS NOT NULL) OR (CASE WHEN ((up.`startdate` <= '201501') AND (up.`newdate` >= '201512')) THEN CASE WHEN isnan(gen_subquery_2.`colunm_2015`) THEN 0.0D ELSE gen [...]
         |  WHERE
-        |    (((NOT isnan(gen_subquery_2.`colunm_2014`)) OR (NOT isnan(gen_subquery_2.`colunm_2015`))) OR (NOT isnan(gen_subquery_2.`colunm_2016`))) AND (((NOT (gen_subquery_2.`colunm_2014` = 0.0D)) OR (NOT (gen_subquery_2.`colunm_2015` = 0.0D))) OR (NOT (gen_subquery_2.`colunm_2016` = 0.0D)))) gen_subquery_3 
+        |    (((NOT isnan(gen_subquery_2.`colunm_2014`)) OR (NOT isnan(gen_subquery_2.`colunm_2015`))) OR (NOT isnan(gen_subquery_2.`colunm_2016`))) AND (((NOT (gen_subquery_2.`colunm_2014` = 0.0D)) OR (NOT (gen_subquery_2.`colunm_2015` = 0.0D))) OR (NOT (gen_subquery_2.`colunm_2016` = 0.0D)))) gen_subquery_3
         |GROUP BY gen_subquery_3.`country_show_cn`, gen_subquery_3.`country`, gen_subquery_3.`colunm_2014`, gen_subquery_3.`colunm_2015`, gen_subquery_3.`colunm_2016`, gen_subquery_3.`tb`, gen_subquery_3.`dbupdate`
         """.stripMargin.trim),
       // single table MV
       ("case_33",
        """
-        |SELECT sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`DIM_10`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sum(1L) AS `sum(1)` 
+        |SELECT sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`DIM_10`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sum(1L) AS `sum(1)`
         |FROM
         |  sdr_dyn_seq_custer_iot_all_hour_60min
         |GROUP BY sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`DIM_10`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`
@@ -2520,7 +2536,7 @@ object TestTPCDS_1_4_Batch {
         |		,MT.a12575903189 AS a12575903189
         |		,SUM(COALESCE(CUSTER_IOT_GRP_USER_NUM_STREAM_C, 0)) AS CUSTER_IOT_GRP_USER_NUM_STREAM_CA
         |		,(
-        |			CASE 
+        |			CASE
         |				WHEN (SUM(COALESCE(CUSTER_IOT_GRP_USER_NUM_STREAM_C, 0))) > 0
         |					THEN 1
         |				ELSE 0
@@ -2612,32 +2628,32 @@ object TestTPCDS_1_4_Batch {
         |ORDER BY START_TIME ASC
        """.stripMargin.trim,
        """
-        |SELECT gen_subquery_4.`START_TIME`, gen_subquery_4.`USER_NUMBER`, gen_subquery_4.`CITY_ASCRIPTION`, gen_subquery_4.`SERVICE_LEVEL`, gen_subquery_4.`INDUSTRY` 
+        |SELECT gen_subquery_4.`START_TIME`, gen_subquery_4.`USER_NUMBER`, gen_subquery_4.`CITY_ASCRIPTION`, gen_subquery_4.`SERVICE_LEVEL`, gen_subquery_4.`INDUSTRY`
         |FROM
-        |  (SELECT gen_subquery_3.`a3600` AS `START_TIME`, sum(CAST(gen_subquery_3.`CUSTER_IOT_GRP_USER_NUMBER_M` AS BIGINT)) AS `USER_NUMBER`, gen_subquery_3.`a12575873557` AS `CITY_ASCRIPTION`, gen_subquery_3.`a12575847251` AS `SERVICE_LEVEL`, gen_subquery_3.`a12575903189` AS `INDUSTRY` 
+        |  (SELECT gen_subquery_3.`a3600` AS `START_TIME`, sum(CAST(gen_subquery_3.`CUSTER_IOT_GRP_USER_NUMBER_M` AS BIGINT)) AS `USER_NUMBER`, gen_subquery_3.`a12575873557` AS `CITY_ASCRIPTION`, gen_subquery_3.`a12575847251` AS `SERVICE_LEVEL`, gen_subquery_3.`a12575903189` AS `INDUSTRY`
         |  FROM
-        |    (SELECT gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557` AS `a12575873557`, gen_subquery_2.`a12575847251` AS `a12575847251`, gen_subquery_2.`a12575903189` AS `a12575903189`, CASE WHEN (sum(coalesce(gen_subquery_2.`CUSTER_IOT_GRP_USER_NUM_STREAM_C`, 0L)) > 0L) THEN 1 ELSE 0 END AS `CUSTER_IOT_GRP_USER_NUMBER_M` 
+        |    (SELECT gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557` AS `a12575873557`, gen_subquery_2.`a12575847251` AS `a12575847251`, gen_subquery_2.`a12575903189` AS `a12575903189`, CASE WHEN (sum(coalesce(gen_subquery_2.`CUSTER_IOT_GRP_USER_NUM_STREAM_C`, 0L)) > 0L) THEN 1 ELSE 0 END AS `CUSTER_IOT_GRP_USER_NUMBER_M`
         |    FROM
-        |      (SELECT CAST(((FLOOR(((CAST(gen_subquery_1.`STARTTIME` AS DOUBLE) + 28800.0D) / 3600.0D)) * 3600L) - 28800L) AS INT) AS `a3600`, sum(gen_subquery_1.`sum(1)`) AS `CUSTER_IOT_GRP_USER_NUM_STREAM_C`, gen_subquery_1.`a12575903189` AS `a12575903189`, gen_subquery_1.`DIM_52` AS `a204010101`, gen_subquery_1.`a12575873557` AS `a12575873557`, gen_subquery_1.`a12575847251` AS `a12575847251` 
+        |      (SELECT CAST(((FLOOR(((CAST(gen_subquery_1.`STARTTIME` AS DOUBLE) + 28800.0D) / 3600.0D)) * 3600L) - 28800L) AS INT) AS `a3600`, sum(gen_subquery_1.`sum(1)`) AS `CUSTER_IOT_GRP_USER_NUM_STREAM_C`, gen_subquery_1.`a12575903189` AS `a12575903189`, gen_subquery_1.`DIM_52` AS `a204010101`, gen_subquery_1.`a12575873557` AS `a12575873557`, gen_subquery_1.`a12575847251` AS `a12575847251`
         |      FROM
-        |        (SELECT gen_subquery_0.`starttime`, gen_subquery_0.`dim_52`, `a12575903189`, `a12575873557`, `a12575847251`, gen_subquery_0.`sum(1)` 
+        |        (SELECT gen_subquery_0.`starttime`, gen_subquery_0.`dim_52`, `a12575903189`, `a12575873557`, `a12575847251`, gen_subquery_0.`sum(1)`
         |        FROM
-        |          (SELECT gen_subsumer_0.`DIM_1`, gen_subsumer_0.`DIM_51`, gen_subsumer_0.`DIM_52`, gen_subsumer_0.`STARTTIME`, sum(gen_subsumer_0.`sum(1)`) AS `sum(1)` 
+        |          (SELECT gen_subsumer_0.`DIM_1`, gen_subsumer_0.`DIM_51`, gen_subsumer_0.`DIM_52`, gen_subsumer_0.`STARTTIME`, sum(gen_subsumer_0.`sum(1)`) AS `sum(1)`
         |          FROM
-        |            (SELECT sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_10`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sum(1L) AS `sum(1)` 
+        |            (SELECT sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_10`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sum(1L) AS `sum(1)`
         |            FROM
         |              sdr_dyn_seq_custer_iot_all_hour_60min
-        |            GROUP BY sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_10`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`) gen_subsumer_0 
-        |          GROUP BY gen_subsumer_0.`DIM_1`, gen_subsumer_0.`DIM_51`, gen_subsumer_0.`DIM_52`, gen_subsumer_0.`STARTTIME`) gen_subquery_0 
-        |          INNER JOIN (SELECT dim_apn_iot.`INDUSTRY` AS `a12575903189`, dim_apn_iot.`APN_NAME` AS `a12575817396`, dim_apn_iot.`CITY_ASCRIPTION` AS `a12575873557`, dim_apn_iot.`SERVICE_LEVEL` AS `a12575847251` 
+        |            GROUP BY sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_10`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`) gen_subsumer_0
+        |          GROUP BY gen_subsumer_0.`DIM_1`, gen_subsumer_0.`DIM_51`, gen_subsumer_0.`DIM_52`, gen_subsumer_0.`STARTTIME`) gen_subquery_0
+        |          INNER JOIN (SELECT dim_apn_iot.`INDUSTRY` AS `a12575903189`, dim_apn_iot.`APN_NAME` AS `a12575817396`, dim_apn_iot.`CITY_ASCRIPTION` AS `a12575873557`, dim_apn_iot.`SERVICE_LEVEL` AS `a12575847251`
         |          FROM
         |            dim_apn_iot
         |          GROUP BY dim_apn_iot.`INDUSTRY`, dim_apn_iot.`APN_NAME`, dim_apn_iot.`CITY_ASCRIPTION`, dim_apn_iot.`SERVICE_LEVEL`) D12575657700_H104  ON (gen_subquery_0.`DIM_51` = D12575657700_H104.`a12575817396`) AND (`a12575873557` IN ('金华', '丽水', '台州', '舟山', '嘉兴', '宁波', '温州', '绍兴', '湖州', '杭州', '衢州', '省直管', '外省地市', '测试')) AND (`a12575903189` IN ('公共管理', '卫生社保', '电力供应', '金融业', '软件业', '文体娱业', '居民服务', '科研技术', '交运仓储', '建筑业', '租赁服务', '制造业', '住宿餐饮', '公共服务', '批发零售', '农林牧渔')) AND (`a12575 [...]
         |        WHERE
-        |          (gen_subquery_0.`DIM_1` IN ('1', '2', '5'))) gen_subquery_1 
-        |      GROUP BY gen_subquery_1.`STARTTIME`, gen_subquery_1.`a12575903189`, gen_subquery_1.`DIM_52`, gen_subquery_1.`a12575873557`, gen_subquery_1.`a12575847251`) gen_subquery_2 
-        |    GROUP BY gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557`, gen_subquery_2.`a12575847251`, gen_subquery_2.`a12575903189`, gen_subquery_2.`a204010101`) gen_subquery_3 
-        |  GROUP BY gen_subquery_3.`a3600`, gen_subquery_3.`a12575873557`, gen_subquery_3.`a12575847251`, gen_subquery_3.`a12575903189`) gen_subquery_4 
+        |          (gen_subquery_0.`DIM_1` IN ('1', '2', '5'))) gen_subquery_1
+        |      GROUP BY gen_subquery_1.`STARTTIME`, gen_subquery_1.`a12575903189`, gen_subquery_1.`DIM_52`, gen_subquery_1.`a12575873557`, gen_subquery_1.`a12575847251`) gen_subquery_2
+        |    GROUP BY gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557`, gen_subquery_2.`a12575847251`, gen_subquery_2.`a12575903189`, gen_subquery_2.`a204010101`) gen_subquery_3
+        |  GROUP BY gen_subquery_3.`a3600`, gen_subquery_3.`a12575873557`, gen_subquery_3.`a12575847251`, gen_subquery_3.`a12575903189`) gen_subquery_4
         |ORDER BY gen_subquery_4.`START_TIME` ASC NULLS FIRST
        """.stripMargin.trim
         ),
@@ -2652,10 +2668,10 @@ object TestTPCDS_1_4_Batch {
         |FROM store_sales
         |GROUP BY ss_cdemo_sk, ss_customer_sk, ss_item_sk, ss_store_sk, ss_promo_sk
         """.stripMargin.trim,
-       """ 
-        |SELECT gen_subsumer_0.`ss_cdemo_sk`, gen_subsumer_0.`ss_customer_sk`, gen_subsumer_0.`sum(ss_net_paid)` AS `sum_paid` 
+       """
+        |SELECT gen_subsumer_0.`ss_cdemo_sk`, gen_subsumer_0.`ss_customer_sk`, gen_subsumer_0.`sum(ss_net_paid)` AS `sum_paid`
         |FROM
-        |  (SELECT store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, sum(store_sales.`ss_list_price`) AS `sum(ss_list_price)`, sum(store_sales.`ss_net_paid`) AS `sum(ss_net_paid)` 
+        |  (SELECT store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, sum(store_sales.`ss_list_price`) AS `sum(ss_list_price)`, sum(store_sales.`ss_net_paid`) AS `sum(ss_net_paid)`
         |  FROM
         |    store_sales
         |  GROUP BY store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, store_sales.`ss_store_sk`, store_sales.`ss_promo_sk`) gen_subsumer_0
@@ -2671,13 +2687,13 @@ object TestTPCDS_1_4_Batch {
         |FROM store_sales
         |GROUP BY ss_customer_sk
         """.stripMargin.trim,
-       """ 
-        |SELECT gen_subsumer_0.`ss_customer_sk`, (sum(gen_subsumer_0.`sum(ss_net_paid)`) / CAST(sum(gen_subsumer_0.`count(ss_net_paid)`) AS DECIMAL(27,2))) AS `avg_paid` 
+       """
+        |SELECT gen_subsumer_0.`ss_customer_sk`, (sum(gen_subsumer_0.`sum(ss_net_paid)`) / CAST(sum(gen_subsumer_0.`count(ss_net_paid)`) AS DECIMAL(27,2))) AS `avg_paid`
         |FROM
-        |  (SELECT store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, sum(store_sales.`ss_list_price`) AS `sum(ss_list_price)`, sum(store_sales.`ss_net_paid`) AS `sum(ss_net_paid)`, count(store_sales.`ss_net_paid`) AS `count(ss_net_paid)` 
+        |  (SELECT store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, sum(store_sales.`ss_list_price`) AS `sum(ss_list_price)`, sum(store_sales.`ss_net_paid`) AS `sum(ss_net_paid)`, count(store_sales.`ss_net_paid`) AS `count(ss_net_paid)`
         |  FROM
         |    store_sales
-        |  GROUP BY store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, store_sales.`ss_store_sk`, store_sales.`ss_promo_sk`) gen_subsumer_0 
+        |  GROUP BY store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, store_sales.`ss_store_sk`, store_sales.`ss_promo_sk`) gen_subsumer_0
         |GROUP BY gen_subsumer_0.`ss_customer_sk`
         """.stripMargin.trim),
       ("case_36",
@@ -2691,13 +2707,13 @@ object TestTPCDS_1_4_Batch {
         |FROM store_sales
         |GROUP BY ss_customer_sk
         """.stripMargin.trim,
-       """ 
-        |SELECT gen_subsumer_0.`ss_customer_sk`, (sum((gen_subsumer_0.`avg(ss_net_paid)` * CAST(sum(gen_subsumer_0.`count(ss_net_paid)`) AS DECIMAL(11,6)))) / CAST(sum(gen_subsumer_0.`count(ss_net_paid)`) AS DECIMAL(21,6))) AS `avg_paid` 
+       """
+        |SELECT gen_subsumer_0.`ss_customer_sk`, (sum((gen_subsumer_0.`avg(ss_net_paid)` * CAST(sum(gen_subsumer_0.`count(ss_net_paid)`) AS DECIMAL(11,6)))) / CAST(sum(gen_subsumer_0.`count(ss_net_paid)`) AS DECIMAL(21,6))) AS `avg_paid`
         |FROM
-        |  (SELECT store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, sum(store_sales.`ss_list_price`) AS `sum(ss_list_price)`, avg(store_sales.`ss_net_paid`) AS `avg(ss_net_paid)`, count(store_sales.`ss_net_paid`) AS `count(ss_net_paid)` 
+        |  (SELECT store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, sum(store_sales.`ss_list_price`) AS `sum(ss_list_price)`, avg(store_sales.`ss_net_paid`) AS `avg(ss_net_paid)`, count(store_sales.`ss_net_paid`) AS `count(ss_net_paid)`
         |  FROM
         |    store_sales
-        |  GROUP BY store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, store_sales.`ss_store_sk`, store_sales.`ss_promo_sk`) gen_subsumer_0 
+        |  GROUP BY store_sales.`ss_item_sk`, store_sales.`ss_customer_sk`, store_sales.`ss_cdemo_sk`, store_sales.`ss_store_sk`, store_sales.`ss_promo_sk`) gen_subsumer_0
         |GROUP BY gen_subsumer_0.`ss_customer_sk`
         """.stripMargin.trim),
       ("case_37",
@@ -2720,7 +2736,7 @@ object TestTPCDS_1_4_Batch {
         |		,MT.a12575903189 AS a12575903189
         |		,SUM(COALESCE(CUSTER_IOT_GRP_USER_NUM_STREAM_C, 0)) AS CUSTER_IOT_GRP_USER_NUM_STREAM_CA
         |		,(
-        |			CASE 
+        |			CASE
         |				WHEN (SUM(COALESCE(CUSTER_IOT_GRP_USER_NUM_STREAM_C, 0))) > 0
         |					THEN 1
         |				ELSE 0
@@ -2811,30 +2827,30 @@ object TestTPCDS_1_4_Batch {
         |	,AT.a12575903189
         |ORDER BY START_TIME ASC
         """.stripMargin.trim,
-       """ 
-        |SELECT gen_subquery_4.`START_TIME`, gen_subquery_4.`USER_NUMBER`, gen_subquery_4.`CITY_ASCRIPTION`, gen_subquery_4.`SERVICE_LEVEL`, gen_subquery_4.`INDUSTRY` 
+       """
+        |SELECT gen_subquery_4.`START_TIME`, gen_subquery_4.`USER_NUMBER`, gen_subquery_4.`CITY_ASCRIPTION`, gen_subquery_4.`SERVICE_LEVEL`, gen_subquery_4.`INDUSTRY`
         |FROM
-        |  (SELECT gen_subquery_3.`a3600` AS `START_TIME`, sum(CAST(gen_subquery_3.`CUSTER_IOT_GRP_USER_NUMBER_M` AS BIGINT)) AS `USER_NUMBER`, gen_subquery_3.`a12575873557` AS `CITY_ASCRIPTION`, gen_subquery_3.`a12575847251` AS `SERVICE_LEVEL`, gen_subquery_3.`a12575903189` AS `INDUSTRY` 
+        |  (SELECT gen_subquery_3.`a3600` AS `START_TIME`, sum(CAST(gen_subquery_3.`CUSTER_IOT_GRP_USER_NUMBER_M` AS BIGINT)) AS `USER_NUMBER`, gen_subquery_3.`a12575873557` AS `CITY_ASCRIPTION`, gen_subquery_3.`a12575847251` AS `SERVICE_LEVEL`, gen_subquery_3.`a12575903189` AS `INDUSTRY`
         |  FROM
-        |    (SELECT gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557` AS `a12575873557`, gen_subquery_2.`a12575847251` AS `a12575847251`, gen_subquery_2.`a12575903189` AS `a12575903189`, CASE WHEN (sum(coalesce(gen_subquery_2.`CUSTER_IOT_GRP_USER_NUM_STREAM_C`, 0L)) > 0L) THEN 1 ELSE 0 END AS `CUSTER_IOT_GRP_USER_NUMBER_M` 
+        |    (SELECT gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557` AS `a12575873557`, gen_subquery_2.`a12575847251` AS `a12575847251`, gen_subquery_2.`a12575903189` AS `a12575903189`, CASE WHEN (sum(coalesce(gen_subquery_2.`CUSTER_IOT_GRP_USER_NUM_STREAM_C`, 0L)) > 0L) THEN 1 ELSE 0 END AS `CUSTER_IOT_GRP_USER_NUMBER_M`
         |    FROM
-        |      (SELECT CAST(((FLOOR(((CAST(gen_subquery_1.`STARTTIME` AS DOUBLE) + 28800.0D) / 3600.0D)) * 3600L) - 28800L) AS INT) AS `a3600`, sum(gen_subquery_1.`sum(1)`) AS `CUSTER_IOT_GRP_USER_NUM_STREAM_C`, gen_subquery_1.`a12575903189` AS `a12575903189`, gen_subquery_1.`DIM_52` AS `a204010101`, gen_subquery_1.`a12575873557` AS `a12575873557`, gen_subquery_1.`a12575847251` AS `a12575847251` 
+        |      (SELECT CAST(((FLOOR(((CAST(gen_subquery_1.`STARTTIME` AS DOUBLE) + 28800.0D) / 3600.0D)) * 3600L) - 28800L) AS INT) AS `a3600`, sum(gen_subquery_1.`sum(1)`) AS `CUSTER_IOT_GRP_USER_NUM_STREAM_C`, gen_subquery_1.`a12575903189` AS `a12575903189`, gen_subquery_1.`DIM_52` AS `a204010101`, gen_subquery_1.`a12575873557` AS `a12575873557`, gen_subquery_1.`a12575847251` AS `a12575847251`
         |      FROM
-        |        (SELECT gen_subquery_0.`starttime`, gen_subquery_0.`dim_52`, `a12575903189`, `a12575873557`, `a12575847251`, gen_harmonized_default_sdr_dyn_seq_custer_iot_all_hour_60min.`sum(1)` 
+        |        (SELECT gen_subquery_0.`starttime`, gen_subquery_0.`dim_52`, `a12575903189`, `a12575873557`, `a12575847251`, gen_harmonized_default_sdr_dyn_seq_custer_iot_all_hour_60min.`sum(1)`
         |        FROM
-        |          (SELECT sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sum(1L) AS `sum(1)` 
+        |          (SELECT sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sum(1L) AS `sum(1)`
         |          FROM
         |            sdr_dyn_seq_custer_iot_all_hour_60min
-        |          GROUP BY sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`) gen_subquery_0 
-        |          INNER JOIN (SELECT dim_apn_iot.`INDUSTRY` AS `a12575903189`, dim_apn_iot.`APN_NAME` AS `a12575817396`, dim_apn_iot.`CITY_ASCRIPTION` AS `a12575873557`, dim_apn_iot.`SERVICE_LEVEL` AS `a12575847251` 
+        |          GROUP BY sdr_dyn_seq_custer_iot_all_hour_60min.`dim_1`, sdr_dyn_seq_custer_iot_all_hour_60min.`starttime`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_52`, sdr_dyn_seq_custer_iot_all_hour_60min.`dim_51`) gen_subquery_0
+        |          INNER JOIN (SELECT dim_apn_iot.`INDUSTRY` AS `a12575903189`, dim_apn_iot.`APN_NAME` AS `a12575817396`, dim_apn_iot.`CITY_ASCRIPTION` AS `a12575873557`, dim_apn_iot.`SERVICE_LEVEL` AS `a12575847251`
         |          FROM
         |            dim_apn_iot
         |          GROUP BY dim_apn_iot.`INDUSTRY`, dim_apn_iot.`APN_NAME`, dim_apn_iot.`CITY_ASCRIPTION`, dim_apn_iot.`SERVICE_LEVEL`) D12575657700_H104  ON (gen_subquery_0.`DIM_51` = D12575657700_H104.`a12575817396`) AND (`a12575873557` IN ('金华', '丽水', '台州', '舟山', '嘉兴', '宁波', '温州', '绍兴', '湖州', '杭州', '衢州', '省直管', '外省地市', '测试')) AND (`a12575903189` IN ('公共管理', '卫生社保', '电力供应', '金融业', '软件业', '文体娱业', '居民服务', '科研技术', '交运仓储', '建筑业', '租赁服务', '制造业', '住宿餐饮', '公共服务', '批发零售', '农林牧渔')) AND (`a12575 [...]
         |        WHERE
-        |          (gen_subquery_0.`DIM_1` IN ('1', '2', '5'))) gen_subquery_1 
-        |      GROUP BY gen_subquery_1.`STARTTIME`, gen_subquery_1.`a12575903189`, gen_subquery_1.`DIM_52`, gen_subquery_1.`a12575873557`, gen_subquery_1.`a12575847251`) gen_subquery_2 
-        |    GROUP BY gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557`, gen_subquery_2.`a12575847251`, gen_subquery_2.`a12575903189`, gen_subquery_2.`a204010101`) gen_subquery_3 
-        |  GROUP BY gen_subquery_3.`a3600`, gen_subquery_3.`a12575873557`, gen_subquery_3.`a12575847251`, gen_subquery_3.`a12575903189`) gen_subquery_4 
+        |          (gen_subquery_0.`DIM_1` IN ('1', '2', '5'))) gen_subquery_1
+        |      GROUP BY gen_subquery_1.`STARTTIME`, gen_subquery_1.`a12575903189`, gen_subquery_1.`DIM_52`, gen_subquery_1.`a12575873557`, gen_subquery_1.`a12575847251`) gen_subquery_2
+        |    GROUP BY gen_subquery_2.`a3600`, gen_subquery_2.`a12575873557`, gen_subquery_2.`a12575847251`, gen_subquery_2.`a12575903189`, gen_subquery_2.`a204010101`) gen_subquery_3
+        |  GROUP BY gen_subquery_3.`a3600`, gen_subquery_3.`a12575873557`, gen_subquery_3.`a12575847251`, gen_subquery_3.`a12575903189`) gen_subquery_4
         |ORDER BY gen_subquery_4.`START_TIME` ASC NULLS FIRST
         """.stripMargin.trim),
       ("case_38",
@@ -2843,7 +2859,7 @@ object TestTPCDS_1_4_Batch {
         |FROM store_sales s
         |LEFT JOIN (
         |  SELECT 1 id, i_item_id, FIRST(i_product_name) prod_name
-        |  FROM item 
+        |  FROM item
         |  GROUP BY i_item_id) p
         |ON s.ss_item_sk = p.i_item_id
         |GROUP BY p.id, p.prod_name, s.ss_ext_list_price
@@ -2853,13 +2869,13 @@ object TestTPCDS_1_4_Batch {
         |FROM store_sales s
         |LEFT JOIN (
         |  SELECT i_item_id, FIRST(i_product_name) prod_name
-        |  FROM item 
+        |  FROM item
         |  GROUP BY i_item_id) p
         |ON s.ss_item_sk = p.i_item_id
         |WHERE s.ss_ext_list_price > 20.0
         |GROUP BY p.prod_name
         """.stripMargin.trim,
-       """ 
+       """
         |
         |
         """.stripMargin.trim),
@@ -2869,7 +2885,7 @@ object TestTPCDS_1_4_Batch {
         |FROM store_sales s
         |LEFT JOIN (
         |  SELECT 1 gen_tag_id, i_item_id, FIRST(i_product_name) prod_name, FIRST(i_size) prod_size
-        |  FROM item 
+        |  FROM item
         |  GROUP BY i_item_id) p
         |ON s.ss_item_sk = p.i_item_id
         |GROUP BY p.gen_tag_id, p.prod_name, p.prod_size
@@ -2879,26 +2895,26 @@ object TestTPCDS_1_4_Batch {
         |FROM store_sales s
         |INNER JOIN (
         |  SELECT i_item_id, FIRST(i_product_name) prod_name, FIRST(i_size) prod_size
-        |  FROM item 
+        |  FROM item
         |  GROUP BY i_item_id) p
         |ON s.ss_item_sk = p.i_item_id
         |WHERE p.prod_size = 'small'
         |GROUP BY p.prod_name
         """.stripMargin.trim,
-       """ 
-        |SELECT sum(gen_subsumer_0.`sum`) AS `sum(ss_sales_price)`, gen_subsumer_0.`prod_name` 
+       """
+        |SELECT sum(gen_subsumer_0.`sum`) AS `sum(ss_sales_price)`, gen_subsumer_0.`prod_name`
         |FROM
-        |  (SELECT p.`gen_tag_id`, sum(s.`ss_sales_price`) AS `sum`, p.`prod_name`, p.`prod_size` 
+        |  (SELECT p.`gen_tag_id`, sum(s.`ss_sales_price`) AS `sum`, p.`prod_name`, p.`prod_size`
         |  FROM
-        |    store_sales s 
-        |    LEFT OUTER JOIN (SELECT 1 AS `gen_tag_id`, item.`i_item_id`, first(item.`i_product_name`, false) AS `prod_name`, first(item.`i_size`, false) AS `prod_size` 
+        |    store_sales s
+        |    LEFT OUTER JOIN (SELECT 1 AS `gen_tag_id`, item.`i_item_id`, first(item.`i_product_name`, false) AS `prod_name`, first(item.`i_size`, false) AS `prod_size`
         |    FROM
         |      item
         |    GROUP BY item.`i_item_id`) p  ON (s.`ss_item_sk` = CAST(p.`i_item_id` AS INT))
-        |  GROUP BY p.`gen_tag_id`, p.`prod_name`, p.`prod_size`) gen_subsumer_0 
+        |  GROUP BY p.`gen_tag_id`, p.`prod_name`, p.`prod_size`) gen_subsumer_0
         |WHERE
         |  (gen_subsumer_0.`prod_size` = 'small') AND (gen_subsumer_0.`gen_tag_id` IS NOT NULL)
         |GROUP BY gen_subsumer_0.`prod_name`
         """.stripMargin.trim)
   )
-}
\ No newline at end of file
+}
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/ModularPlanTest.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/ModularPlanTest.scala
similarity index 99%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/testutil/ModularPlanTest.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/testutil/ModularPlanTest.scala
index 8125241..442e3be 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/ModularPlanTest.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/ModularPlanTest.scala
@@ -15,18 +15,17 @@
  * limitations under the License.
  */
 
-package org.apache.carbondata.mv.testutil
+package org.apache.carbondata.view.testutil
 
+import org.apache.carbondata.mv.plans.modular
+import org.apache.carbondata.mv.plans.modular.Flags._
+import org.apache.carbondata.mv.plans.modular.{ModularPlan, OneRowTable, Select}
 import org.apache.spark.sql.catalyst.expressions._
 import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression
 import org.apache.spark.sql.catalyst.plans.logical._
 import org.apache.spark.sql.catalyst.util._
 import org.apache.spark.sql.test.util.QueryTest
 
-import org.apache.carbondata.mv.plans.modular
-import org.apache.carbondata.mv.plans.modular.Flags._
-import org.apache.carbondata.mv.plans.modular.{ModularPlan, OneRowTable, Select}
-
 /**
  * Provides helper methods for comparing plans.
  */
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/TestSQLBatch.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/TestSQLBatch.scala
similarity index 97%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/testutil/TestSQLBatch.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/testutil/TestSQLBatch.scala
index bb90340..a6d4709 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/TestSQLBatch.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/TestSQLBatch.scala
@@ -14,14 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package org.apache.carbondata.mv.testutil
+package org.apache.carbondata.view.testutil
 
 object TestSQLBatch {
 
   val testSQLBatch = Seq[String](
       s"""
-         |SELECT f1.A,COUNT(*) AS B 
+         |SELECT f1.A,COUNT(*) AS B
          |FROM
          |  fact f1
          |  JOIN dim d1 ON (f1.K = d1.K)
@@ -29,7 +28,7 @@ object TestSQLBatch {
          |GROUP BY f1.A
       """.stripMargin.trim,
       s"""
-         |SELECT f1.A,COUNT(*) AS B 
+         |SELECT f1.A,COUNT(*) AS B
          |FROM
          |  fact f1
          |  JOIN dim d1 ON (f1.K = d1.K)
@@ -43,10 +42,10 @@ object TestSQLBatch {
          |WHERE date_dim.d_date_sk = store_sales.ss_sold_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND date_dim.d_year in (2000, 2000+1, 2000+2, 2000+3)
-         |GROUP BY substr(item.i_item_desc,1,30), item.i_item_sk,date_dim.d_date 
+         |GROUP BY substr(item.i_item_desc,1,30), item.i_item_sk,date_dim.d_date
       """.stripMargin.trim,
       s"""
-         |SELECT item.i_item_desc, item.i_category, item.i_class, item.i_current_price, 
+         |SELECT item.i_item_desc, item.i_category, item.i_class, item.i_current_price,
          |       SUM(store_sales.ss_ext_sales_price) as itemrevenue,
          |       SUM(store_sales.ss_ext_sales_price)*100/sum(sum(store_sales.ss_ext_sales_price)) over (partition by item.i_class) as revenueratio
          |FROM date_dim, store_sales, item
@@ -54,55 +53,55 @@ object TestSQLBatch {
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND item.i_category in ('Sport', 'Books', 'Home')
          |      AND date_dim.d_date between cast('1999-02-22' as date) AND (cast('1999-02-22' as date) + interval 30 days)
-         |GROUP BY item.i_item_id, item.i_item_desc, item.i_category, item.i_class, item.i_current_price 
+         |GROUP BY item.i_item_id, item.i_item_desc, item.i_category, item.i_class, item.i_current_price
       """.stripMargin.trim,
       s"""
-         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy, 
-         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price 
+         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy,
+         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_store_sk IS NULL
          |      AND store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
-         |GROUP BY channel, store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category 
+         |GROUP BY channel, store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category
       """.stripMargin.trim,
       s"""
-         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy, 
-         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price 
+         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy,
+         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_store_sk IS NULL
          |      AND store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
-         |GROUP BY store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category 
+         |GROUP BY store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category
       """.stripMargin.trim,
       s"""
-         |SELECT item.i_brand_id brand_id, item.i_brand brand, SUM(ss_ext_sales_price) ext_price 
+         |SELECT item.i_brand_id brand_id, item.i_brand brand, SUM(ss_ext_sales_price) ext_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND item.i_manager_id = 28
          |      AND date_dim.d_year = 1999
          |      AND date_dim.d_moy = 11
-         |GROUP BY item.i_brand_id, item.i_brand 
+         |GROUP BY item.i_brand_id, item.i_brand
       """.stripMargin.trim,
       s"""
-         |SELECT item.i_brand_id brand_id, item.i_brand_id brand, SUM(ss_ext_sales_price) ext_price 
+         |SELECT item.i_brand_id brand_id, item.i_brand_id brand, SUM(ss_ext_sales_price) ext_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND item.i_manager_id = 28
          |      AND date_dim.d_year = 1999
          |      AND date_dim.d_moy = 11
-         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id 
+         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id
       """.stripMargin.trim,
       s"""
-         |SELECT 'store' channel, item.i_brand_id, item.i_class_id, item.i_category_id, 
+         |SELECT 'store' channel, item.i_brand_id, item.i_class_id, item.i_category_id,
          |       SUM(store_sales.ss_quantity*store_sales.ss_list_price) sales, count(*) number_sales
          |FROM date_dim, store_sales, item
          |WHERE date_dim.d_date_sk = store_sales.ss_sold_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND date_dim.d_year = 1999 + 2
          |      AND date_dim.d_moy = 11
-         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id 
+         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id
       """.stripMargin.trim,
       s"""
          |SELECT substr(item.i_item_desc,1,30) itemdesc, item.i_item_sk item_sk, dt.d_date solddate, count(*) cnt
@@ -581,4 +580,4 @@ object TestSQLBatch {
            |GROUP BY ROLLUP(date_dim.d_moy,date_dim.d_qoy, date_dim.d_year)
       """.stripMargin.trim
     )
-}
\ No newline at end of file
+}
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/TestSQLBatch2.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/TestSQLBatch2.scala
similarity index 91%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/testutil/TestSQLBatch2.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/testutil/TestSQLBatch2.scala
index a02cc89..ee7f7d7 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/TestSQLBatch2.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/TestSQLBatch2.scala
@@ -14,14 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package org.apache.carbondata.mv.testutil
+package org.apache.carbondata.view.testutil
 
 object TestSQLBatch2 {
 
   val testSQLBatch2 = Seq[String](
       s"""
-         |SELECT f1.A,COUNT(*) AS B 
+         |SELECT f1.A,COUNT(*) AS B
          |FROM
          |  fact f1
          |  JOIN dim d1 ON (f1.K = d1.K)
@@ -29,7 +28,7 @@ object TestSQLBatch2 {
          |GROUP BY f1.A
       """.stripMargin.trim,
       s"""
-         |SELECT f1.A,COUNT(*) AS B 
+         |SELECT f1.A,COUNT(*) AS B
          |FROM
          |  fact f1
          |  JOIN dim d1 ON (f1.K = d1.K)
@@ -43,10 +42,10 @@ object TestSQLBatch2 {
          |WHERE date_dim.d_date_sk = store_sales.ss_sold_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND date_dim.d_year in (2000, 2000+1, 2000+2, 2000+3)
-         |GROUP BY substr(item.i_item_desc,1,30), item.i_item_sk,date_dim.d_date 
+         |GROUP BY substr(item.i_item_desc,1,30), item.i_item_sk,date_dim.d_date
       """.stripMargin.trim,
       s"""
-         |SELECT item.i_item_desc, item.i_category, item.i_class, item.i_current_price, 
+         |SELECT item.i_item_desc, item.i_category, item.i_class, item.i_current_price,
          |       SUM(store_sales.ss_ext_sales_price) as itemrevenue,
          |       SUM(store_sales.ss_ext_sales_price)*100/sum(sum(store_sales.ss_ext_sales_price)) over (partition by item.i_class) as revenueratio
          |FROM date_dim, store_sales, item
@@ -54,55 +53,55 @@ object TestSQLBatch2 {
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND item.i_category in ('Sport', 'Books', 'Home')
          |      AND date_dim.d_date between cast('1999-02-22' as date) AND (cast('1999-02-22' as date) + interval 30 days)
-         |GROUP BY item.i_item_id, item.i_item_desc, item.i_category, item.i_class, item.i_current_price 
+         |GROUP BY item.i_item_id, item.i_item_desc, item.i_category, item.i_class, item.i_current_price
       """.stripMargin.trim,
       s"""
-         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy, 
-         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price 
+         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy,
+         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_store_sk IS NULL
          |      AND store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
-         |GROUP BY channel, store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category 
+         |GROUP BY channel, store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category
       """.stripMargin.trim,
       s"""
-         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy, 
-         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price 
+         |SELECT 'store' channel, store_sales.ss_store_sk col_name, date_dim.d_year, date_dim.d_qoy,
+         |       item.i_category, SUM(store_sales.ss_ext_sales_price) ext_sales_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_store_sk IS NULL
          |      AND store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
-         |GROUP BY store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category 
+         |GROUP BY store_sales.ss_store_sk, date_dim.d_year, date_dim.d_qoy, item.i_category
       """.stripMargin.trim,
       s"""
-         |SELECT item.i_brand_id brand_id, item.i_brand brand, SUM(ss_ext_sales_price) ext_price 
+         |SELECT item.i_brand_id brand_id, item.i_brand brand, SUM(ss_ext_sales_price) ext_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND item.i_manager_id = 28
          |      AND date_dim.d_year = 1999
          |      AND date_dim.d_moy = 11
-         |GROUP BY item.i_brand_id, item.i_brand 
+         |GROUP BY item.i_brand_id, item.i_brand
       """.stripMargin.trim,
       s"""
-         |SELECT item.i_brand_id brand_id, item.i_brand_id brand, SUM(ss_ext_sales_price) ext_price 
+         |SELECT item.i_brand_id brand_id, item.i_brand_id brand, SUM(ss_ext_sales_price) ext_price
          |FROM date_dim, store_sales, item
          |WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND item.i_manager_id = 28
          |      AND date_dim.d_year = 1999
          |      AND date_dim.d_moy = 11
-         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id 
+         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id
       """.stripMargin.trim,
       s"""
-         |SELECT 'store' channel, item.i_brand_id, item.i_class_id, item.i_category_id, 
+         |SELECT 'store' channel, item.i_brand_id, item.i_class_id, item.i_category_id,
          |       SUM(store_sales.ss_quantity*store_sales.ss_list_price) sales, count(*) number_sales
          |FROM date_dim, store_sales, item
          |WHERE date_dim.d_date_sk = store_sales.ss_sold_date_sk
          |      AND store_sales.ss_item_sk = item.i_item_sk
          |      AND date_dim.d_year = 1999 + 2
          |      AND date_dim.d_moy = 11
-         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id 
+         |GROUP BY item.i_brand_id, item.i_class_id,item.i_category_id
       """.stripMargin.trim,
       s"""
          |SELECT substr(item.i_item_desc,1,30) itemdesc, item.i_item_sk item_sk, dt.d_date solddate, count(*) cnt
@@ -135,4 +134,4 @@ object TestSQLBatch2 {
          |GROUP BY ROLLUP(date_dim.d_moy,date_dim.d_qoy, date_dim.d_year)
       """.stripMargin.trim
       )
-}
\ No newline at end of file
+}
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/Tpcds_1_4_QueryBatch.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/Tpcds_1_4_QueryBatch.scala
similarity index 99%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/testutil/Tpcds_1_4_QueryBatch.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/testutil/Tpcds_1_4_QueryBatch.scala
index e6c0223..67f6801 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/Tpcds_1_4_QueryBatch.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/Tpcds_1_4_QueryBatch.scala
@@ -14,8 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package org.apache.carbondata.mv.testutil
+package org.apache.carbondata.view.testutil
 
 object Tpcds_1_4_QueryBatch {
 
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/Tpcds_1_4_Tables.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/Tpcds_1_4_Tables.scala
similarity index 97%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/testutil/Tpcds_1_4_Tables.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/testutil/Tpcds_1_4_Tables.scala
index 620de29..2f58ead 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/testutil/Tpcds_1_4_Tables.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/testutil/Tpcds_1_4_Tables.scala
@@ -1,4 +1,20 @@
-package org.apache.carbondata.mv.testutil
+/*
+ * 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.view.testutil
 
 object Tpcds_1_4_Tables {
   val tpcds1_4Tables = Seq[String](
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesCarbonCreateIndexCommand.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesCarbonCreateIndexCommand.scala
similarity index 98%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesCarbonCreateIndexCommand.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesCarbonCreateIndexCommand.scala
index 7b49db3..2572066 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesCarbonCreateIndexCommand.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesCarbonCreateIndexCommand.scala
@@ -15,17 +15,16 @@
 * limitations under the License.
 */
 
-package org.apache.carbondata.mv.timeseries
+package org.apache.carbondata.view.timeseries
 
 import java.util.concurrent.{Callable, Executors, TimeUnit}
 
-import org.apache.spark.sql.test.util.QueryTest
-import org.scalatest.BeforeAndAfterAll
-
 import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.mv.rewrite.TestUtil
+import org.apache.carbondata.view.rewrite.TestUtil
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
 
 class TestMVTimeSeriesCarbonCreateIndexCommand extends QueryTest with BeforeAndAfterAll {
 
@@ -116,14 +115,14 @@ class TestMVTimeSeriesCarbonCreateIndexCommand extends QueryTest with BeforeAndA
   }
 
   test("test mv_timeseries for same event_column with different granularities") {
-    def dropMaterializedViews = {
+    def dropMVs = {
       sql("drop materialized view if exists mv1")
       sql("drop materialized view if exists mv2")
       sql("drop materialized view if exists mv3")
       sql("drop materialized view if exists mv4")
       sql("drop materialized view if exists mv5")
     }
-    dropMaterializedViews
+    dropMVs
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'second'), sum(projectcode) from maintable group by timeseries(projectjoindate,'second')")
@@ -139,7 +138,7 @@ class TestMVTimeSeriesCarbonCreateIndexCommand extends QueryTest with BeforeAndA
     sql(
       "create materialized view mv5 as " +
       "select timeseries(projectjoindate,'year'), sum(projectcode) from maintable group by timeseries(projectjoindate,'year')")
-    dropMaterializedViews
+    dropMVs
   }
 
   test("test mv_timeseries create materialized view with more event_columns") {
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesLoadAndQuery.scala
similarity index 91%
rename from mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala
rename to integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesLoadAndQuery.scala
index 03981dc..3b811150 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesLoadAndQuery.scala
@@ -15,16 +15,15 @@
 * limitations under the License.
 */
 
-package org.apache.carbondata.mv.timeseries
-
-import org.apache.spark.sql.DataFrame
-import org.apache.spark.sql.test.util.QueryTest
-import org.scalatest.BeforeAndAfterAll
+package org.apache.carbondata.view.timeseries
 
 import org.apache.carbondata.common.exceptions.sql.MalformedMVCommandException
 import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.mv.rewrite.TestUtil
+import org.apache.carbondata.view.rewrite.TestUtil
+import org.apache.spark.sql.DataFrame
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
 
 class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
 
@@ -42,7 +41,7 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     loadData("maintable")
     val df = sql("select timeseries(projectjoindate,'minute'), sum(projectcode) from maintable group by timeseries(projectjoindate,'minute')")
     assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'minute'), sum(projectcode) from maintable where timeseries(projectjoindate,'minute') = '2016-02-23 09:17:00' group by timeseries(projectjoindate,'minute')")
@@ -53,11 +52,11 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     assert(TestUtil.verifyMVHit(df1.queryExecution.optimizedPlan, "mv1"))
     val df2 = sql("select timeseries(projectjoindate,'MINUTE'), sum(projectcode) from maintable where timeseries(projectjoindate,'MINute') = '2016-02-23 09:17:00' group by timeseries(projectjoindate,'MINUTE')")
     TestUtil.verifyMVHit(df2.queryExecution.optimizedPlan, "mv1")
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mv timeseries with ctas and filter in actual query") {
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'hour'), sum(projectcode) from maintable group by timeseries(projectjoindate,'hour')")
@@ -65,16 +64,16 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     val df = sql("select timeseries(projectjoindate,'hour'), sum(projectcode) from maintable where timeseries(projectjoindate,'hour') = '2016-02-23 09:00:00' " +
                  "group by timeseries(projectjoindate,'hour')")
     assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mv timeseries with multiple granularity mvs") {
-    dropMaterializedView("mv1")
-    dropMaterializedView("mv2")
-    dropMaterializedView("mv3")
-    dropMaterializedView("mv4")
-    dropMaterializedView("mv5")
-    dropMaterializedView("mv6")
+    dropMV("mv1")
+    dropMV("mv2")
+    dropMV("mv3")
+    dropMV("mv4")
+    dropMV("mv5")
+    dropMV("mv6")
     loadData("maintable")
     sql(
       "create materialized view mv1 as " +
@@ -131,16 +130,16 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
       case Some(row) => assert(row.get(2).toString.contains("ENABLED"))
       case None => assert(false)
     }
-    dropMaterializedView("mv1")
-    dropMaterializedView("mv2")
-    dropMaterializedView("mv3")
-    dropMaterializedView("mv4")
-    dropMaterializedView("mv5")
-    dropMaterializedView("mv6")
+    dropMV("mv1")
+    dropMV("mv2")
+    dropMV("mv3")
+    dropMV("mv4")
+    dropMV("mv5")
+    dropMV("mv6")
   }
 
   test("test mv timeseries with week granular select data") {
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     loadData("maintable")
     sql(
       "create materialized view mv1 as " +
@@ -157,12 +156,12 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     val df1 = sql("select timeseries(projectjoindate,'week'), sum(salary) from maintable group by timeseries(projectjoindate,'week')")
     checkPlan("mv1", df1)
     checkExistence(df1, true, "2016-02-21 00:00:00.0" )
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test timeseries with different aggregations") {
-    dropMaterializedView("mv1")
-    dropMaterializedView("mv2")
+    dropMV("mv1")
+    dropMV("mv2")
     loadData("maintable")
     sql(
       "create materialized view mv1 as " +
@@ -174,14 +173,14 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     checkPlan("mv1", df1)
     val df2 = sql("select timeseries(projectjoindate,'day'), count(projectcode), min(salary) from maintable group by timeseries(projectjoindate,'day')")
     checkPlan("mv2", df2)
-    dropMaterializedView("mv1")
-    dropMaterializedView("mv2")
+    dropMV("mv1")
+    dropMV("mv2")
   }
 
   test("test timeseries with and and or filters") {
-    dropMaterializedView("mv1")
-    dropMaterializedView("mv2")
-    dropMaterializedView("mv3")
+    dropMV("mv1")
+    dropMV("mv2")
+    dropMV("mv3")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'month'), max(salary) from maintable where timeseries(projectjoindate,'month') = '2016-03-01 00:00:00' or  timeseries(projectjoindate,'month') = '2016-02-01 00:00:00' group by timeseries(projectjoindate,'month')")
@@ -200,13 +199,13 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
       "select timeseries(projectjoindate,'month'), max(salary) from maintable where timeseries(projectjoindate,'month') = '2016-03-01 00:00:00' and  timeseries(projectjoindate,'month') = '2016-02-01 00:00:00' or  timeseries(projectjoindate,'month') = '2016-04-01 00:00:00'  group by timeseries(projectjoindate,'month')")
     val df3 = sql("select timeseries(projectjoindate,'month'), max(salary) from maintable where timeseries(projectjoindate,'month') = '2016-03-01 00:00:00' and  timeseries(projectjoindate,'month') = '2016-02-01 00:00:00' or  timeseries(projectjoindate,'month') = '2016-04-01 00:00:00' group by timeseries(projectjoindate,'month')")
     checkPlan("mv3", df3)
-    dropMaterializedView("mv1")
-    dropMaterializedView("mv2")
-    dropMaterializedView("mv3")
+    dropMV("mv1")
+    dropMV("mv2")
+    dropMV("mv3")
   }
 
   test("test timeseries with simple projection of time aggregation and between filter") {
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     loadData("maintable")
     sql(
       "create materialized view mv1 as " +
@@ -217,11 +216,11 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     checkPlan("mv1", df2)
     val df3 = sql("select timeseries(projectjoindate,'month') from maintable where timeseries(projectjoindate,'month') between '2016-03-01 00:00:00' and '2016-04-01 00:00:00' group by timeseries(projectjoindate,'month')")
     checkPlan("mv1", df3)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mv timeseries with dictinct, cast") {
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'month'),projectcode from maintable group by timeseries(projectjoindate,'month'),projectcode")
@@ -230,18 +229,18 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     checkPlan("mv1", df1)
     val df2 = sql("select distinct(timeseries(projectjoindate,'month')) from maintable")
     checkPlan("mv1", df2)
-    // TODO: cast expression and group by not allowing to create indexSchema, check later
+    // TODO: cast expression and group by not allowing to create mv, check later
 //    sql(
 //      "create materialized view mv2 as " +
 //      "select timeseries(projectjoindate,'month'),cast(floor((projectcode + 1000) / 900) * 900 - 2000 AS INT) from maintable group by timeseries(projectjoindate,'month'),projectcode")
 //    val df3 = sql("select timeseries(projectjoindate,'month'),cast(floor((projectcode + 1000) / 900) * 900 - 2000 AS INT) from maintable group by timeseries(projectjoindate,'month'),projectcode")
 //    checkPlan("mv2", df3)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mvtimeseries with alias") {
     val result = sql("select timeseries(projectjoindate,'month'),projectcode from maintable group by timeseries(projectjoindate,'month'),projectcode")
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'month') as t,projectcode as y from maintable group by timeseries(projectjoindate,'month'),projectcode")
@@ -253,51 +252,51 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     checkAnswer(result, df2)
     val df4 = sql("select timeseries(projectjoindate,'month'),projectcode as y from maintable group by timeseries(projectjoindate,'month'),projectcode")
     checkPlan("mv1", df4)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'month'),projectcode from maintable group by timeseries(projectjoindate,'month'),projectcode")
     val df3 = sql("select timeseries(projectjoindate,'month') as t,projectcode as y from maintable group by timeseries(projectjoindate,'month'),projectcode")
     checkPlan("mv1", df3)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mv timeseries with case when and Sum + Sum") {
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'month') ,sum(CASE WHEN projectcode=5 THEN salary ELSE 0 END)  from maintable group by timeseries(projectjoindate,'month')")
     val df = sql("select timeseries(projectjoindate,'month') ,sum(CASE WHEN projectcode=5 THEN salary ELSE 0 END)  from maintable group by timeseries(projectjoindate,'month')")
     checkPlan("mv1", df)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'hour') ,sum(projectcode) + sum(salary)  from maintable group by timeseries(projectjoindate,'hour')")
     loadData("maintable")
     val df1 = sql("select timeseries(projectjoindate,'hour') ,sum(projectcode) + sum(salary)  from maintable group by timeseries(projectjoindate,'hour')")
     checkPlan("mv1", df1)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mv timeseries with IN filter subquery") {
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'hour') ,sum(projectcode)  from maintable group by timeseries(projectjoindate,'hour')")
     val df = sql("select max(salary) from maintable where projectcode IN (select sum(projectcode)  from maintable group by timeseries(projectjoindate,'hour')) ")
     checkPlan("mv1", df)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mv timeseries duplicate columns and constant columns") {
     // new optimized insert into flow doesn't support duplicate column names, so send it to old flow
     CarbonProperties.getInstance()
       .addProperty(CarbonCommonConstants.CARBON_ENABLE_BAD_RECORD_HANDLING_FOR_INSERT, "true")
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     intercept[MalformedMVCommandException] {
       sql(
         "create materialized view mv1 as " +
-        "select timeseries(projectjoindate,'month') ,sum(projectcode),sum(projectcode)  from maintable group by timeseries(projectjoindate,'month')")
+          "select timeseries(projectjoindate,'month') ,sum(projectcode),sum(projectcode)  from maintable group by timeseries(projectjoindate,'month')")
     }
     sql(
       "create materialized view mv1 as " +
@@ -307,29 +306,29 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     checkPlan("mv1", df1)
     val df2 = sql("select timeseries(projectjoindate,'month') ,sum(projectcode),sum(projectcode)  from maintable group by timeseries(projectjoindate,'month')")
     checkPlan("mv1", df2)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'month') ,sum(1) ex  from maintable group by timeseries(projectjoindate,'month')")
     val df3 = sql("select timeseries(projectjoindate,'month') ,sum(1)  ex from maintable group by timeseries(projectjoindate,'month')")
     checkPlan("mv1", df3)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     CarbonProperties.getInstance()
       .addProperty(CarbonCommonConstants.CARBON_ENABLE_BAD_RECORD_HANDLING_FOR_INSERT, "false")
   }
 
   test("test mv timeseries with like filters") {
-    dropMaterializedView("mv1")
+    dropMV("mv1")
     sql(
       "create materialized view mv1 as " +
       "select timeseries(projectjoindate,'month') ,sum(salary) from maintable  where salary NOT LIKE '6%' group by timeseries(projectjoindate,'month')")
     val df1 = sql("select timeseries(projectjoindate,'month') ,sum(salary) from maintable  where salary NOT LIKE '6%' group by timeseries(projectjoindate,'month')")
     checkPlan("mv1", df1)
-    dropMaterializedView("mv1")
+    dropMV("mv1")
   }
 
   test("test mv timeseries with join scenario") {
-    // this test case indexSchema table is created with distinct column (2 columns),
+    // this test case mv table is created with distinct column (2 columns),
     // but insert projection has duplicate column(3 columns). Cannot support in new insert into flow
     CarbonProperties.getInstance()
       .addProperty(CarbonCommonConstants.CARBON_ENABLE_BAD_RECORD_HANDLING_FOR_INSERT, "true")
@@ -373,8 +372,8 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll {
     sql("drop table if exists maintable")
   }
 
-  def dropMaterializedView(mvName: String): Unit = {
-    sql(s"drop materialized view if exists $mvName")
+  def dropMV(viewName: String): Unit = {
+    sql(s"drop materialized view if exists $viewName")
   }
 
   def createTable(): Unit = {
diff --git a/integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesQueryRollUp.scala b/integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesQueryRollUp.scala
new file mode 100644
index 0000000..0731b9f
--- /dev/null
+++ b/integration/spark/src/test/scala/org/apache/carbondata/view/timeseries/TestMVTimeSeriesQueryRollUp.scala
@@ -0,0 +1,297 @@
+  /*
+  * 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.view.timeseries
+
+import org.apache.carbondata.view.rewrite.TestUtil
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
+
+class TestMVTimeSeriesQueryRollUp extends QueryTest with BeforeAndAfterAll {
+
+  override def beforeAll(): Unit = {
+    drop()
+    createTable()
+    loadData("maintable")
+  }
+
+  override def afterAll(): Unit = {
+    drop()
+  }
+
+  test("test timeseries query rollup with simple projection") {
+    val result  = sql("select timeseries(projectjoindate,'day'),projectcode from maintable")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),projectcode from maintable")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour'),projectcode from maintable")
+    val df = sql("select timeseries(projectjoindate,'day'),projectcode from maintable")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with simple projection with group by - scenario-1") {
+    val result  = sql("select timeseries(projectjoindate,'day'),projectcode from maintable group by timeseries(projectjoindate,'day'),projectcode")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),projectcode from maintable group by timeseries(projectjoindate,'second'),projectcode")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour'),projectcode from maintable group by timeseries(projectjoindate,'hour'),projectcode")
+    var df = sql("select timeseries(projectjoindate,'day'),projectcode from maintable group by timeseries(projectjoindate,'day'),projectcode")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    df = sql("select timeseries(projectjoindate,'second'),projectcode from maintable group by timeseries(projectjoindate,'second'),projectcode")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
+    df = sql("select timeseries(projectjoindate,'second') from maintable group by timeseries(projectjoindate,'second')")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with simple projection with group by - scenario-1 with single materialized view ") {
+    val result  = sql("select timeseries(projectjoindate,'day'),projectcode from maintable group by timeseries(projectjoindate,'day'),projectcode")
+    sql("drop materialized view  if exists mv1")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),projectcode from maintable group by timeseries(projectjoindate,'second'),projectcode")
+    var df = sql("select timeseries(projectjoindate,'day'),projectcode from maintable group by timeseries(projectjoindate,'day'),projectcode")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
+    checkAnswer(result,df)
+    df = sql("select timeseries(projectjoindate,'second'),projectcode from maintable group by timeseries(projectjoindate,'second'),projectcode")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
+    df = sql("select timeseries(projectjoindate,'second') from maintable group by timeseries(projectjoindate,'second')")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
+    sql("drop materialized view  if exists mv1")
+  }
+
+  test("test timeseries query rollup with simple projection with group by - scenario-2") {
+    val result  = sql("select timeseries(projectjoindate,'day'),sum(projectcode) from maintable group by timeseries(projectjoindate,'day')")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),sum(projectcode) from maintable group by timeseries(projectjoindate,'second')")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour'),sum(projectcode) from maintable group by timeseries(projectjoindate,'hour')")
+    val df =sql("select timeseries(projectjoindate,'day'),sum(projectcode) from maintable group by timeseries(projectjoindate,'day')")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with simple projection with filter") {
+    val result  = sql("select timeseries(projectjoindate,'day'),projectcode from maintable where projectcode=8")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),projectcode from maintable")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour'),projectcode from maintable")
+    val df = sql("select timeseries(projectjoindate,'day'),projectcode from maintable where projectcode=8")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with simple projection with group by & filter - scenario 1") {
+    val result = sql("select timeseries(projectjoindate,'day'),projectcode from maintable where projectcode=8 " +
+                     "group by timeseries(projectjoindate,'day'),projectcode")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql("create materialized view  mv1  as " +
+        "select timeseries(projectjoindate,'second'),projectcode from maintable group by " +
+        "timeseries(projectjoindate,'second'),projectcode")
+    sql("create materialized view  mv2  as " +
+        "select timeseries(projectjoindate,'hour'),projectcode from maintable group by timeseries" +
+        "(projectjoindate,'hour'),projectcode")
+    val df = sql("select timeseries(projectjoindate,'day'),projectcode from maintable where projectcode=8 " +
+                 "group by timeseries(projectjoindate,'day'),projectcode")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result, df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with simple projection with group by & filter - scenario 2") {
+    val result  = sql("select timeseries(projectjoindate,'day'),projectcode from maintable where projectcode=8 group by timeseries(projectjoindate,'day'),projectcode")
+    sql("drop materialized view  if exists mv1")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),projectcode from maintable where projectcode=1 group by timeseries(projectjoindate,'second'),projectcode")
+    val df = sql("select timeseries(projectjoindate,'day'),projectcode from maintable where projectcode=8 group by timeseries(projectjoindate,'day'),projectcode")
+    assert(!TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv1"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+  }
+
+  test("test timeseries query rollup with simple projection with alias- scenario 1") {
+    val result  = sql("select timeseries(projectjoindate,'day') as a,projectcode as b from maintable")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),projectcode from maintable")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour'),projectcode from maintable")
+    val df = sql("select timeseries(projectjoindate,'day') as a,projectcode as b from maintable")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with simple projection with alias- scenario 2") {
+    val result  = sql("select timeseries(projectjoindate,'day'),projectcode from maintable")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second') as a,projectcode as b from maintable")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour') as a,projectcode as b from maintable")
+    val df = sql("select timeseries(projectjoindate,'day'),projectcode from maintable")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with projection with alias and group by- scenario 1") {
+    val result  = sql("select timeseries(projectjoindate,'day') as a,sum(projectcode) as b from maintable group by timeseries(projectjoindate,'day')")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),sum(projectcode) from maintable group by timeseries(projectjoindate,'second')")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour'),sum(projectcode) from maintable group by timeseries(projectjoindate,'hour')")
+    val df = sql("select timeseries(projectjoindate,'day') as a,sum(projectcode) as b from maintable group by timeseries(projectjoindate,'day')")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test timeseries query rollup with projection with alias and group by- scenario 2") {
+    val result  = sql("select timeseries(projectjoindate,'day'),sum(projectcode) from maintable group by timeseries(projectjoindate,'day')")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second') as a,sum(projectcode) as b from maintable group by timeseries(projectjoindate,'second')")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour') as a,sum(projectcode) as b from maintable group by timeseries(projectjoindate,'hour')")
+    val df = sql("select timeseries(projectjoindate,'day'),sum(projectcode) from maintable group by timeseries(projectjoindate,'day')")
+    assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("rollup not supported for join queries") {
+    sql("drop table if exists maintable1")
+    sql("CREATE TABLE maintable1 (empno int,empname string, projectcode int, projectjoindate " +
+      "Timestamp,salary double) STORED AS CARBONDATA")
+    loadData("maintable1")
+    val result = sql("select timeseries(t1.projectjoindate,'day'),count(timeseries(t2.projectjoindate,'day')),sum(t2.projectcode) from maintable t1 inner join maintable1 t2 " +
+        "on (timeseries(t1.projectjoindate,'day')=timeseries(t2.projectjoindate,'day')) group by timeseries(t1.projectjoindate,'day')")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql("create materialized view  mv1  as " +
+      "select timeseries(t1.projectjoindate,'second'),count(timeseries(t2.projectjoindate,'second')),sum(t2.projectcode) from maintable t1 inner join maintable1 t2 " +
+      "on (timeseries(t1.projectjoindate,'second')=timeseries(t2.projectjoindate,'second')) group by timeseries(t1.projectjoindate,'second')")
+    sql("create materialized view  mv2  as " +
+      "select timeseries(t1.projectjoindate,'hour'),count(timeseries(t2.projectjoindate,'hour')),sum(t2.projectcode) from maintable t1 inner join maintable1 t2 " +
+      "on (timeseries(t1.projectjoindate,'hour')=timeseries(t2.projectjoindate,'hour')) group by timeseries(t1.projectjoindate,'hour')")
+    val df = sql("select timeseries(t1.projectjoindate,'day'),count(timeseries(t2.projectjoindate,'day')),sum(t2.projectcode) from maintable t1 inner join maintable1 t2 " +
+        "on (timeseries(t1.projectjoindate,'day')=timeseries(t2.projectjoindate,'day')) group by timeseries(t1.projectjoindate,'day')")
+    assert(!TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("rollup not supported for timeseries udf in filter") {
+    val result  = sql("select timeseries(projectjoindate,'day'),sum(projectcode) from maintable where timeseries(projectjoindate,'day')='2016-02-23 00:00:00' group by timeseries(projectjoindate,'day')")
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+    sql(
+      "create materialized view  mv1  as " +
+      "select timeseries(projectjoindate,'second'),sum(projectcode) from maintable group by timeseries(projectjoindate,'second')")
+    sql(
+      "create materialized view  mv2  as " +
+      "select timeseries(projectjoindate,'hour'),sum(projectcode) from maintable group by timeseries(projectjoindate,'hour')")
+    val df = sql("select timeseries(projectjoindate,'day'),sum(projectcode) from maintable where timeseries(projectjoindate,'day')='2016-02-23 00:00:00' group by timeseries(projectjoindate,'day')")
+    assert(!TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "mv2"))
+    checkAnswer(result,df)
+    sql("drop materialized view  if exists mv1")
+    sql("drop materialized view  if exists mv2")
+  }
+
+  test("test rollup for timeseries column of Date type") {
+    drop()
+    sql("CREATE TABLE maintable (empno int,empname string, projectcode int, projectjoindate " +
+      "date,salary double) STORED AS CARBONDATA")
+    sql("insert into maintable select 11,'joey',2,'2016-02-23',300")
+    sql("insert into maintable select 13,'pheobe',1,'2016-02-23',450")
+    sql("insert into maintable select 22,'cathy',1,'2016-02-25',450.5")
+    sql("drop materialized view  if exists mv1")
+    val result = sql("select timeseries(projectjoindate,'week'),sum(projectcode) from maintable group by timeseries(projectjoindate,'week')")
+    sql("create materialized view  mv1  as select timeseries(projectjoindate,'day'),sum(projectcode) from maintable group by timeseries(projectjoindate,'day')")
+    val dayDF= sql("select timeseries(projectjoindate,'day'),sum(projectcode) from maintable group by timeseries(projectjoindate,'day')")
+    assert(TestUtil.verifyMVHit(dayDF.queryExecution.optimizedPlan, "mv1"))
+    val weekDF = sql("select timeseries(projectjoindate,'week'),sum(projectcode) from maintable group by timeseries(projectjoindate,'week')")
+    assert(TestUtil.verifyMVHit(weekDF.queryExecution.optimizedPlan, "mv1"))
+    checkAnswer(result, weekDF)
+    sql("drop materialized view  if exists mv1")
+    drop()
+  }
+
+  def drop(): Unit = {
+    sql("drop table if exists maintable")
+  }
+
+  def createTable(): Unit = {
+    sql(
+      "CREATE TABLE maintable (empno int,empname string, projectcode int, projectjoindate " +
+      "Timestamp,salary double) STORED AS CARBONDATA")
+  }
+
+  def loadData(table: String): Unit = {
+    sql(
+      s"""LOAD DATA local inpath '$resourcesPath/mv_sampledata.csv' INTO TABLE $table  OPTIONS
+         |('DELIMITER'= ',', 'QUOTECHAR'= '"')""".stripMargin)
+  }
+}
diff --git a/mv/core/pom.xml b/mv/core/pom.xml
deleted file mode 100644
index 877ee6c..0000000
--- a/mv/core/pom.xml
+++ /dev/null
@@ -1,243 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <parent>
-    <groupId>org.apache.carbondata</groupId>
-    <artifactId>carbondata-parent</artifactId>
-    <version>2.0.0-SNAPSHOT</version>
-    <relativePath>../../pom.xml</relativePath>
-  </parent>
-
-  <artifactId>carbondata-mv-core</artifactId>
-  <name>Apache CarbonData :: Materialized View Core</name>
-
-  <properties>
-    <dev.path>${basedir}/../../dev</dev.path>
-    <jacoco.append>true</jacoco.append>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.carbondata</groupId>
-      <artifactId>carbondata-spark</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.carbondata</groupId>
-      <artifactId>carbondata-mv-plan</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.scalatest</groupId>
-      <artifactId>scalatest_${scala.binary.version}</artifactId>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <testSourceDirectory>src/test/scala</testSourceDirectory>
-    <plugins>
-      <plugin>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <configuration>
-          <source>1.8</source>
-          <target>1.8</target>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <version>2.18</version>
-        <!-- Note config is repeated in scalatest config -->
-        <configuration>
-          <skip>false</skip>
-          <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
-          <argLine>-Xmx3g -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=512m</argLine>
-          <systemProperties>
-            <java.awt.headless>true</java.awt.headless>
-          </systemProperties>
-          <!-- testFailureIgnore>false</testFailureIgnore -->
-          <failIfNoTests>false</failIfNoTests>
-        </configuration>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-checkstyle-plugin</artifactId>
-        <version>2.17</version>
-        <configuration>
-          <skip>true</skip>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.scala-tools</groupId>
-        <artifactId>maven-scala-plugin</artifactId>
-        <version>2.15.2</version>
-        <executions>
-          <execution>
-            <id>compile</id>
-            <goals>
-              <goal>compile</goal>
-            </goals>
-            <phase>compile</phase>
-          </execution>
-          <execution>
-            <id>testCompile</id>
-            <goals>
-              <goal>testCompile</goal>
-            </goals>
-            <phase>test</phase>
-          </execution>
-          <execution>
-            <phase>process-resources</phase>
-            <goals>
-              <goal>compile</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-enforcer-plugin</artifactId>
-        <version>1.4.1</version>
-        <configuration>
-          <skip>true</skip>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>com.ning.maven.plugins</groupId>
-        <artifactId>maven-duplicate-finder-plugin</artifactId>
-        <configuration>
-          <skip>true</skip>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.scalatest</groupId>
-        <artifactId>scalatest-maven-plugin</artifactId>
-        <version>1.0</version>
-        <!-- Note config is repeated in surefire config -->
-        <configuration>
-          <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
-          <junitxml>.</junitxml>
-          <testFailureIgnore>false</testFailureIgnore>
-          <filereports>CarbonTestSuite.txt</filereports>
-          <argLine>-ea -Xmx3g -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=512m
-          </argLine>
-          <stderr/>
-          <environmentVariables>
-          </environmentVariables>
-          <systemProperties>
-            <java.awt.headless>true</java.awt.headless>
-          </systemProperties>
-        </configuration>
-        <executions>
-          <execution>
-            <id>test</id>
-            <goals>
-              <goal>test</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-  <profiles>
-    <profile>
-      <id>sdvtest</id>
-      <properties>
-        <maven.test.skip>true</maven.test.skip>
-      </properties>
-    </profile>
-    <profile>
-      <id>spark-2.3</id>
-      <activation>
-        <activeByDefault>true</activeByDefault>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <groupId>org.apache.maven.plugins</groupId>
-            <artifactId>maven-compiler-plugin</artifactId>
-            <configuration>
-              <excludes>
-                <exclude>src/main/spark2.4</exclude>
-              </excludes>
-            </configuration>
-          </plugin>
-          <plugin>
-            <groupId>org.codehaus.mojo</groupId>
-            <artifactId>build-helper-maven-plugin</artifactId>
-            <version>3.0.0</version>
-            <executions>
-              <execution>
-                <id>add-source</id>
-                <phase>generate-sources</phase>
-                <goals>
-                  <goal>add-source</goal>
-                </goals>
-                <configuration>
-                  <sources>
-                    <source>src/main/spark2.3</source>
-                  </sources>
-                </configuration>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>spark-2.4</id>
-      <build>
-        <plugins>
-          <plugin>
-            <groupId>org.apache.maven.plugins</groupId>
-            <artifactId>maven-compiler-plugin</artifactId>
-            <configuration>
-              <excludes>
-                <exclude>src/main/spark2.3</exclude>
-              </excludes>
-            </configuration>
-          </plugin>
-          <plugin>
-            <groupId>org.codehaus.mojo</groupId>
-            <artifactId>build-helper-maven-plugin</artifactId>
-            <version>3.0.0</version>
-            <executions>
-              <execution>
-                <id>add-source</id>
-                <phase>generate-sources</phase>
-                <goals>
-                  <goal>add-source</goal>
-                </goals>
-                <configuration>
-                  <sources>
-                    <source>src/main/spark2.4</source>
-                  </sources>
-                </configuration>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-  </profiles>
-</project>
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVAnalyzerRule.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVAnalyzerRule.scala
deleted file mode 100644
index d8a0ffe..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVAnalyzerRule.scala
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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.extension
-
-import scala.collection.JavaConverters._
-
-import org.apache.spark.sql.SparkSession
-import org.apache.spark.sql.catalyst.analysis.{UnresolvedAlias, UnresolvedAttribute}
-import org.apache.spark.sql.catalyst.catalog.CatalogTable
-import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute, ScalaUDF}
-import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, Command, DeserializeToObject, LogicalPlan}
-import org.apache.spark.sql.catalyst.rules.Rule
-import org.apache.spark.sql.execution.datasources.LogicalRelation
-
-import org.apache.carbondata.common.logging.LogServiceFactory
-import org.apache.carbondata.core.constants.CarbonCommonConstants
-import org.apache.carbondata.core.index.IndexStoreManager
-import org.apache.carbondata.core.metadata.schema.index.IndexClassProvider
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema
-import org.apache.carbondata.core.util.ThreadLocalSessionInfo
-import org.apache.carbondata.index.IndexManager
-import org.apache.carbondata.mv.plans.modular.{ModularPlan, Select}
-import org.apache.carbondata.mv.rewrite.{MVUdf, SummaryDataset, SummaryDatasetCatalog}
-
-/**
- * Analyzer rule to rewrite the query for MV indexSchema
- *
- * @param sparkSession
- */
-class MVAnalyzerRule(sparkSession: SparkSession) extends Rule[LogicalPlan] {
-
-  // TODO Find way better way to get the provider.
-  private val indexProvider =
-    IndexManager.get().getIndexProvider(null,
-      new IndexSchema("", IndexClassProvider.MV.getShortName), sparkSession)
-
-  private val LOGGER = LogServiceFactory.getLogService(classOf[MVAnalyzerRule].getName)
-
-  override def apply(plan: LogicalPlan): LogicalPlan = {
-    var needAnalysis = true
-    plan.transformAllExpressions {
-      // first check if any mv UDF is applied it is present is in plan
-      // then call is from create MV so no need to transform the query plan
-      // TODO Add different UDF name
-      case al@Alias(udf: ScalaUDF, name) if name.equalsIgnoreCase(MVUdf.MV_SKIP_RULE_UDF) =>
-        needAnalysis = false
-        al
-      // in case of query if any unresolve alias is present then wait for plan to be resolved
-      // return the same plan as we can tranform the plan only when everything is resolved
-      case unresolveAlias@UnresolvedAlias(_, _) =>
-        needAnalysis = false
-        unresolveAlias
-      case attr@UnresolvedAttribute(_) =>
-        needAnalysis = false
-        attr
-    }
-    plan.transform {
-      case aggregate@Aggregate(grp, aExp, child) =>
-        // check for if plan is for dataload for preaggregate table, then skip applying mv
-        val isPreAggLoad = aExp.exists { p =>
-          if (p.isInstanceOf[UnresolvedAlias]) {
-            false
-          } else {
-            p.name.equals(MVUdf.MV_SKIP_RULE_UDF)
-          }
-        }
-        if (isPreAggLoad) {
-          needAnalysis = false
-        }
-        Aggregate(grp, aExp, child)
-    }
-    if (needAnalysis) {
-      var catalog = IndexStoreManager.getInstance().getMVCatalog(indexProvider,
-        IndexClassProvider.MV.getShortName, false).asInstanceOf[SummaryDatasetCatalog]
-      // when first time MV catalog are initialized, it stores session info also,
-      // but when carbon session is newly created, catalog map will not be cleared,
-      // so if session info is different, remove the entry from map.
-      if (catalog != null && !catalog.mvSession.sparkSession.equals(sparkSession)) {
-        catalog = IndexStoreManager.getInstance().getMVCatalog(indexProvider,
-          IndexClassProvider.MV.getShortName, true).asInstanceOf[SummaryDatasetCatalog]
-      }
-      if (catalog != null && isValidPlan(plan, catalog)) {
-        val modularPlan = catalog.mvSession.sessionState.rewritePlan(plan).withMVTable
-        if (modularPlan.find(_.rewritten).isDefined) {
-          var compactSQL = modularPlan.asCompactSQL
-          compactSQL = reWriteTheUDFInSQLWithQualifierName(modularPlan, compactSQL)
-          val analyzed = sparkSession.sql(compactSQL).queryExecution.analyzed
-          analyzed
-        } else {
-          plan
-        }
-      } else {
-        plan
-      }
-    } else {
-      plan
-    }
-  }
-
-  /**
-   * This method is specially handled for timeseries on MV, because when we use timeseries UDF which
-   * is a scala UDF, so after plan matching when query is made. We get as below query for example
-   *
-   * SELECT gen_subsumer_0.`UDF:timeseries(projectjoindate, hour)` AS `UDF:timeseries(projectjoi...
-   * FROM
-   * (SELECT mv_table.`UDF:timeseries_projectjoindate_hour` AS `UDF:timeseries(projectjoin...
-   * FROM
-   *     default.mv_table
-   * GROUP BY mv_table.`UDF:timeseries_projectjoindate_hour`) gen_subsumer_0
-   * WHERE
-   * (UDF:timeseries(projectjoindate, hour) = TIMESTAMP('2016-02-23 09:00:00.0'))
-   *
-   * Here for Where filter expression is of type ScalaUDF, so when we do .sql() to prepare SQL, we
-   * get without qualifier name(Refer org.apache.spark.sql.catalyst.expressions.NonSQLExpression)
-   * which is 'gen_subsumer_0', so this function rewrites with qualifier name and returns, so that
-   * parsing does not fail in spark, for rewritten MV query.
-   * @param plan Modular Plan
-   * @param compactSQL compactSQL generated from Modular plan
-   * @return Rewritten plan with the qualifier names for where clauses in query.
-   */
-  private def reWriteTheUDFInSQLWithQualifierName(plan: ModularPlan, compactSQL: String): String = {
-    var outPutUDFColumn = ""
-    var reWrittenQuery = compactSQL
-    plan match {
-      case select: Select =>
-        select.outputList.collect {
-          case a: Alias if a.child.isInstanceOf[Attribute] =>
-            val childName = a.child.asInstanceOf[Attribute].name
-            if (childName.startsWith("UDF:timeseries")) {
-              outPutUDFColumn = childName
-            }
-        }
-        var queryArray: Array[String] = Array.empty
-        if (!outPutUDFColumn.equalsIgnoreCase("") && compactSQL.contains("WHERE")) {
-          queryArray = compactSQL.split("\n")
-          queryArray(queryArray.indexOf("WHERE") + 1) = queryArray(
-            queryArray.indexOf("WHERE") + 1).toLowerCase.replace(outPutUDFColumn.toLowerCase,
-            s"gen_subsumer_0.`$outPutUDFColumn`")
-          reWrittenQuery = queryArray.mkString("\n")
-        }
-        reWrittenQuery
-      case _ =>
-        compactSQL
-    }
-  }
-
-  /**
-   * Whether the plan is valid for doing modular plan matching and indexSchema replacing.
-   */
-  def isValidPlan(plan: LogicalPlan, catalog: SummaryDatasetCatalog): Boolean = {
-    if (!plan.isInstanceOf[Command]  && !plan.isInstanceOf[DeserializeToObject]) {
-      val catalogs = extractCatalogs(plan)
-      !isIndexReplaced(catalog.listAllValidSchema(), catalogs) &&
-      isMVExists(catalog.listAllValidSchema(), catalogs) &&
-      !isSegmentSetForMainTable(catalogs)
-    } else {
-      false
-    }
-
-  }
-  /**
-   * Check whether indexSchema table already updated in the query.
-   *
-   * @param mvdataSetArray Array of available mvdataset which include modular plans
-   * @return Boolean whether already indexSchema replaced in the plan or not
-   */
-  def isIndexReplaced(
-      mvdataSetArray: Array[SummaryDataset],
-      catalogs: Seq[Option[CatalogTable]]): Boolean = {
-    catalogs.exists { c =>
-      mvdataSetArray.exists { mv =>
-        val identifier = mv.indexSchema.getRelationIdentifier
-        identifier.getTableName.equals(c.get.identifier.table) &&
-        identifier.getDatabaseName.equals(c.get.database)
-      }
-    }
-  }
-
-  /**
-   * Check whether any suitable indexes(like index which parent tables are present in the plan)
-   * exists for this plan.
-   *
-   * @param mvs
-   * @return
-   */
-  def isMVExists(mvs: Array[SummaryDataset], catalogs: Seq[Option[CatalogTable]]): Boolean = {
-    catalogs.exists { c =>
-      mvs.exists { mv =>
-        mv.indexSchema.getParentTables.asScala.exists { identifier =>
-          identifier.getTableName.equals(c.get.identifier.table) &&
-          identifier.getDatabaseName.equals(c.get.database)
-        }
-      }
-    }
-  }
-
-  private def extractCatalogs(plan: LogicalPlan): Seq[Option[CatalogTable]] = {
-    val catalogs = plan collect {
-      case l: LogicalRelation => l.catalogTable
-    }
-    catalogs
-  }
-
-  /**
-   * Check if any segments are set for main table for Query. If any segments are set, then
-   * skip mv indexSchema table for query
-   */
-  def isSegmentSetForMainTable(catalogs: Seq[Option[CatalogTable]]): Boolean = {
-    catalogs.foreach { c =>
-      val carbonSessionInfo = ThreadLocalSessionInfo.getCarbonSessionInfo
-      if (carbonSessionInfo != null) {
-        val segmentsToQuery = carbonSessionInfo.getSessionParams
-          .getProperty(CarbonCommonConstants.CARBON_INPUT_SEGMENTS +
-                       c.get.identifier.database.get + "." +
-                       c.get.identifier.table, "")
-        if (segmentsToQuery.isEmpty || segmentsToQuery.equalsIgnoreCase("*")) {
-          return false
-        } else {
-          return true
-        }
-      } else {
-        return false
-      }
-    }
-    false
-  }
-
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVExtension.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVExtension.scala
deleted file mode 100644
index b5f81c2..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVExtension.scala
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.extension
-
-import org.apache.spark.sql.{SparkSession, SparkSessionExtensions, SQLConf}
-import org.apache.spark.sql.catalyst.parser.ParserInterface
-import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
-import org.apache.spark.sql.catalyst.rules.Rule
-
-import org.apache.carbondata.mv.rewrite.MVUdf
-import org.apache.carbondata.mv.timeseries.TimeSeriesFunction
-
-/**
- * Materialized View extension for Apache Spark
- *
- * Following SQL command are added:
- *   1. CREATE MATERIALIZED VIEW
- *   2. DROP MATERIALIZED VIEW
- *   3. SHOW MATERIALIZED VIEW
- *   4. REFRESH MATERIALIZED VIEW
- *
- * Following optimizer rules are added:
- *   1. Rewrite SQL statement by matching existing MV and
- *      select the lowest cost MV
- */
-class MVExtension extends (SparkSessionExtensions => Unit) {
-
-  override def apply(extensions: SparkSessionExtensions): Unit = {
-    // MV parser
-    extensions.injectParser(
-      (sparkSession: SparkSession, parser: ParserInterface) =>
-        new MVExtensionSqlParser(new SQLConf, sparkSession, parser))
-
-    // MV optimizer rules
-    extensions.injectPostHocResolutionRule(
-      (session: SparkSession) => MVOptimizerRule(session) )
-  }
-}
-
-case class MVOptimizerRule(session: SparkSession) extends Rule[LogicalPlan] {
-  self =>
-
-  var initialized = false
-
-  override def apply(plan: LogicalPlan): LogicalPlan = {
-    if (!initialized) {
-      self.synchronized {
-        if (!initialized) {
-          initialized = true
-
-          addMVUdf(session)
-
-          val sessionState = session.sessionState
-          val field = sessionState.getClass.getDeclaredField("optimizer")
-          field.setAccessible(true)
-          field.set(sessionState,
-            new MVOptimizer(session, sessionState.catalog, sessionState.optimizer))
-        }
-      }
-    }
-    plan
-  }
-
-  private def addMVUdf(sparkSession: SparkSession) = {
-    // added for handling MV table creation. when user will fire create ddl for
-    // create table we are adding a udf so no need to apply MV rules.
-    sparkSession.udf.register(MVUdf.MV_SKIP_RULE_UDF, () => "")
-
-    // added for handling timeseries function like hour, minute, day , month , year
-    sparkSession.udf.register("timeseries", new TimeSeriesFunction)
-  }
-}
-
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVExtensionSqlParser.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVExtensionSqlParser.scala
deleted file mode 100644
index 5b6df16..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVExtensionSqlParser.scala
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.extension
-
-import org.apache.spark.sql.{CarbonEnv, CarbonUtils, SparkSession}
-import org.apache.spark.sql.catalyst.parser.ParserInterface
-import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
-import org.apache.spark.sql.execution.SparkSqlParser
-import org.apache.spark.sql.internal.SQLConf
-import org.apache.spark.sql.util.CarbonException
-
-import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
-import org.apache.carbondata.spark.util.CarbonScalaUtil
-
-/**
- * Parser for Materialized View related command
- */
-class MVExtensionSqlParser(
-    conf: SQLConf,
-    sparkSession: SparkSession,
-    initialParser: ParserInterface
-) extends SparkSqlParser(conf) {
-
-  val parser = new MVParser
-
-  override def parsePlan(sqlText: String): LogicalPlan = {
-    parser.synchronized {
-      CarbonEnv.getInstance(sparkSession)
-    }
-    CarbonUtils.updateSessionInfoToCurrentThread(sparkSession)
-    try {
-      val plan = parser.parse(sqlText)
-      plan
-    } catch {
-      case ce: MalformedCarbonCommandException =>
-        throw ce
-      case ex: Throwable =>
-        try {
-          val parsedPlan = initialParser.parsePlan(sqlText)
-          CarbonScalaUtil.cleanParserThreadLocals
-          parsedPlan
-        } catch {
-          case mce: MalformedCarbonCommandException =>
-            throw mce
-          case e: Throwable =>
-            CarbonScalaUtil.cleanParserThreadLocals
-            CarbonException.analysisException(
-              s"""== Parser1: ${parser.getClass.getSimpleName} ==
-                 |${ex.getMessage}
-                 |== Parser2: ${initialParser.getClass.getSimpleName} ==
-                 |${e.getMessage}
-               """.stripMargin.trim)
-        }
-    }
-  }
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVHelper.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVHelper.scala
deleted file mode 100644
index 36e48d6..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVHelper.scala
+++ /dev/null
@@ -1,730 +0,0 @@
-/*
- * 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.extension
-
-import java.util
-
-import scala.collection.JavaConverters._
-import scala.collection.mutable
-
-import org.apache.spark.sql.{CarbonEnv, CarbonSource, SparkSession}
-import org.apache.spark.sql.catalyst.{CarbonParserUtil, TableIdentifier}
-import org.apache.spark.sql.catalyst.catalog.{CatalogTable, HiveTableRelation}
-import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute, AttributeReference, Cast, Coalesce, Expression, Literal, NamedExpression, ScalaUDF}
-import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression, Average}
-import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, Join, Limit, LogicalPlan, Project, Sort}
-import org.apache.spark.sql.execution.command.{Field, PartitionerField, TableModel, TableNewProcessor}
-import org.apache.spark.sql.execution.command.table.{CarbonCreateTableCommand, CarbonDropTableCommand}
-import org.apache.spark.sql.execution.datasources.LogicalRelation
-import org.apache.spark.sql.types.{ArrayType, DateType, MapType, StructType}
-
-import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
-import org.apache.carbondata.core.constants.CarbonCommonConstants
-import org.apache.carbondata.core.datastore.compression.CompressorFactory
-import org.apache.carbondata.core.datastore.impl.FileFactory
-import org.apache.carbondata.core.index.IndexStoreManager
-import org.apache.carbondata.core.metadata.datatype.DataTypes
-import org.apache.carbondata.core.metadata.schema.index.{IndexClassProvider, IndexProperty}
-import org.apache.carbondata.core.metadata.schema.table.{CarbonTable, IndexSchema, RelationIdentifier}
-import org.apache.carbondata.core.statusmanager.SegmentStatusManager
-import org.apache.carbondata.index.IndexManager
-import org.apache.carbondata.mv.plans.modular.{GroupBy, ModularPlan}
-import org.apache.carbondata.mv.plans.util.SQLBuilder
-import org.apache.carbondata.mv.rewrite.{MVUdf, SummaryDatasetCatalog}
-import org.apache.carbondata.mv.timeseries.{TimeSeriesFunction, TimeSeriesUtil}
-import org.apache.carbondata.spark.util.CommonUtil
-
-case class MVField(
-    var aggregateFunction: String = "",
-    columnTableRelationList: Seq[ColumnTableRelation]) {
-}
-
-case class ColumnTableRelation(columnName: String, tableName: String, databaseName: String)
-
-case class Relation(output: Seq[AttributeReference], catalogTable: Option[CatalogTable])
-
-/**
- * Utility for MV operations.
- */
-object MVHelper {
-
-  def createMV(
-      sparkSession: SparkSession,
-      schema: IndexSchema,
-      queryString: String,
-      ifNotExistsSet: Boolean = false): Unit = {
-    val properties = schema.getProperties.asScala
-    if (properties.contains("streaming") && properties("streaming").equalsIgnoreCase("true")) {
-      throw new MalformedCarbonCommandException(
-        s"Materialized view does not support streaming"
-      )
-    }
-    val mvUtil = new MVUtil
-    mvUtil.validateDMProperty(properties)
-    val queryPlan = dropDummyFunc(MVParser.getMVPlan(queryString, sparkSession))
-    // if there is limit in MV ctas query string, throw exception, as its not a valid usecase
-    queryPlan match {
-      case Limit(_, _) =>
-        throw new MalformedCarbonCommandException("Materialized view does not support the query " +
-                                                  "with limit")
-      case _ =>
-    }
-
-    // Order by columns needs to be present in projection list for creating mv. This is because,
-    // we have to perform order by on all segments during query, which requires the order by column
-    // data
-    queryPlan.transform {
-      case sort@Sort(order, _, _) =>
-        order.map { orderByCol =>
-          orderByCol.child match {
-            case attr: AttributeReference =>
-              if (!queryPlan.output.contains(attr.toAttribute)) {
-                throw new UnsupportedOperationException(
-                  "Order by column `" + attr.name + "` must be present in project columns")
-              }
-          }
-          order
-        }
-        sort
-    }
-
-    val mainTables = getCatalogTables(queryPlan)
-    if (mainTables.isEmpty) {
-      throw new MalformedCarbonCommandException("Non-Carbon table does not support creating MV")
-    }
-    val modularPlan = validateMVQuery(sparkSession, queryPlan)
-    val updatedQueryWithDb = modularPlan.asCompactSQL
-    val (timeSeriesColumn, granularity) = validateMVTimeSeriesQuery(queryPlan, schema)
-    val isQueryNeedFullRebuild = checkIsQueryNeedFullRebuild(queryPlan)
-    val hasNonCarbonProvider = checkMainTableHasNonCarbonSource(mainTables)
-    val isNeedFullRebuild = isQueryNeedFullRebuild || hasNonCarbonProvider
-    var counter = 0
-    // the ctas query can have duplicate columns, so we should take distinct and create fields,
-    // so that it won't fail during create mv table
-    val fields = queryPlan.output.map { attr =>
-      if (attr.dataType.isInstanceOf[ArrayType] || attr.dataType.isInstanceOf[StructType] ||
-          attr.dataType.isInstanceOf[MapType]) {
-        throw new UnsupportedOperationException(
-          s"MV is not supported for complex datatype columns and complex datatype return " +
-          s"types of function :" + attr.name)
-      }
-      val name = updateColumnName(attr, counter)
-      counter += 1
-      val rawSchema = '`' + name + '`' + ' ' + attr.dataType.typeName
-      if (attr.dataType.typeName.startsWith("decimal")) {
-        val (precision, scale) = CommonUtil.getScaleAndPrecision(attr.dataType.catalogString)
-        Field(column = name,
-          dataType = Some(attr.dataType.typeName),
-          name = Some(name),
-          children = None,
-          precision = precision,
-          scale = scale,
-          rawSchema = rawSchema)
-      } else {
-        Field(column = name,
-          dataType = Some(attr.dataType.typeName),
-          name = Some(name),
-          children = None,
-          rawSchema = rawSchema)
-      }
-    }.distinct
-
-    val tableProperties = mutable.Map[String, String]()
-    val parentTables = new util.ArrayList[String]()
-    val parentTablesList = new util.ArrayList[CarbonTable](mainTables.size)
-    mainTables.foreach { mainTable =>
-      val table = CarbonEnv.getAnyTable(
-        mainTable.identifier.database, mainTable.identifier.table)(sparkSession)
-      if (!table.getTableInfo.isTransactionalTable) {
-        throw new MalformedCarbonCommandException("Unsupported operation on NonTransactional table")
-      }
-      if (table.isChildTableForMV) {
-        throw new MalformedCarbonCommandException(
-          "Cannot create MV on child table " + table.getTableUniqueName)
-      }
-      if (table.isStreamingSink) {
-        throw new MalformedCarbonCommandException(
-        s"Streaming table does not support creating materialized view")
-      }
-      parentTables.add(table.getTableName)
-      parentTablesList.add(table)
-    }
-
-    // Check if load is in progress in any of the parent table mapped to the MV
-    parentTablesList.asScala.foreach {
-      parentTable =>
-        if (SegmentStatusManager.isLoadInProgressInTable(parentTable)) {
-          throw new UnsupportedOperationException(
-            "Cannot create MV table when insert is in progress on parent table: " +
-            parentTable.getTableName)
-        }
-    }
-
-    tableProperties.put(CarbonCommonConstants.MV_NAME, schema.getIndexName)
-    tableProperties.put(CarbonCommonConstants.PARENT_TABLES, parentTables.asScala.mkString(","))
-
-    val finalModularPlan = new SQLBuilder(modularPlan).SQLizer.execute(modularPlan)
-    val fieldRelationMap = mvUtil.getFieldsAndMVFieldsFromPlan(
-      finalModularPlan, getRelation(queryPlan))
-    // If MV is mapped to single main table, then inherit table properties from main table,
-    // else, will use default table properties. If DMProperties contains table properties, then
-    // table properties of MV table will be updated
-    if (parentTablesList.size() == 1 && CarbonSource.isCarbonDataSource(mainTables.head)) {
-      inheritTablePropertiesFromMainTable(
-        parentTablesList.get(0),
-        fields,
-        fieldRelationMap,
-        tableProperties)
-      if (granularity != null) {
-        val timeSeriesDataType = parentTablesList
-          .get(0)
-          .getTableInfo
-          .getFactTable
-          .getListOfColumns
-          .asScala
-          .filter(columnSchema => columnSchema.getColumnName
-            .equalsIgnoreCase(timeSeriesColumn))
-          .head
-          .getDataType
-        if (timeSeriesDataType.equals(DataTypes.DATE) ||
-            timeSeriesDataType.equals(DataTypes.TIMESTAMP)) {
-          // if data type is of Date type, then check if given granularity is valid for date type
-          if (timeSeriesDataType.equals(DataTypes.DATE)) {
-            TimeSeriesUtil.validateTimeSeriesGranularityForDate(granularity)
-          }
-        } else {
-          throw new MalformedCarbonCommandException(
-            "TimeSeries Column must be of TimeStamp or Date type")
-        }
-      }
-    }
-    properties.foreach(t => tableProperties.put(t._1, t._2))
-    val usePartitioning = properties.getOrElse("partitioning", "true").toBoolean
-
-    // Inherit partition from parent table if MV is mapped to single parent table
-    val partitionerFields = if (parentTablesList.size() == 1) {
-      val partitionInfo = parentTablesList.get(0).getPartitionInfo
-      val parentPartitionColumns = if (!usePartitioning) {
-        Seq.empty
-      } else if (parentTablesList.get(0).isHivePartitionTable) {
-        partitionInfo.getColumnSchemaList.asScala.map(_.getColumnName)
-      } else {
-        Seq()
-      }
-      getPartitionerFields(parentPartitionColumns, fieldRelationMap)
-    } else {
-      Seq.empty
-    }
-
-    val columnOrderMap = new java.util.HashMap[Integer, String]()
-    if (partitionerFields.nonEmpty) {
-      fields.zipWithIndex.foreach { case (field, index) =>
-        columnOrderMap.put(index, field.column)
-      }
-    }
-
-    val viewTableIdentifier = TableIdentifier(
-      schema.getIndexName + "_table", mainTables.head.identifier.database)
-
-    // prepare table model of the collected tokens
-    val viewTableModel: TableModel = CarbonParserUtil.prepareTableModel(
-      ifNotExistPresent = ifNotExistsSet,
-      CarbonParserUtil.convertDbNameToLowerCase(viewTableIdentifier.database),
-      viewTableIdentifier.table.toLowerCase,
-      fields,
-      partitionerFields,
-      tableProperties,
-      None,
-      isAlterFlow = false,
-      None)
-
-    val viewTablePath = if (properties.contains("path")) {
-      properties("path")
-    } else {
-      CarbonEnv.getTablePath(viewTableModel.databaseNameOp, viewTableModel.tableName)(sparkSession)
-    }
-    CarbonCreateTableCommand(TableNewProcessor(viewTableModel),
-      viewTableModel.ifNotExistsSet, Some(viewTablePath), isVisible = false).run(sparkSession)
-
-    // Map list of main table columns mapped to MV table
-    val mainTableToColumnsMap = new java.util.HashMap[String, util.Set[String]]()
-    val mainTableFieldIterator = fieldRelationMap.values.asJava.iterator()
-    while (mainTableFieldIterator.hasNext) {
-      val value = mainTableFieldIterator.next()
-      value.columnTableRelationList.foreach {
-        columnTableRelation =>
-          if (null == mainTableToColumnsMap.get(columnTableRelation.tableName)) {
-            val columns = new util.HashSet[String]()
-            columns.add(columnTableRelation.columnName.toLowerCase())
-            mainTableToColumnsMap.put(columnTableRelation.tableName, columns)
-          } else {
-            mainTableToColumnsMap.get(columnTableRelation.tableName)
-              .add(columnTableRelation.columnName.toLowerCase())
-          }
-      }
-    }
-    schema.setMainTableColumnList(mainTableToColumnsMap)
-    schema.setColumnsOrderMap(columnOrderMap)
-    if (null != granularity && null != timeSeriesColumn) {
-      schema.setCtasQuery(queryString)
-      schema.setTimeSeries(true)
-    } else {
-      schema.setCtasQuery(updatedQueryWithDb)
-    }
-    schema.setRelationIdentifier(
-      new RelationIdentifier(
-        viewTableIdentifier.database.get,
-        viewTableIdentifier.table,
-        CarbonEnv.getCarbonTable(viewTableIdentifier)(sparkSession).getTableId))
-
-    val parentIdents = mainTables.map { table =>
-      val relationIdentifier = new RelationIdentifier(table.database, table.identifier.table, "")
-      relationIdentifier.setTablePath(FileFactory.getUpdatedFilePath(table.location.toString))
-      relationIdentifier.setProvider(table.provider.get)
-      relationIdentifier
-    }
-    schema.getRelationIdentifier.setTablePath(viewTablePath)
-    schema.setParentTables(new util.ArrayList[RelationIdentifier](parentIdents.asJava))
-    schema.getProperties.put(IndexProperty.FULL_REFRESH, isNeedFullRebuild.toString)
-    try {
-      IndexStoreManager.getInstance().saveIndexSchema(schema)
-    } catch {
-      case ex: Exception =>
-        val dropTableCommand = CarbonDropTableCommand(
-          ifExistsSet = true,
-          new Some[String](schema.getRelationIdentifier.getDatabaseName),
-          schema.getRelationIdentifier.getTableName,
-          dropChildTable = true)
-        dropTableCommand.run(sparkSession)
-        throw ex
-    }
-  }
-
-  private def validateMVQuery(
-      sparkSession: SparkSession,
-      logicalPlan: LogicalPlan): ModularPlan = {
-    val indexProvider = IndexManager.get().getIndexProvider(null,
-      new IndexSchema("", IndexClassProvider.MV.getShortName), sparkSession)
-    var catalog = IndexStoreManager.getInstance().getMVCatalog(indexProvider,
-      IndexClassProvider.MV.getShortName, false).asInstanceOf[SummaryDatasetCatalog]
-    if (catalog == null) {
-      catalog = new SummaryDatasetCatalog(sparkSession)
-    }
-    val modularPlan =
-      catalog.mvSession.sessionState.modularizer.modularize(
-        catalog.mvSession.sessionState.optimizer.execute(logicalPlan)).next().semiHarmonized
-
-    // Only queries which can be select , predicate , join, group by and having queries.
-    if (!modularPlan.isSPJGH)  {
-      throw new UnsupportedOperationException("MV is not supported for this query")
-    }
-    val isValid = modularPlan match {
-      case g: GroupBy =>
-        // Make sure all predicates are present in projections.
-        g.predicateList.forall{p =>
-          g.outputList.exists{
-            case a: Alias =>
-              a.semanticEquals(p) || a.child.semanticEquals(p)
-            case other => other.semanticEquals(p)
-          }
-        }
-      case _ => true
-    }
-    if (!isValid) {
-      throw new UnsupportedOperationException(
-        "Group by columns must be present in project columns")
-    }
-    if (catalog.isMVWithSameQueryPresent(logicalPlan)) {
-      throw new UnsupportedOperationException("MV with same query present")
-    }
-
-    var expressionValid = true
-    modularPlan.transformExpressions {
-      case coal@Coalesce(_) if coal.children.exists(
-        exp => exp.isInstanceOf[AggregateExpression]) =>
-        expressionValid = false
-        coal
-    }
-
-    if (!expressionValid) {
-      throw new UnsupportedOperationException("MV doesn't support Coalesce")
-    }
-    modularPlan
-  }
-
-  def getUpdatedName(name: String, counter: Int): String = {
-    var updatedName = name.replace("(", "_")
-      .replace(")", "")
-      .replace(" ", "_")
-      .replace("=", "")
-      .replace(",", "")
-      .replace(".", "_")
-      .replace("`", "")
-    if (updatedName.length >= CarbonCommonConstants.MAXIMUM_CHAR_LENGTH) {
-      updatedName = updatedName.substring(0, 110) + CarbonCommonConstants.UNDERSCORE + counter
-    }
-    updatedName
-  }
-
-  private def updateColumnName(attr: Attribute, counter: Int): String = {
-    val name = getUpdatedName(attr.name, counter)
-    val value = attr.qualifier.map(qualifier => qualifier + "_" + name)
-    if (value.nonEmpty) value.last else name
-  }
-
-  // Return all relations involved in the plan
-  private def getCatalogTables(logicalPlan: LogicalPlan): Seq[CatalogTable] = {
-    logicalPlan.collect {
-      case l: LogicalRelation => l.catalogTable.get
-      case h: HiveTableRelation => h.tableMeta
-    }
-  }
-
-  private def getRelation(logicalPlan: LogicalPlan): Seq[Relation] = {
-    logicalPlan.collect {
-      case l: LogicalRelation => Relation(l.output, l.catalogTable)
-      case h: HiveTableRelation => Relation(h.output, Some(h.tableMeta))
-    }
-  }
-
-  def dropDummyFunc(plan: LogicalPlan): LogicalPlan = {
-    plan transform {
-      case p@Project(exps, child) =>
-        Project(dropDummyExp(exps), child)
-      case Aggregate(grp, aggExp, child) =>
-        Aggregate(
-          grp,
-          dropDummyExp(aggExp),
-          child)
-    }
-  }
-
-  private def dropDummyExp(exps: Seq[NamedExpression]) = {
-    exps.map {
-      case al@Alias(udf: ScalaUDF, name) if name.equalsIgnoreCase(MVUdf.MV_SKIP_RULE_UDF) =>
-        None
-      case attr: AttributeReference if attr.name.equalsIgnoreCase(MVUdf.MV_SKIP_RULE_UDF) =>
-        None
-      case other => Some(other)
-    }.filter(_.isDefined).map(_.get)
-  }
-
-  /**
-   * Return true if we can do incremental load on the mv table based on data source
-   * @param mainTables
-   * @return
-   */
-  private def checkMainTableHasNonCarbonSource(mainTables: Seq[CatalogTable]): Boolean = {
-    mainTables.exists(table => !CarbonSource.isCarbonDataSource(table))
-  }
-
-  /**
-   * Return true if we can do incremental load on the mv table based on the query plan.
-   * Some cases like aggregation functions which are present inside other expressions
-   * like sum(a)+sum(b) cannot be incremental loaded.
-   */
-  private def checkIsQueryNeedFullRebuild(logicalPlan: LogicalPlan): Boolean = {
-    var isFullReload = false
-    logicalPlan.transformAllExpressions {
-      case a: Alias => a
-      case agg: AggregateExpression =>
-        // If average function present then go for full refresh
-        var reload = agg.aggregateFunction match {
-          case avg: Average => true
-          case _ => false
-        }
-        isFullReload = reload || isFullReload
-        agg
-      case c: Cast =>
-        isFullReload = c.child.find {
-          case agg: AggregateExpression => false
-          case _ => false
-        }.isDefined || isFullReload
-        c
-      case exp: Expression =>
-        // Check any aggregation function present inside other expression.
-        isFullReload = exp.find {
-          case agg: AggregateExpression => true
-          case _ => false
-        }.isDefined || isFullReload
-        exp
-    }
-    // TODO:- Remove this case when incremental datalaoding is supported for multiple tables
-    logicalPlan.transformDown {
-      case join@Join(l1, l2, jointype, condition) =>
-        isFullReload = true
-        join
-    }
-    isFullReload
-  }
-
-  /**
-   * Validate mv timeseries query for timeseries column and granularity.
-   * TimeSeries udf function will contain data type as TimeStamp/cast as TimeStamp
-   *
-   * @param logicalPlan   to be validated
-   * @param schema to check if it is lazy/non-lazy MV
-   * @return
-   */
-  private def validateMVTimeSeriesQuery(logicalPlan: LogicalPlan,
-      schema: IndexSchema): (String, String) = {
-    var timeSeriesColumn: String = null
-    var granularity: String = null
-    logicalPlan.transformExpressions {
-      case alias@Alias(udf: ScalaUDF, _) =>
-        if (udf.function.isInstanceOf[TimeSeriesFunction]) {
-          if (null == timeSeriesColumn && null == granularity) {
-            udf.children.collect {
-              case attr: AttributeReference =>
-                timeSeriesColumn = attr.name
-              case l: Literal =>
-                granularity = l.value.toString
-              case c: Cast =>
-                c.child match {
-                  case attribute: AttributeReference =>
-                    if (attribute.dataType.isInstanceOf[DateType]) {
-                      timeSeriesColumn = attribute.name
-                    }
-                  case _ =>
-                }
-            }
-          } else {
-            udf.children.collect {
-              case attr: AttributeReference =>
-                if (!attr.name.equalsIgnoreCase(timeSeriesColumn)) {
-                  throw new MalformedCarbonCommandException(
-                    "Multiple timeseries udf functions are defined in Select statement with " +
-                    "different timestamp columns")
-                }
-              case l: Literal =>
-                if (!granularity.equalsIgnoreCase(l.value.toString)) {
-                  throw new MalformedCarbonCommandException(
-                    "Multiple timeseries udf functions are defined in Select statement with " +
-                    "different granularities")
-                }
-            }
-          }
-        }
-        alias
-    }
-    // timeseries column and granularity is not null, then validate
-    if (null != timeSeriesColumn && null != granularity) {
-      if (schema.isLazy) {
-        throw new MalformedCarbonCommandException(
-          "MV TimeSeries queries does not support Lazy Rebuild")
-      }
-      TimeSeriesUtil.validateTimeSeriesGranularity(granularity)
-    } else if (null == timeSeriesColumn && null != granularity) {
-      throw new MalformedCarbonCommandException(
-        "MV TimeSeries is only supported on Timestamp/Date column")
-    }
-    (timeSeriesColumn, granularity)
-  }
-
-  /**
-   * Used to extract PartitionerFields for MV.
-   * This method will keep generating partitionerFields until the sequence of
-   * partition column is broken.
-   *
-   * For example: if x,y,z are partition columns in main table then child tables will be
-   * partitioned only if the child table has List("x,y,z", "x,y", "x") as the projection columns.
-   *
-   */
-  private def getPartitionerFields(allPartitionColumn: Seq[String],
-      fieldRelations: mutable.LinkedHashMap[Field, MVField]): Seq[PartitionerField] = {
-
-    def generatePartitionerField(partitionColumn: List[String],
-        partitionerFields: Seq[PartitionerField]): Seq[PartitionerField] = {
-      partitionColumn match {
-        case head :: tail =>
-          // Collect the first relation which matched the condition
-          val validRelation = fieldRelations.zipWithIndex.collectFirst {
-            case ((field, mvField), index) if
-            mvField.columnTableRelationList.nonEmpty &&
-            head.equals(mvField.columnTableRelationList.head.columnName) &&
-            mvField.aggregateFunction.isEmpty =>
-              (PartitionerField(field.name.get,
-                field.dataType,
-                field.columnComment), allPartitionColumn.indexOf(head))
-          }
-          if (validRelation.isDefined) {
-            val (partitionerField, index) = validRelation.get
-            // if relation is found then check if the partitionerFields already found are equal
-            // to the index of this element.
-            // If x with index 1 is found then there should be exactly 1 element already found.
-            // If z with index 2 comes directly after x then this check will be false are 1
-            // element is skipped in between and index would be 2 and number of elements found
-            // would be 1. In that case return empty sequence so that the aggregate table is not
-            // partitioned on any column.
-            if (index == partitionerFields.length) {
-              generatePartitionerField(tail, partitionerFields :+ partitionerField)
-            } else {
-              Seq.empty
-            }
-          } else {
-            // if not found then countinue search for the rest of the elements. Because the rest
-            // of the elements can also decide if the table has to be partitioned or not.
-            generatePartitionerField(tail, partitionerFields)
-          }
-        case Nil =>
-          // if end of list then return fields.
-          partitionerFields
-      }
-    }
-
-    generatePartitionerField(allPartitionColumn.toList, Seq.empty)
-  }
-
-  private def inheritTablePropertiesFromMainTable(
-      parentTable: CarbonTable,
-      fields: Seq[Field],
-      fieldRelationMap: scala.collection.mutable.LinkedHashMap[Field, MVField],
-      tableProperties: mutable.Map[String, String]): Unit = {
-    var newOrder = Seq[String]()
-    val parentOrder = parentTable.getSortColumns.asScala
-    parentOrder.foreach(parentCol =>
-      fields.filter(col => fieldRelationMap(col).aggregateFunction.isEmpty &&
-                           fieldRelationMap(col).columnTableRelationList.size == 1 &&
-                           parentCol.equalsIgnoreCase(
-                             fieldRelationMap(col).columnTableRelationList.head.columnName))
-        .map(cols => newOrder :+= cols.column))
-    if (newOrder.nonEmpty) {
-      tableProperties.put(CarbonCommonConstants.SORT_COLUMNS, newOrder.mkString(","))
-    }
-    val sort_scope = parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-      .get("sort_scope")
-    if (sort_scope.isDefined) {
-      tableProperties.put("sort_scope", sort_scope.get)
-    }
-    tableProperties
-      .put(CarbonCommonConstants.TABLE_BLOCKSIZE, parentTable.getBlockSizeInMB.toString)
-    tableProperties.put(CarbonCommonConstants.FLAT_FOLDER,
-      parentTable.getTableInfo.getFactTable.getTableProperties.asScala.getOrElse(
-        CarbonCommonConstants.FLAT_FOLDER, CarbonCommonConstants.DEFAULT_FLAT_FOLDER))
-
-    // MV table name and columns are automatically added prefix with parent table name
-    // in carbon. For convenient, users can type column names same as the ones in select statement
-    // when config dmproperties, and here we update column names with prefix.
-    // If longStringColumn is not present in dm properties then we take long_string_columns from
-    // the parent table.
-    var longStringColumn = tableProperties.get(CarbonCommonConstants.LONG_STRING_COLUMNS)
-    if (longStringColumn.isEmpty) {
-      val longStringColumnInParents = parentTable.getTableInfo.getFactTable.getTableProperties
-        .asScala
-        .getOrElse(CarbonCommonConstants.LONG_STRING_COLUMNS, "").split(",").map(_.trim)
-      val varcharmvFields = scala.collection.mutable.ArrayBuffer.empty[String]
-      fieldRelationMap foreach (fields => {
-        val aggFunc = fields._2.aggregateFunction
-        val relationList = fields._2.columnTableRelationList
-        // check if columns present in MV are long_string_col in parent table. If they are
-        // long_string_columns in parent, make them long_string_columns in MV
-        if (aggFunc.isEmpty && relationList.size == 1 && longStringColumnInParents
-          .contains(relationList.head.columnName)) {
-          varcharmvFields += relationList.head.columnName
-        }
-      })
-      if (varcharmvFields.nonEmpty) {
-        longStringColumn = Option(varcharmvFields.mkString(","))
-      }
-    }
-
-    if (longStringColumn.isDefined) {
-      val fieldNames = fields.map(_.column)
-      val newLongStringColumn = longStringColumn.get.split(",").map(_.trim).map { colName =>
-        val newColName = parentTable.getTableName.toLowerCase() + "_" + colName
-        if (!fieldNames.contains(newColName)) {
-          throw new MalformedCarbonCommandException(
-            CarbonCommonConstants.LONG_STRING_COLUMNS.toUpperCase() + ":" + colName
-            + " does not in mv")
-        }
-        newColName
-      }
-      tableProperties.put(CarbonCommonConstants.LONG_STRING_COLUMNS,
-        newLongStringColumn.mkString(","))
-    }
-    // inherit compressor property
-    tableProperties
-      .put(CarbonCommonConstants.COMPRESSOR,
-        parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-          .getOrElse(CarbonCommonConstants.COMPRESSOR,
-            CompressorFactory.getInstance().getCompressor.getName))
-
-    // inherit the local dictionary properties of main parent table
-    tableProperties
-      .put(CarbonCommonConstants.LOCAL_DICTIONARY_ENABLE,
-        parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-          .getOrElse(CarbonCommonConstants.LOCAL_DICTIONARY_ENABLE, "false"))
-    tableProperties
-      .put(CarbonCommonConstants.LOCAL_DICTIONARY_THRESHOLD,
-        parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-          .getOrElse(CarbonCommonConstants.LOCAL_DICTIONARY_THRESHOLD,
-            CarbonCommonConstants.LOCAL_DICTIONARY_THRESHOLD_DEFAULT))
-    val parentDictInclude = parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-      .getOrElse(CarbonCommonConstants.LOCAL_DICTIONARY_INCLUDE, "").split(",")
-
-    val parentDictExclude = parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-      .getOrElse(CarbonCommonConstants.LOCAL_DICTIONARY_EXCLUDE, "").split(",")
-
-    val newLocalDictInclude = getMVColumns(parentDictInclude, fields, fieldRelationMap)
-
-    val newLocalDictExclude = getMVColumns(parentDictExclude, fields, fieldRelationMap)
-
-    if (newLocalDictInclude.nonEmpty) {
-      tableProperties
-        .put(CarbonCommonConstants.LOCAL_DICTIONARY_INCLUDE, newLocalDictInclude.mkString(","))
-    }
-    if (newLocalDictExclude.nonEmpty) {
-      tableProperties
-        .put(CarbonCommonConstants.LOCAL_DICTIONARY_EXCLUDE, newLocalDictExclude.mkString(","))
-    }
-
-    val parentInvertedIndex = parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-      .getOrElse(CarbonCommonConstants.INVERTED_INDEX, "").split(",")
-
-    val newInvertedIndex = getMVColumns(parentInvertedIndex, fields, fieldRelationMap)
-
-    val parentNoInvertedIndex = parentTable.getTableInfo.getFactTable.getTableProperties.asScala
-      .getOrElse(CarbonCommonConstants.NO_INVERTED_INDEX, "").split(",")
-
-    val newNoInvertedIndex = getMVColumns(parentNoInvertedIndex, fields, fieldRelationMap)
-
-    if (newInvertedIndex.nonEmpty) {
-      tableProperties
-        .put(CarbonCommonConstants.INVERTED_INDEX, newInvertedIndex.mkString(","))
-    }
-    if (newNoInvertedIndex.nonEmpty) {
-      tableProperties
-        .put(CarbonCommonConstants.NO_INVERTED_INDEX, newNoInvertedIndex.mkString(","))
-    }
-
-  }
-
-  private def getMVColumns(parentColumns: Array[String], fields: Seq[Field],
-      fieldRelationMap: scala.collection.mutable.LinkedHashMap[Field, MVField]) = {
-    val mvColumns = parentColumns.flatMap(parentcol =>
-      fields.collect {
-        case col if fieldRelationMap(col).aggregateFunction.isEmpty &&
-                    fieldRelationMap(col).columnTableRelationList.size == 1 &&
-                    parentcol.equalsIgnoreCase(
-                      fieldRelationMap(col).columnTableRelationList.head.columnName) =>
-          col.column
-      })
-    mvColumns
-  }
-
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVIndexProvider.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVIndexProvider.scala
deleted file mode 100644
index 3b3bc6b..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVIndexProvider.scala
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * 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.extension
-
-import java.io.IOException
-
-import scala.collection.JavaConverters._
-
-import org.apache.spark.sql.{CarbonUtils, SparkSession}
-import org.apache.spark.sql.execution.command.management.CarbonInsertIntoCommand
-import org.apache.spark.sql.execution.command.table.CarbonDropTableCommand
-
-import org.apache.carbondata.common.annotations.InterfaceAudience
-import org.apache.carbondata.common.exceptions.sql.MalformedMVCommandException
-import org.apache.carbondata.common.logging.LogServiceFactory
-import org.apache.carbondata.core.constants.CarbonCommonConstants
-import org.apache.carbondata.core.index.{CarbonIndexProvider, IndexStoreManager, MVCatalog}
-import org.apache.carbondata.core.index.dev.{Index, IndexFactory}
-import org.apache.carbondata.core.index.status.IndexStatusManager
-import org.apache.carbondata.core.indexstore.Blocklet
-import org.apache.carbondata.core.metadata.schema.index.{IndexClassProvider, IndexProperty}
-import org.apache.carbondata.core.metadata.schema.table.{CarbonTable, IndexSchema}
-import org.apache.carbondata.mv.rewrite.{SummaryDataset, SummaryDatasetCatalog}
-import org.apache.carbondata.processing.util.CarbonLoaderUtil
-
-@InterfaceAudience.Internal
-class MVIndexProvider(
-    sparkSession: SparkSession,
-    indexSchema: IndexSchema)
-  extends CarbonIndexProvider(null, indexSchema) {
-
-  protected var dropTableCommand: CarbonDropTableCommand = null
-
-  private val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
-
-  @throws[MalformedMVCommandException]
-  @throws[IOException]
-  override def initMeta(ctasSqlStatement: String): Unit = {
-    if (ctasSqlStatement == null) {
-      throw new MalformedMVCommandException(
-        "select statement is mandatory")
-    }
-    MVHelper.createMV(
-      sparkSession,
-      indexSchema,
-      ctasSqlStatement,
-      true)
-    try {
-      val catalog = IndexStoreManager.getInstance().getMVCatalog(this,
-        IndexClassProvider.MV.getShortName, false).asInstanceOf[SummaryDatasetCatalog]
-      if (catalog != null && !catalog.mvSession.sparkSession.equals(sparkSession)) {
-        IndexStoreManager.getInstance.registerMVCatalog(this, indexSchema, true)
-      } else {
-        IndexStoreManager.getInstance.registerMVCatalog(this, indexSchema, false)
-      }
-      if (indexSchema.isLazy) {
-        IndexStatusManager.disableIndex(indexSchema.getIndexName)
-      }
-    } catch {
-      case exception: Exception =>
-        dropTableCommand = new CarbonDropTableCommand(true,
-          new Some[String](indexSchema.getRelationIdentifier.getDatabaseName),
-          indexSchema.getRelationIdentifier.getTableName,
-          true)
-        dropTableCommand.run(sparkSession)
-        IndexStoreManager.getInstance().dropIndexSchema(indexSchema.getIndexName)
-        throw exception
-    }
-  }
-
-  override def initData(): Unit = {
-    if (!indexSchema.isLazy) {
-      if (rebuild()) {
-        IndexStatusManager.enableIndex(indexSchema.getIndexName)
-      }
-    }
-  }
-
-  @throws[IOException]
-  override def cleanMeta(): Unit = {
-    dropTableCommand = new CarbonDropTableCommand(true,
-      new Some[String](indexSchema.getRelationIdentifier.getDatabaseName),
-      indexSchema.getRelationIdentifier.getTableName,
-      true)
-    dropTableCommand.processMetadata(sparkSession)
-    // First, drop schema and unregister MV from catalog, because if in
-    // case, unregister fails, schema will not be deleted from system and cannot
-    // create MV also again
-    try {
-      IndexStoreManager.getInstance().dropIndexSchema(indexSchema.getIndexName)
-    } catch {
-      case e: IOException =>
-        throw e
-    } finally {
-      IndexStoreManager.getInstance.unRegisterIndex(indexSchema)
-    }
-  }
-
-  override def cleanData(): Unit = {
-    if (dropTableCommand != null) {
-      dropTableCommand.processData(sparkSession)
-    }
-  }
-
-  @throws[IOException]
-  override def rebuildInternal(newLoadName: String,
-      segmentMap: java.util.Map[String, java.util.List[String]],
-      childTable: CarbonTable): Boolean = {
-    val ctasQuery = indexSchema.getCtasQuery
-    if (ctasQuery != null) {
-      val identifier = indexSchema.getRelationIdentifier
-      val updatedQuery = MVParser.getMVQuery(ctasQuery, sparkSession)
-      var isOverwriteTable = false
-      val isFullRefresh =
-        if (null != indexSchema.getProperties.get(IndexProperty.FULL_REFRESH)) {
-          indexSchema.getProperties.get(IndexProperty.FULL_REFRESH).toBoolean
-        } else {
-          false
-        }
-      if (isFullRefresh) {
-        isOverwriteTable = true
-      }
-      // Set specified segments for incremental load
-      val segmentMapIterator = segmentMap.entrySet().iterator()
-      while (segmentMapIterator.hasNext) {
-        val entry = segmentMapIterator.next()
-        setSegmentsToLoadChildTable(entry.getKey, entry.getValue)
-      }
-      val header = childTable.getTableInfo.getFactTable.getListOfColumns.asScala
-        .filter { column =>
-          !column.getColumnName
-            .equalsIgnoreCase(CarbonCommonConstants.DEFAULT_INVISIBLE_DUMMY_MEASURE)
-        }.sortBy(_.getSchemaOrdinal).map(_.getColumnName).mkString(",")
-      val insertIntoCommand = CarbonInsertIntoCommand(
-        databaseNameOp = Some(identifier.getDatabaseName),
-        tableName = identifier.getTableName,
-        options = scala.collection.immutable.Map("fileheader" -> header),
-        isOverwriteTable,
-        logicalPlan = updatedQuery.queryExecution.analyzed,
-        tableInfo = childTable.getTableInfo,
-        internalOptions = Map("mergedSegmentName" -> newLoadName,
-          CarbonCommonConstants.IS_INTERNAL_LOAD_CALL -> "true"))
-      try {
-        insertIntoCommand.run(sparkSession)
-      } catch {
-        case ex: Exception =>
-          // If load to MV table fails, disable the MV and if newLoad is still
-          // in INSERT_IN_PROGRESS state, mark for delete the newLoad and update table status file
-          IndexStatusManager.disableIndex(indexSchema.getIndexName)
-          LOGGER.error("Data Load failed for Index: ", ex)
-          CarbonLoaderUtil.updateTableStatusInCaseOfFailure(
-            newLoadName,
-            childTable.getAbsoluteTableIdentifier,
-            childTable.getTableName,
-            childTable.getDatabaseName,
-            childTable.getTablePath,
-            childTable.getMetadataPath)
-          throw ex
-      } finally {
-        unsetMainTableSegments()
-      }
-    }
-    true
-  }
-
-  /**
-   * This method will set main table segments which needs to be loaded to the MV
-   */
-  private def setSegmentsToLoadChildTable(tableUniqueName: String,
-      mainTableSegmentList: java.util.List[String]): Unit = {
-    CarbonUtils
-      .threadSet(CarbonCommonConstants.CARBON_INPUT_SEGMENTS +
-                 tableUniqueName, mainTableSegmentList.asScala.mkString(","))
-  }
-
-  private def unsetMainTableSegments(): Unit = {
-    val relationIdentifiers = indexSchema.getParentTables.asScala
-    for (relationIdentifier <- relationIdentifiers) {
-      CarbonUtils
-        .threadUnset(CarbonCommonConstants.CARBON_INPUT_SEGMENTS +
-                     relationIdentifier.getDatabaseName + "." +
-                     relationIdentifier.getTableName)
-    }
-  }
-
-  override def createMVCatalog : MVCatalog[SummaryDataset] =
-    new SummaryDatasetCatalog(sparkSession)
-
-  override def getIndexFactory: IndexFactory[_ <: Index[_ <: Blocklet]] = {
-    throw new UnsupportedOperationException
-  }
-
-  override def supportRebuild(): Boolean = true
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVParser.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVParser.scala
deleted file mode 100644
index fad6044..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVParser.scala
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * 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.extension
-
-import scala.language.implicitConversions
-import scala.util.matching.Regex
-import scala.util.parsing.combinator.PackratParsers
-import scala.util.parsing.combinator.syntactical.StandardTokenParsers
-
-import org.apache.spark.sql.{DataFrame, SparkSession}
-import org.apache.spark.sql.catalyst.{SqlLexical, TableIdentifier}
-import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
-import org.apache.spark.sql.hive.CarbonMVRules
-import org.apache.spark.sql.util.{CarbonException, SparkSQLUtil}
-
-import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
-import org.apache.carbondata.mv.extension.command.{CreateMVCommand, DropMVCommand, RefreshMVCommand, ShowMVCommand}
-import org.apache.carbondata.mv.rewrite.MVUdf
-
-class MVParser extends StandardTokenParsers with PackratParsers {
-
-  // Keywords used in this parser
-  protected val SELECT: Regex = carbonKeyWord("SELECT")
-  protected val CREATE: Regex = carbonKeyWord("CREATE")
-  protected val MATERIALIZED: Regex = carbonKeyWord("MATERIALIZED")
-  protected val VIEW: Regex = carbonKeyWord("VIEW")
-  protected val VIEWS: Regex = carbonKeyWord("VIEWS")
-  protected val AS: Regex = carbonKeyWord("AS")
-  protected val DROP: Regex = carbonKeyWord("DROP")
-  protected val SHOW: Regex = carbonKeyWord("SHOW")
-  protected val IF: Regex = carbonKeyWord("IF")
-  protected val EXISTS: Regex = carbonKeyWord("EXISTS")
-  protected val NOT: Regex = carbonKeyWord("NOT")
-  protected val PROPERTIES: Regex = carbonKeyWord("PROPERTIES")
-  protected val WITH: Regex = carbonKeyWord("WITH")
-  protected val DEFERRED: Regex = carbonKeyWord("DEFERRED")
-  protected val REFRESH: Regex = carbonKeyWord("REFRESH")
-  protected val ON: Regex = carbonKeyWord("ON")
-  protected val TABLE: Regex = carbonKeyWord("TABLE")
-
-  /**
-   * This will convert key word to regular expression.
-   */
-  private def carbonKeyWord(keys: String): Regex = {
-    ("(?i)" + keys).r
-  }
-
-  implicit def regexToParser(regex: Regex): Parser[String] = {
-    import lexical.Identifier
-    acceptMatch(
-      s"identifier matching regex ${ regex }",
-      { case Identifier(str) if regex.unapplySeq(str).isDefined => str }
-    )
-  }
-
-  // By default, use Reflection to find the reserved words defined in the sub class.
-  // NOTICE, Since the Keyword properties defined by sub class, we couldn't call this
-  // method during the parent class instantiation, because the sub class instance
-  // isn't created yet.
-  protected lazy val reservedWords: Seq[String] =
-  this
-    .getClass
-    .getMethods
-    .filter(_.getReturnType == classOf[Keyword])
-    .map(_.invoke(this).asInstanceOf[Keyword].normalize)
-
-  // Set the keywords as empty by default, will change that later.
-  override val lexical = new SqlLexical
-
-  protected case class Keyword(str: String) {
-    def normalize: String = lexical.normalizeKeyword(str)
-    def parser: Parser[String] = normalize
-  }
-
-  def parse(input: String): LogicalPlan = {
-    synchronized {
-      phrase(start)(new lexical.Scanner(input)) match {
-        case Success(plan, _) =>
-          plan
-        case failureOrError =>
-          CarbonException.analysisException(failureOrError.toString)
-      }
-    }
-  }
-
-  private lazy val start: Parser[LogicalPlan] = mvCommand
-
-  private lazy val mvCommand: Parser[LogicalPlan] =
-    createMV | dropMV | showMV | refreshMV
-
-  /**
-   * CREATE MATERIALIZED VIEW [IF NOT EXISTS] mv_name
-   * [WITH DEFERRED REFRESH]
-   * [PROPERTIES('KEY'='VALUE')]
-   * AS mv_query_statement
-   */
-  private lazy val createMV: Parser[LogicalPlan] =
-    CREATE ~> MATERIALIZED ~> VIEW ~> opt(IF ~> NOT ~> EXISTS) ~ ident ~
-    opt(WITH ~> DEFERRED ~> REFRESH) ~
-    (PROPERTIES ~> "(" ~> repsep(options, ",") <~ ")").? ~
-    (AS ~> restInput).? <~ opt(";") ^^ {
-      case ifNotExists ~ mvName ~ deferredRebuild ~ properties ~ query =>
-        val map = properties.getOrElse(List[(String, String)]()).toMap[String, String]
-        CreateMVCommand(mvName, map, query,
-          ifNotExists.isDefined, deferredRebuild.isDefined)
-    }
-
-  /**
-   * DROP MATERIALIZED VIEW [IF EXISTS] mv_name
-   */
-  private lazy val dropMV: Parser[LogicalPlan] =
-    DROP ~> MATERIALIZED ~> VIEW ~> opt(IF ~> EXISTS) ~ ident <~ opt(";") ^^ {
-      case ifExits ~ mvName =>
-        DropMVCommand(mvName, ifExits.isDefined)
-    }
-
-  /**
-   * SHOW MATERIALIZED VIEWS [ON TABLE table_name]
-   */
-  private lazy val showMV: Parser[LogicalPlan] =
-    SHOW ~> MATERIALIZED ~> VIEWS ~> opt(onTable) <~ opt(";") ^^ {
-      case tableIdent =>
-        ShowMVCommand(tableIdent)
-    }
-
-  /**
-   * REFRESH MATERIALIZED VIEW mv_name
-   */
-  private lazy val refreshMV: Parser[LogicalPlan] =
-    REFRESH ~> MATERIALIZED ~> VIEW ~> ident <~ opt(";") ^^ {
-      case mvName =>
-        RefreshMVCommand(mvName)
-    }
-
-  // Returns the rest of the input string that are not parsed yet
-  private lazy val restInput: Parser[String] = new Parser[String] {
-    def apply(in: Input): ParseResult[String] =
-      Success(
-        in.source.subSequence(in.offset, in.source.length()).toString,
-        in.drop(in.source.length()))
-  }
-
-  private lazy val options: Parser[(String, String)] =
-    (stringLit <~ "=") ~ stringLit ^^ {
-      case opt ~ optvalue => (opt.trim.toLowerCase(), optvalue)
-      case _ => ("", "")
-    }
-
-  protected lazy val onTable: Parser[TableIdentifier] =
-    ON ~> TABLE ~>  (ident <~ ".").? ~ ident ^^ {
-      case dbName ~ tableName =>
-        TableIdentifier(tableName, dbName)
-    }
-
-  protected lazy val segmentId: Parser[String] =
-    numericLit ^^ { u => u } |
-    elem("decimal", p => {
-      p.getClass.getSimpleName.equals("FloatLit") ||
-      p.getClass.getSimpleName.equals("DecimalLit")
-    }) ^^ (_.chars)
-
-  def addMVSkipFunction(sql: String): String = {
-    lazy val addMVSkipUDF: Parser[String] =
-      SELECT ~> restInput <~ opt(";") ^^ {
-        case query =>
-          "select mv() as mv, " + query
-      }
-    addMVSkipUDF(new lexical.Scanner(sql)) match {
-      case Success(query, _) => query
-      case _ =>
-        throw new MalformedCarbonCommandException(s"Unsupported query")
-    }
-  }
-}
-
-object MVParser {
-
-  def getMVQuery(query: String, sparkSession: SparkSession): DataFrame = {
-    SparkSQLUtil
-      .execute(getMVPlan(query, sparkSession), sparkSession)
-      .drop(MVUdf.MV_SKIP_RULE_UDF)
-  }
-
-  def getMVPlan(query: String, sparkSession: SparkSession): LogicalPlan = {
-    val updatedQuery = new MVParser().addMVSkipFunction(query)
-    val analyzed = sparkSession.sql(updatedQuery).queryExecution.analyzed
-    CarbonMVRules(sparkSession).apply(analyzed)
-  }
-
-}
-
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVUtil.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVUtil.scala
deleted file mode 100644
index 51302f8..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/MVUtil.scala
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * 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.extension
-
-import scala.collection.mutable
-import scala.collection.mutable.ArrayBuffer
-
-import org.apache.spark.sql.catalyst.catalog.CatalogTable
-import org.apache.spark.sql.catalyst.expressions._
-import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression
-import org.apache.spark.sql.execution.command.Field
-import org.apache.spark.sql.types.DataType
-
-import org.apache.carbondata.common.exceptions.sql.MalformedMVCommandException
-import org.apache.carbondata.mv.plans.modular.{GroupBy, ModularPlan, ModularRelation, Select}
-import org.apache.carbondata.spark.util.CommonUtil
-
-/**
- * Utility class for keeping all the utility method for the MV
- */
-class MVUtil {
-
-  var counter = 0
-
-  /**
-   * Below method will be used to validate and get the required fields from select plan
-   */
-  def getFieldsAndMVFieldsFromPlan(
-      plan: ModularPlan,
-      relations: Seq[Relation]): mutable.LinkedHashMap[Field, MVField] = {
-    plan match {
-      case select: Select =>
-        select.children.map {
-          case groupBy: GroupBy =>
-            getFieldsFromProject(groupBy.outputList, groupBy.predicateList, relations)
-          case _: ModularRelation =>
-            getFieldsFromProject(select.outputList, select.predicateList, relations)
-        }.head
-      case groupBy: GroupBy =>
-        groupBy.child match {
-          case select: Select =>
-            getFieldsFromProject(groupBy.outputList, select.predicateList, relations)
-          case _: ModularRelation =>
-            getFieldsFromProject(groupBy.outputList, groupBy.predicateList, relations)
-        }
-    }
-  }
-
-  /**
-   * Create's main table to MV table field relation map by using modular plan generated from
-   * user query
-   * @param outputList of the modular plan
-   * @param predicateList of the modular plan
-   * @param relations list of main table from query
-   * @return fieldRelationMap
-   */
-  private def getFieldsFromProject(
-      outputList: Seq[NamedExpression],
-      predicateList: Seq[Expression],
-      relations: Seq[Relation]): mutable.LinkedHashMap[Field, MVField] = {
-    var fieldToMVFieldMap = scala.collection.mutable.LinkedHashMap.empty[Field, MVField]
-    fieldToMVFieldMap ++== getFieldsFromProject(outputList, relations)
-    var finalPredicateList: Seq[NamedExpression] = Seq.empty
-    predicateList.map { p =>
-      p.collect {
-        case attr: AttributeReference =>
-          finalPredicateList = finalPredicateList.:+(attr)
-      }
-    }
-    fieldToMVFieldMap ++== getFieldsFromProject(finalPredicateList.distinct, relations)
-    fieldToMVFieldMap
-  }
-
-  private def getFieldsFromProject(
-      projectList: Seq[NamedExpression],
-      relations: Seq[Relation]): mutable.LinkedHashMap[Field, MVField] = {
-    var fieldToMVFieldMap = scala.collection.mutable.LinkedHashMap.empty[Field, MVField]
-    projectList.map {
-      case attr: AttributeReference =>
-        val catalogTable = getCatalogTable(relations, attr)
-        if (null != catalogTable) {
-          val arrayBuffer: ArrayBuffer[ColumnTableRelation] = new ArrayBuffer[ColumnTableRelation]()
-          val relation = getColumnRelation(
-            attr.name,
-            catalogTable.identifier.table,
-            catalogTable.database)
-          if (null != relation) {
-            arrayBuffer += relation
-          }
-          var qualifier: Option[String] = None
-          if (attr.qualifier.nonEmpty) {
-            qualifier = if (attr.qualifier.headOption.get.startsWith("gen_sub")) {
-              Some(catalogTable.identifier.table)
-            } else {
-              attr.qualifier.lastOption
-            }
-          }
-          fieldToMVFieldMap +=
-          getFieldToMVFields(
-            attr.name,
-            attr.dataType,
-            qualifier.lastOption,
-            "",
-            arrayBuffer,
-            catalogTable.identifier.table)
-        }
-      case Alias(attr: AttributeReference, name) =>
-        val catalogTable = getCatalogTable(relations, attr)
-        if (null != catalogTable) {
-          val arrayBuffer: ArrayBuffer[ColumnTableRelation] = new ArrayBuffer[ColumnTableRelation]()
-          val relation = getColumnRelation(
-            attr.name,
-            catalogTable.identifier.table,
-            catalogTable.database)
-          if (null != relation) {
-            arrayBuffer += relation
-          }
-          fieldToMVFieldMap +=
-          getFieldToMVFields(name, attr.dataType, None, "", arrayBuffer, "")
-        }
-
-      case a@Alias(agg: AggregateExpression, _) =>
-        checkIfComplexDataTypeExists(a)
-        val arrayBuffer: ArrayBuffer[ColumnTableRelation] = new ArrayBuffer[ColumnTableRelation]()
-        a.collect {
-          case attr: AttributeReference =>
-            val catalogTable = getCatalogTable(relations, attr)
-            if (null != catalogTable) {
-              val relation = getColumnRelation(
-                attr.name,
-                catalogTable.identifier.table,
-                catalogTable.database)
-              if (null != relation) {
-                arrayBuffer += relation
-              }
-            }
-        }
-        fieldToMVFieldMap +=
-        getFieldToMVFields(a.name,
-          a.dataType,
-          None,
-          agg.aggregateFunction.nodeName,
-          arrayBuffer,
-          "")
-
-      case a@Alias(_, _) =>
-        checkIfComplexDataTypeExists(a)
-        val arrayBuffer: ArrayBuffer[ColumnTableRelation] = new ArrayBuffer[ColumnTableRelation]()
-        a.collect {
-          case attr: AttributeReference =>
-            val catalogTable = getCatalogTable(relations, attr)
-            if (null != catalogTable) {
-              val relation = getColumnRelation(
-                attr.name,
-                catalogTable.identifier.table,
-                catalogTable.database)
-              if (null != relation) {
-                arrayBuffer += relation
-              }
-            }
-        }
-        fieldToMVFieldMap +=
-        getFieldToMVFields(a.name, a.dataType, None, "arithmetic", arrayBuffer, "")
-    }
-    fieldToMVFieldMap
-  }
-
-  /**
-   * Below method will be used to get the column relation with the parent column
-   */
-  private def getColumnRelation(
-      parentColumnName: String,
-      parentTableName: String,
-      parentDatabaseName: String) = {
-    ColumnTableRelation(
-      columnName = parentColumnName,
-      tableName = parentTableName,
-      databaseName = parentDatabaseName)
-  }
-
-  /**
-   * Return the catalog table after matching the attr in logicalRelation
-   */
-  private def getCatalogTable(
-      relations: Seq[Relation],
-      attr: AttributeReference): CatalogTable = {
-    val filteredRelation = relations.filter { relation =>
-        relation.output.exists(attrRef => attrRef.name.equalsIgnoreCase(attr.name) &&
-                                          attrRef.exprId.equals(attr.exprId))
-    }
-    if (filteredRelation.nonEmpty) {
-      filteredRelation.head.catalogTable.get
-    } else {
-      null
-    }
-  }
-
-  /**
-   * Below method will be used to get the fields object for mv table
-   */
-  private def getFieldToMVFields(
-      name: String,
-      dataType: DataType,
-      qualifier: Option[String],
-      aggregateType: String,
-      columnTableRelationList: ArrayBuffer[ColumnTableRelation],
-      parenTableName: String) = {
-    var actualColumnName = MVHelper.getUpdatedName(name, counter)
-    counter += 1
-    if (qualifier.isDefined) {
-      actualColumnName = qualifier.map(qualifier => qualifier + "_" + name)
-        .getOrElse(actualColumnName)
-    }
-    if (qualifier.isEmpty) {
-      if (aggregateType.isEmpty && !parenTableName.isEmpty) {
-        actualColumnName = parenTableName + "_" + actualColumnName
-      }
-    }
-    val rawSchema = '`' + actualColumnName + '`' + ' ' + dataType.typeName
-    val mvField = MVField(aggregateType, columnTableRelationList)
-    if (dataType.typeName.startsWith("decimal")) {
-      val (precision, scale) = CommonUtil.getScaleAndPrecision(dataType.catalogString)
-      (Field(column = actualColumnName,
-        dataType = Some(dataType.typeName),
-        name = Some(actualColumnName),
-        children = None,
-        precision = precision,
-        scale = scale,
-        rawSchema = rawSchema), mvField)
-    } else {
-      (Field(column = actualColumnName,
-        dataType = Some(dataType.typeName),
-        name = Some(actualColumnName),
-        children = None,
-        rawSchema = rawSchema), mvField)
-    }
-  }
-
-  private def checkIfComplexDataTypeExists(a: Alias): Unit = {
-    if (a.child.isInstanceOf[GetMapValue] || a.child.isInstanceOf[GetStructField] ||
-        a.child.isInstanceOf[GetArrayItem]) {
-      throw new UnsupportedOperationException(
-        s"MV is not supported for complex datatype child columns and complex datatype " +
-        s"return types of function :" + a.child.simpleString)
-    }
-  }
-
-  def validateDMProperty(tableProperty: mutable.Map[String, String]): Unit = {
-    val tableProperties = Array("sort_columns",
-      "local_dictionary_include", "local_dictionary_exclude", "long_string_columns",
-      "no_inverted_index", "inverted_index", "column_meta_cache", "range_column")
-    val unsupportedProps = tableProperty
-      .filter(f => tableProperties.exists(prop => prop.equalsIgnoreCase(f._1)))
-    if (unsupportedProps.nonEmpty) {
-      throw new MalformedMVCommandException(
-        "DMProperties " + unsupportedProps.keySet.mkString(",") +
-        " are not allowed for this MV")
-    }
-  }
-
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/CreateMVCommand.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/CreateMVCommand.scala
deleted file mode 100644
index 4487547..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/CreateMVCommand.scala
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.extension.command
-
-import scala.collection.JavaConverters._
-import scala.collection.mutable
-
-import org.apache.spark.sql._
-import org.apache.spark.sql.execution.command._
-
-import org.apache.carbondata.common.exceptions.sql.MalformedMVCommandException
-import org.apache.carbondata.common.logging.LogServiceFactory
-import org.apache.carbondata.core.index.{CarbonIndexProvider, IndexStoreManager}
-import org.apache.carbondata.core.index.status.IndexStatusManager
-import org.apache.carbondata.core.metadata.schema.index.{IndexClassProvider, IndexProperty}
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema
-import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.events._
-import org.apache.carbondata.index.IndexManager
-
-/**
- * Create Materialized View Command implementation
- * It will create the MV table, load the MV table (if deferred rebuild is false),
- * and register the MV mvSchema in [[IndexStoreManager]]
- */
-case class CreateMVCommand(
-    mvName: String,
-    properties: Map[String, String],
-    queryString: Option[String],
-    ifNotExistsSet: Boolean = false,
-    deferredRebuild: Boolean = false)
-  extends AtomicRunnableCommand {
-
-  private val LOGGER = LogServiceFactory.getLogService(this.getClass.getName)
-  private var indexProvider: CarbonIndexProvider = _
-  private var mvSchema: IndexSchema = _
-
-  override def processMetadata(sparkSession: SparkSession): Seq[Row] = {
-
-    setAuditInfo(Map("mvName" -> mvName) ++ properties)
-
-    val mutableMap = mutable.Map[String, String](properties.toSeq: _*)
-    mutableMap.put(IndexProperty.DEFERRED_REBUILD, deferredRebuild.toString)
-
-    mvSchema = new IndexSchema(mvName, IndexClassProvider.MV.name())
-    mvSchema.setProperties(mutableMap.asJava)
-    indexProvider = IndexManager.get.getIndexProvider(null, mvSchema, sparkSession)
-    if (IndexStoreManager.getInstance().getAllIndexSchemas.asScala
-      .exists(_.getIndexName.equalsIgnoreCase(mvSchema.getIndexName))) {
-      if (!ifNotExistsSet) {
-        throw new MalformedMVCommandException(
-          s"Materialized view with name ${mvSchema.getIndexName} already exists")
-      } else {
-        return Seq.empty
-      }
-    }
-
-    val systemFolderLocation: String = CarbonProperties.getInstance().getSystemFolderLocation
-    val operationContext: OperationContext = new OperationContext()
-    val preExecEvent = CreateMVPreExecutionEvent(sparkSession, systemFolderLocation, null)
-    OperationListenerBus.getInstance().fireEvent(preExecEvent, operationContext)
-
-    indexProvider.initMeta(queryString.orNull)
-
-    val postExecEvent = CreateMVPostExecutionEvent(
-      sparkSession, systemFolderLocation, null, IndexClassProvider.MV.name())
-    OperationListenerBus.getInstance().fireEvent(postExecEvent, operationContext)
-    Seq.empty
-  }
-
-  override def processData(sparkSession: SparkSession): Seq[Row] = {
-    if (indexProvider != null) {
-      indexProvider.initData()
-      if (!mvSchema.isLazy) {
-        IndexStatusManager.enableIndex(mvName)
-      }
-    }
-    Seq.empty
-  }
-
-  override def undoMetadata(sparkSession: SparkSession, exception: Exception): Seq[Row] = {
-    if (indexProvider != null) {
-      DropMVCommand(mvName, true).run(sparkSession)
-    }
-    Seq.empty
-  }
-
-  override protected def opName: String = "CREATE MATERIALIZED VIEW"
-}
-
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/DropMVCommand.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/DropMVCommand.scala
deleted file mode 100644
index b09f469..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/DropMVCommand.scala
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.extension.command
-
-import org.apache.spark.sql.{Row, SparkSession}
-import org.apache.spark.sql.execution.command.AtomicRunnableCommand
-
-import org.apache.carbondata.common.logging.LogServiceFactory
-import org.apache.carbondata.core.index.{CarbonIndexProvider, IndexStoreManager}
-import org.apache.carbondata.core.index.status.IndexStatusManager
-import org.apache.carbondata.core.metadata.schema.table.{CarbonTable, IndexSchema}
-import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.events._
-import org.apache.carbondata.index.IndexManager
-
-/**
- * Drop Materialized View Command implementation
- * It will drop the MV table, and unregister the schema in [[IndexStoreManager]]
- */
-case class DropMVCommand(
-    mvName: String,
-    ifExistsSet: Boolean,
-    forceDrop: Boolean = false)
-  extends AtomicRunnableCommand {
-
-  private val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
-  private var provider: CarbonIndexProvider = _
-  var mainTable: CarbonTable = _
-  var mvSchema: IndexSchema = _
-
-  override def processMetadata(sparkSession: SparkSession): Seq[Row] = {
-    setAuditInfo(Map("mvName" -> mvName))
-    try {
-      dropSchema(sparkSession)
-    } catch {
-      case e: Exception =>
-        if (!ifExistsSet) {
-          throw e
-        }
-    }
-    Seq.empty
-  }
-
-  // drop MV schema in underlying store
-  private def dropSchema(sparkSession: SparkSession): Unit = {
-    LOGGER.info("Trying to drop materialized view schema")
-    try {
-      mvSchema = IndexStoreManager.getInstance().getIndexSchema(mvName)
-      if (mvSchema != null) {
-        val operationContext = new OperationContext()
-        val storeLocation = CarbonProperties.getInstance().getSystemFolderLocation
-        val preExecEvent = UpdateMVPreExecutionEvent(sparkSession, storeLocation, null)
-        OperationListenerBus.getInstance().fireEvent(preExecEvent, operationContext)
-
-        IndexStatusManager.dropIndex(mvName)
-
-        val postExecEvent = UpdateMVPostExecutionEvent(sparkSession, storeLocation, null)
-        OperationListenerBus.getInstance().fireEvent(postExecEvent, operationContext)
-
-        provider = IndexManager.get.getIndexProvider(null, mvSchema, sparkSession)
-        provider.cleanMeta()
-      }
-    } catch {
-      case e: Exception =>
-        if (!ifExistsSet) {
-          throw e
-        }
-    }
-  }
-
-  override def processData(sparkSession: SparkSession): Seq[Row] = {
-    // delete the table folder
-    if (provider != null) {
-      provider.cleanData()
-    }
-    Seq.empty
-  }
-
-  override protected def opName: String = "DROP MATERIALIZED VIEW"
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/RefreshMVCommand.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/RefreshMVCommand.scala
deleted file mode 100644
index 1893e04..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/RefreshMVCommand.scala
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.extension.command
-
-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
-import org.apache.carbondata.core.index.IndexStoreManager
-import org.apache.carbondata.core.index.status.IndexStatusManager
-import org.apache.carbondata.core.util.CarbonProperties
-import org.apache.carbondata.events.{UpdateMVPostExecutionEvent, _}
-import org.apache.carbondata.index.IndexManager
-
-/**
- * Refresh Materialized View Command implementation
- * This command refresh the MV table incrementally and make it synchronized with the main
- * table. After sync, MV state is changed to enabled.
- */
-case class RefreshMVCommand(
-    mvName: String) extends DataCommand {
-
-  override def processData(sparkSession: SparkSession): Seq[Row] = {
-    import scala.collection.JavaConverters._
-    val schemas = IndexStoreManager.getInstance().getAllIndexSchemas
-    val schemaOption = schemas.asScala.find(p => p.getIndexName.equalsIgnoreCase(mvName))
-    if (schemaOption.isEmpty) {
-        throw new MalformedMVCommandException(
-          s"Materialized view $mvName does not exist")
-    }
-    val mvSchema = schemaOption.get
-    val mvTable = CarbonEnv.getCarbonTable(
-      Option(mvSchema.getRelationIdentifier.getDatabaseName),
-      mvSchema.getRelationIdentifier.getTableName
-    )(sparkSession)
-
-    setAuditTable(mvTable)
-
-    val provider = IndexManager.get().getIndexProvider(mvTable, mvSchema, sparkSession)
-    provider.rebuild()
-
-    // After rebuild successfully enable the MV table.
-    val operationContext = new OperationContext()
-    val storeLocation = CarbonProperties.getInstance().getSystemFolderLocation
-    val preExecEvent = UpdateMVPreExecutionEvent(sparkSession, storeLocation,
-      new TableIdentifier(mvTable.getTableName, Some(mvTable.getDatabaseName)))
-    OperationListenerBus.getInstance().fireEvent(preExecEvent, operationContext)
-    IndexStatusManager.enableIndex(mvName)
-    val postExecEvent = UpdateMVPostExecutionEvent(sparkSession, storeLocation,
-      new TableIdentifier(mvTable.getTableName, Some(mvTable.getDatabaseName)))
-    OperationListenerBus.getInstance().fireEvent(postExecEvent, operationContext)
-    Seq.empty
-  }
-
-  override protected def opName: String = "REFRESH MATERIALIZED VIEW"
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/ShowMVCommand.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/ShowMVCommand.scala
deleted file mode 100644
index 5ae949c..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/extension/command/ShowMVCommand.scala
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.extension.command
-
-import java.util
-
-import scala.collection.JavaConverters._
-
-import org.apache.spark.sql.{CarbonEnv, Row, SparkSession}
-import org.apache.spark.sql.catalyst.TableIdentifier
-import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
-import org.apache.spark.sql.execution.command.{Checker, DataCommand}
-import org.apache.spark.sql.types.{BooleanType, StringType}
-
-import org.apache.carbondata.core.index.IndexStoreManager
-import org.apache.carbondata.core.metadata.schema.index.IndexClassProvider
-import org.apache.carbondata.core.metadata.schema.table.IndexSchema
-
-/**
- * Show Materialized View Command implementation
- *
- */
-case class ShowMVCommand(tableIdentifier: Option[TableIdentifier])
-  extends DataCommand {
-
-  override def output: Seq[Attribute] = {
-    Seq(
-      AttributeReference("Name", StringType, nullable = false)(),
-      AttributeReference("Related Table", StringType, nullable = false)(),
-      AttributeReference("Refresh", StringType, nullable = false)(),
-      AttributeReference("Incremental", BooleanType, nullable = false)(),
-      AttributeReference("Properties", StringType, nullable = false)(),
-      AttributeReference("Status", StringType, nullable = false)(),
-      AttributeReference("Sync Info", StringType, nullable = false)())
-  }
-
-  override def processData(sparkSession: SparkSession): Seq[Row] = {
-    convertToRow(getAllMVSchema(sparkSession))
-  }
-
-  /**
-   * get all MV schema for this table
-   */
-  def getAllMVSchema(sparkSession: SparkSession): Seq[IndexSchema] = {
-    val indexSchemaList = new util.ArrayList[IndexSchema]()
-    tableIdentifier match {
-      case Some(table) =>
-        val carbonTable = CarbonEnv.getCarbonTable(table)(sparkSession)
-        setAuditTable(carbonTable)
-        Checker.validateTableExists(table.database, table.table, sparkSession)
-        val schemaList = IndexStoreManager.getInstance().getIndexSchemasOfTable(carbonTable)
-        if (!schemaList.isEmpty) {
-          indexSchemaList.addAll(schemaList)
-        }
-      case _ =>
-        indexSchemaList.addAll(IndexStoreManager.getInstance().getAllIndexSchemas)
-    }
-    indexSchemaList.asScala.filter(
-      _.getProviderName.equalsIgnoreCase(IndexClassProvider.MV.name())
-    ).toList
-  }
-
-  private def convertToRow(schemaList: Seq[IndexSchema]) = {
-    if (schemaList != null && schemaList.nonEmpty) {
-      schemaList
-        .map { schema =>
-          Row(
-            schema.getIndexName,
-            schema.getUniqueTableName,
-            if (schema.isLazy) "manual" else "auto",
-            schema.canBeIncrementalBuild,
-            schema.getPropertiesAsString,
-            schema.getStatus.name(),
-            schema.getSyncStatus
-          )
-        }
-    } else {
-      Seq.empty
-    }
-  }
-
-  override protected def opName: String = "SHOW MATERIALIZED VIEW"
-}
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/DefaultMatchMaker.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/DefaultMatchMaker.scala
deleted file mode 100644
index b967686..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/DefaultMatchMaker.scala
+++ /dev/null
@@ -1,860 +0,0 @@
-/*
- * 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.rewrite
-
-import org.apache.spark.sql.CarbonToSparkAdapter
-import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute, AttributeMap, AttributeReference, AttributeSet, Expression, PredicateHelper, _}
-import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression
-import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode}
-import org.apache.spark.sql.catalyst.plans.{FullOuter, Inner, LeftOuter}
-import org.apache.spark.sql.types.{DataType, Metadata}
-
-import org.apache.carbondata.mv.plans.modular.{JoinEdge, Matchable, ModularPlan, _}
-import org.apache.carbondata.mv.plans.modular
-import org.apache.carbondata.mv.plans.modular.Flags._
-import org.apache.carbondata.mv.plans.util.SQLBuilder
-import org.apache.carbondata.mv.timeseries.TimeSeriesFunction
-
-
-abstract class DefaultMatchMaker extends MatchMaker[ModularPlan]
-
-abstract class DefaultMatchPattern extends MatchPattern[ModularPlan] {
-
-  /** Name for this pattern, automatically inferred based on class name. */
-  val patternName: String = {
-    val className = getClass.getName
-    if (className endsWith "$") className.dropRight(1) else className
-  }
-
-  def factorOutSubsumer(
-      compensation: ModularPlan,
-      subsumer: Matchable,
-      aliasMapMain: Map[Int, String]): ModularPlan = {
-
-    // Create aliasMap with attribute to alias reference attribute
-    val aliasMap = AttributeMap(
-        subsumer.outputList.collect {
-          case a: Alias if a.child.isInstanceOf[Attribute] =>
-            (a.child.asInstanceOf[Attribute], a.toAttribute)
-          })
-
-    // Create aliasMap with Expression to alias reference attribute
-    val aliasMapExp =
-      subsumer.outputList.collect {
-        case a: Alias if a.child.isInstanceOf[Expression] &&
-                         !a.child.isInstanceOf[AggregateExpression] =>
-          a.child match {
-            case s: ScalaUDF if s.function.isInstanceOf[TimeSeriesFunction] =>
-              Utils.getTransformedTimeSeriesUDF(s) -> a.toAttribute
-            case cast: Cast if cast.child.isInstanceOf[AttributeReference] =>
-                Utils.getTransformedCastExpression(cast) -> a.toAttribute
-            case _ =>
-              a.child -> a.toAttribute
-          }
-      }.toMap
-
-    // Check and replace all alias references with subsumer alias map references.
-    val compensation1 = compensation.transform {
-      case plan if !plan.skip && plan != subsumer =>
-        plan.transformExpressions {
-          case a: AttributeReference =>
-            aliasMap
-              .get(a)
-              .map { ref =>
-                AttributeReference(
-                  ref.name, ref.dataType)(
-                  exprId = ref.exprId,
-                  qualifier = a.qualifier)
-              }.getOrElse(a)
-          case a: Expression =>
-            var attribute = aliasMapExp
-              .get(a)
-            // attribute will be empty, if attribute name is of different case. If empty, change
-            // case of scalaUDF present in expression and get updated expression from aliasMap
-            if (attribute.isEmpty) {
-              val newExp = a transform {
-                case s: ScalaUDF if s.function.isInstanceOf[TimeSeriesFunction] =>
-                  Utils.getTransformedTimeSeriesUDF(s)
-                case cast: Cast if cast.child.isInstanceOf[AttributeReference] =>
-                  Utils.getTransformedCastExpression(cast)
-              }
-              attribute = aliasMapExp.get(newExp)
-            }
-            attribute
-              .map { ref =>
-                AttributeReference(
-                  ref.name, ref.dataType)(
-                  exprId = ref.exprId)
-              }.getOrElse(a)
-          }
-    }
-
-    val subqueryAttributeSet = SQLBuilder.collectAttributeSet(subsumer.outputList)
-    if (SQLBuilder.collectDuplicateNames(subqueryAttributeSet).nonEmpty) {
-      new UnsupportedOperationException(
-        s"duplicate name(s): ${ subsumer.output.map(_.toString + ", ") }")
-    }
-    if (aliasMapMain.size == 1) {
-      val subsumerName: Option[String] = aliasMapMain.get(0)
-      // Replace all compensation1 attributes with refrences of subsumer attributeset
-      val compensationFinal = compensation1.transformExpressions {
-        case ref: Attribute if subqueryAttributeSet.contains(ref) =>
-          CarbonToSparkAdapter.createAttributeReference(
-            ref.name, ref.dataType, nullable = true, metadata = Metadata.empty,
-            exprId = ref.exprId, qualifier = subsumerName)
-        case alias: Alias if subqueryAttributeSet.contains(alias.toAttribute) =>
-          CarbonToSparkAdapter.createAliasRef(
-            alias.child, alias.name, alias.exprId, subsumerName)
-      }
-      compensationFinal
-    } else {
-      compensation1
-    }
-  }
-}
-
-object DefaultMatchMaker extends DefaultMatchMaker {
-  lazy val patterns =
-    SelectSelectNoChildDelta ::
-    GroupbyGroupbyNoChildDelta ::
-    GroupbyGroupbySelectOnlyChildDelta ::
-    GroupbyGroupbyGroupbyChildDelta ::
-    SelectSelectSelectChildDelta ::
-    SelectSelectGroupbyChildDelta :: Nil
-}
-
-/**
- * Convention:
- * EmR: each subsumee's expression match some of subsumer's expression
- * EdR: each subsumee's expression derive from some of subsumer's expression
- * RmE: each subsumer's expression match some of subsumee's expression
- * RdE: each subsumer's expression derive from some of subsumee's expression
- */
-
-object SelectSelectNoChildDelta extends DefaultMatchPattern with PredicateHelper {
-  private def isDerivable(
-      exprE: Expression,
-      exprListR: Seq[Expression],
-      subsumee: ModularPlan,
-      subsumer: ModularPlan,
-      compensation: Option[ModularPlan]): Boolean = {
-    if (subsumee.asInstanceOf[Select].predicateList.contains(exprE)) {
-      subsumer.asInstanceOf[Select].predicateList.exists(_.semanticEquals(exprE)) ||
-      canEvaluate(exprE, subsumer) ||
-      Utils.isExpressionMatchesUDF(exprE, subsumer.asInstanceOf[Select].predicateList)
-    } else if (subsumee.asInstanceOf[Select].outputList.contains(exprE)) {
-      exprE match {
-        case a@Alias(_, _) =>
-          exprListR.exists(a1 => a1.isInstanceOf[Alias] &&
-                                 a1.asInstanceOf[Alias].child.semanticEquals(a.child)) ||
-          exprListR.exists(_.semanticEquals(exprE) || canEvaluate(exprE, subsumer)) ||
-          Utils.isExpressionMatchesUDF(exprE, exprListR)
-        case exp =>
-          exprListR.exists(a1 => a1.isInstanceOf[Alias] &&
-                                 a1.asInstanceOf[Alias].child.semanticEquals(exp)) ||
-          exprListR.exists(_.semanticEquals(exprE) || canEvaluate(exprE, subsumer)) ||
-          Utils.isExpressionMatchesUDF(exprE, exprListR)
-      }
-    } else {
-      false
-    }
-  }
-
-  private def isLeftJoinView(subsumer: ModularPlan): Boolean = {
-    subsumer match {
-      case sel: Select
-        if sel.joinEdges.length == 1 &&
-           sel.joinEdges.head.joinType == LeftOuter &&
-           sel.children(1).isInstanceOf[HarmonizedRelation] =>
-        val hDim = sel.children(1).asInstanceOf[HarmonizedRelation]
-        hDim.tag match {
-          case Some(tag) => sel.outputList.contains(tag)
-          case None => false
-        }
-      case _ => false
-    }
-  }
-
-  def apply(subsumer: ModularPlan,
-      subsumee: ModularPlan,
-      compensation: Option[ModularPlan],
-      rewrite: QueryRewrite): Seq[ModularPlan] = {
-
-    (subsumer, subsumee, compensation) match {
-      case (
-          sel_1a @ modular.Select(_, _, _, _, _, _, _, _, _, _),
-          sel_1q @ modular.Select(_, _, _, _, _, _, _, _, _, _), None
-        ) if sel_1a.children.forall { _.isInstanceOf[modular.LeafNode] } &&
-             sel_1q.children.forall { _.isInstanceOf[modular.LeafNode] } =>
-
-        // assume children (including harmonized relation) of subsumer and subsumee
-        // are 1-1 correspondence.
-        // Change the following two conditions to more complicated ones if we want to
-        // consider things that combine extrajoin, rejoin, and harmonized relations
-        val isUniqueRmE = subsumer.children.filter { x => subsumee.children.count{
-          case relation: ModularRelation => relation.fineEquals(x)
-          case other => other == x
-        } != 1 }
-        val isUniqueEmR = subsumee.children.filter { x => subsumer.children.count{
-          case relation: ModularRelation => relation.fineEquals(x)
-          case other => other == x
-        } != 1 }
-
-        val extrajoin = sel_1a.children.filterNot { child => sel_1q.children.contains(child) }
-        val rejoin = sel_1q.children.filterNot { child => sel_1a.children.contains(child) }
-        val rejoinOutputList = rejoin.flatMap(_.output)
-
-        val isPredicateRmE = sel_1a.predicateList.forall(expr =>
-          sel_1q.predicateList.exists(_.semanticEquals(expr)) ||
-          Utils.isExpressionMatchesUDF(expr, sel_1q.predicateList))
-        val isPredicateEmdR = sel_1q.predicateList.forall(expr =>
-          isDerivable(expr, sel_1a.outputList ++ rejoinOutputList, sel_1q, sel_1a, None))
-        // Check if sel_1q.outputList is non empty and then check whether
-        // it can be derivable with sel_1a otherwise for empty cases it returns true.
-        val isOutputEdR = sel_1q.outputList.nonEmpty && sel_1q.outputList.forall(expr =>
-          isDerivable(expr, sel_1a.outputList ++ rejoinOutputList, sel_1q, sel_1a, None))
-
-        if (isUniqueRmE.isEmpty && isUniqueEmR.isEmpty && extrajoin.isEmpty && isPredicateRmE &&
-            isPredicateEmdR && isOutputEdR) {
-          val mappings = sel_1a.children.zipWithIndex.map {
-            case (childr, fromIdx) if sel_1q.children.contains(childr) =>
-              val toIndx = sel_1q.children.indexWhere{
-                case relation: ModularRelation => relation.fineEquals(childr)
-                case other => other == childr
-              }
-              (toIndx -> fromIdx)
-
-          }
-          val e2r = mappings.toMap
-          val r2e = e2r.map(_.swap)
-          val r2eJoinsMatch = sel_1a.joinEdges.forall { x =>
-              (r2e.get(x.left), r2e.get(x.right)) match {
-                case (Some(l), Some(r)) =>
-                  val mappedEdge = JoinEdge(l, r, x.joinType)
-                  val joinTypeEquivalent =
-                    if (sel_1q.joinEdges.contains(mappedEdge)) {
-                      true
-                    } else {
-                      x.joinType match {
-                        case Inner | FullOuter =>
-                          sel_1q.joinEdges.contains(JoinEdge(r, l, x.joinType))
-                        case LeftOuter if isLeftJoinView(sel_1a) =>
-                          sel_1q.joinEdges.contains(JoinEdge(l, r, Inner)) ||
-                          sel_1q.joinEdges.contains(JoinEdge(r, l, Inner))
-                        case _ => false
-                      }
-                    }
-                  if (joinTypeEquivalent) {
-                    val sel_1a_join = sel_1a.extractJoinConditions(
-                      sel_1a.children(x.left),
-                      sel_1a.children(x.right))
-                    val sel_1q_join = sel_1q.extractJoinConditions(
-                      sel_1q.children(mappedEdge.left),
-                      sel_1q.children(mappedEdge.right))
-                    sel_1a_join.forall(e => sel_1q_join.exists(e.semanticEquals(_)) ||
-                    Utils.isExpressionMatchesUDF(e, sel_1q_join)) &&
-                    sel_1q_join.forall(e => sel_1a_join.exists(e.semanticEquals(_)) ||
-                    Utils.isExpressionMatchesUDF(e, sel_1a_join))
-                  } else false
-                case _ => false
-              }
-          }
-
-          val isPredicateEmR = sel_1q.predicateList.forall(expr =>
-            sel_1a.predicateList.exists(_.semanticEquals(expr)) ||
-            Utils.isExpressionMatchesUDF(expr, sel_1a.predicateList))
-          val isOutputEmR = sel_1q.outputList.forall(expr =>
-            sel_1a.outputList.exists(_.semanticEquals(expr)) ||
-            Utils.isExpressionMatchesUDF(expr, sel_1a.outputList))
-          val isOutputRmE = sel_1a.outputList.forall(expr =>
-            sel_1q.outputList.exists(_.semanticEquals(expr)) ||
-            Utils.isExpressionMatchesUDF(expr, sel_1q.outputList))
-          val isLOEmLOR = !(isLeftJoinView(sel_1a) && sel_1q.joinEdges.head.joinType == Inner)
-
-          if (r2eJoinsMatch) {
-            if (isPredicateEmR && isOutputEmR && isOutputRmE && rejoin.isEmpty && isLOEmLOR) {
-              if (sel_1q.flagSpec.isEmpty) {
-                Seq(sel_1a)
-              } else {
-                Seq(sel_1a.copy(flags = sel_1q.flags, flagSpec = sel_1q.flagSpec))
-              }
-            } else {
-              // no compensation needed
-              val tChildren = new collection.mutable.ArrayBuffer[ModularPlan]()
-              val tAliasMap = new collection.mutable.HashMap[Int, String]()
-
-              val usel_1a = sel_1a.copy(outputList = sel_1a.outputList)
-              tChildren += usel_1a
-              tAliasMap += (tChildren.indexOf(usel_1a) -> rewrite.newSubsumerName())
-
-              sel_1q.children.zipWithIndex.foreach {
-                case (childe, idx) =>
-                  if (e2r.get(idx).isEmpty) {
-                    tChildren += childe
-                    sel_1q.aliasMap.get(idx).map(x => tAliasMap += (tChildren.indexOf(childe) -> x))
-                  }
-              }
-
-              val tJoinEdges = sel_1q.joinEdges.collect {
-                case JoinEdge(le, re, joinType) =>
-                  (e2r.get(le), e2r.get(re)) match {
-                    case (Some(lr), None) =>
-                      JoinEdge(
-                        0,
-                        tChildren.indexOf(sel_1q.children(re)),
-                        joinType)
-                    case (None, None) =>
-                      JoinEdge(
-                        tChildren.indexOf(sel_1q.children(le)),
-                        tChildren.indexOf(sel_1q.children(re)),
-                        joinType)
-                    case (None, Some(rr)) =>
-                      JoinEdge(
-                        tChildren.indexOf(sel_1q.children(le)),
-                        0,
-                        joinType)
-                    case _ =>
-                      null.asInstanceOf[JoinEdge]
-                  }
-              }
-              val tPredicateList = sel_1q.predicateList.filter { p =>
-                !sel_1a.predicateList.exists(_.semanticEquals(p))
-              } ++ (if (isLeftJoinView(sel_1a) &&
-                        sel_1q.joinEdges.head.joinType == Inner) {
-                sel_1a.children(1)
-                  .asInstanceOf[HarmonizedRelation].tag.map(IsNotNull(_)).toSeq
-              } else {
-                Seq.empty
-              })
-              val sel_1q_temp = sel_1q.copy(
-                predicateList = tPredicateList,
-                children = tChildren,
-                joinEdges = tJoinEdges.filter(_ != null),
-                aliasMap = tAliasMap.toMap)
-
-              val done = factorOutSubsumer(sel_1q_temp, usel_1a, sel_1q_temp.aliasMap)
-              Seq(done)
-            }
-          } else Nil
-        } else Nil
-
-      case (
-        sel_3a @ modular.Select(_, _, _, _, _, _, _, _, _, _),
-        sel_3q @ modular.Select(_, _, _, _, _, _, _, _, _, _), None)
-        if sel_3a.children.forall(_.isInstanceOf[GroupBy]) &&
-           sel_3q.children.forall(_.isInstanceOf[GroupBy]) =>
-        val isPredicateRmE = sel_3a.predicateList.isEmpty ||
-                             sel_3a.predicateList.forall(expr =>
-                               sel_3q.predicateList.exists(_.semanticEquals(expr)) ||
-                               Utils.isExpressionMatchesUDF(expr, sel_3q.predicateList))
-        val isPredicateEmdR = sel_3q.predicateList.isEmpty ||
-                              sel_3q.predicateList.forall(expr =>
-                                sel_3a.predicateList.exists(_.semanticEquals(expr) ||
-                                                            Utils.isExpressionMatchesUDF(expr,
-                                                              sel_3a.predicateList)) ||
-                                isDerivable(expr, sel_3a.outputList, sel_3q, sel_3a, None))
-        val isOutputEdR = sel_3q.outputList.forall(expr =>
-          isDerivable(expr, sel_3a.outputList, sel_3q, sel_3a, None))
-        val isSingleChild = sel_3a.children.length == 1 && sel_3q.children.length == 1
-
-        if (isPredicateRmE && isPredicateEmdR && isOutputEdR && isSingleChild) {
-          val isPredicateEmR = sel_3q.predicateList.isEmpty ||
-                               sel_3q.predicateList.forall(expr =>
-                                 sel_3a.predicateList.exists(_.semanticEquals(expr)) ||
-                                 Utils.isExpressionMatchesUDF(expr, sel_3a.predicateList))
-          val isOutputRmE = sel_3a.outputList.forall(expr =>
-            isDerivable(expr, sel_3q.outputList, sel_3a, sel_3q, None))
-          val isOutputEmR = sel_3q.outputList.forall(expr =>
-            isDerivable(expr, sel_3a.outputList, sel_3q, sel_3a, None))
-
-          if (isPredicateEmR && isOutputEmR && isOutputRmE) {
-            Seq(sel_3a)
-          } else if (isPredicateEmR && isOutputEmR) {
-            // no compensation needed
-            val sel_3q_exp = sel_3q.transformExpressions({
-              case a: Alias => sel_3a.outputList
-                .find { a1 =>
-                  a1.isInstanceOf[Alias] &&
-                  (a1.asInstanceOf[Alias].child.semanticEquals(a.child) ||
-                    Utils.isExpressionMatchesUDF(a1.asInstanceOf[Alias].child, a.child))
-                }.map(_.toAttribute).get
-            })
-            val wip = sel_3q_exp.copy(
-              children = Seq(sel_3a),
-              aliasMap = Seq(0 -> rewrite.newSubsumerName()).toMap)
-            val done = factorOutSubsumer(wip, sel_3a, wip.aliasMap)
-            Seq(done)
-          } else {
-            Nil
-          }
-        } else Nil
-
-      case _ => Nil
-    }
-  }
-
-}
-
-object GroupbyGroupbyNoChildDelta extends DefaultMatchPattern {
-  def apply(
-      subsumer: ModularPlan,
-      subsumee: ModularPlan,
-      compensation: Option[ModularPlan],
-      rewrite: QueryRewrite): Seq[ModularPlan] = {
-    (subsumer, subsumee, compensation) match {
-      case (
-        gb_2a @ modular.GroupBy(_, _, _, _, _, _, _, _),
-        gb_2q @ modular.GroupBy(_, _, _, _, _, _, _, _),
-        None) =>
-        val isGroupingEmR = gb_2q.predicateList.forall(expr =>
-          gb_2a.predicateList.exists(_.semanticEquals(expr)) ||
-          Utils.isExpressionMatchesUDF(expr, gb_2a.predicateList))
-        val isGroupingRmE = gb_2a.predicateList.forall(expr =>
-          gb_2q.predicateList.exists(_.semanticEquals(expr)) ||
-          Utils.isExpressionMatchesUDF(expr, gb_2q.predicateList))
-        val isOutputEmR = gb_2q.outputList.forall {
-          case a @ Alias(_, _) =>
-            gb_2a.outputList.exists{
-              case a1: Alias => a1.child.semanticEquals(a.child)
-              case exp => exp.semanticEquals(a.child)
-            }
-          case exp => gb_2a.outputList.exists(_.semanticEquals(exp))
-        }
-        if (isGroupingEmR && isGroupingRmE) {
-          if (isOutputEmR) {
-            // Mappings of output of two plans by checking semantic equals.
-            val mappings = gb_2a.outputList.zipWithIndex.map { case(exp, index) =>
-              (exp, gb_2q.outputList.find {
-                case a: Alias if exp.isInstanceOf[Alias] =>
-                  a.child.semanticEquals(exp.children.head) ||
-                  Utils.isExpressionMatchesUDF(a.child, exp.children.head)
-                case a: Alias => a.child.semanticEquals(exp)
-                case other => other.semanticEquals(exp)
-              }.getOrElse(gb_2a.outputList(index)))
-            }
-
-            val oList = mappings.map{case (out1, out2) =>
-              if (out1.name != out2.name) out1 match {
-                case alias: Alias => Alias(alias.child, out2.name)(exprId = alias.exprId)
-                case _ => Alias(out1, out2.name)(exprId = out2.exprId)
-              } else out1
-            }
-
-            Seq(gb_2a.copy(outputList = oList))
-          } else {
-            Nil
-          }
-        } else {
-          val aliasMap = AttributeMap(gb_2a.outputList.collect { case a: Alias =>
-            (a.toAttribute, a)})
-          if (isGroupingEmR) {
-            Utils.tryMatch(
-              gb_2a, gb_2q, aliasMap).flatMap {
-              case g: GroupBy =>
-                // Check any agg function exists on outputlist, in case of expressions like
-                // sum(a), then create new alias and copy to group by node
-                val aggFunExists = g.outputList.exists { f =>
-                  f.find {
-                    case _: AggregateExpression => true
-                    case _ => false
-                  }.isDefined
-                }
-                if (aggFunExists && !isGroupingRmE && isOutputEmR) {
-                  val tChildren = new collection.mutable.ArrayBuffer[ModularPlan]()
-                  val sel_1a = g.child.asInstanceOf[Select]
-
-                  val usel_1a = sel_1a.copy(outputList = sel_1a.outputList)
-                  tChildren += gb_2a
-                  val sel_1q_temp = sel_1a.copy(
-                    predicateList = sel_1a.predicateList,
-                    children = tChildren,
-                    joinEdges = sel_1a.joinEdges,
-                    aliasMap = Seq(0 -> rewrite.newSubsumerName()).toMap)
-
-                  val res = factorOutSubsumer(sel_1q_temp, usel_1a, sel_1q_temp.aliasMap)
-                  Some(g.copy(child = res))
-                } else {
-                  Some(g.copy(child = g.child.withNewChildren(
-                    g.child.children.map {
-                      case modular.Select(_, _, _, _, _, _, _, _, _, _) => gb_2a;
-                      case other => other
-                    })));
-                }
-              case _ => None}.map(Seq(_)).getOrElse(Nil)
-          } else {
-            Nil
-          }
-        }
-
-      case _ => Nil
-    }
-  }
-}
-
-object GroupbyGroupbySelectOnlyChildDelta extends DefaultMatchPattern with PredicateHelper {
-  private def isDerivable(
-      exprE: Expression,
-      exprListR: Seq[Expression],
-      subsumee: ModularPlan,
-      subsumer: ModularPlan,
-      compensation: Option[ModularPlan]) = {
-    if (subsumee.asInstanceOf[GroupBy].predicateList.contains(exprE)) {
-      if (exprListR.exists(_.semanticEquals(exprE)) || canEvaluate(exprE, exprListR) ||
-          isDerivableForUDF(exprE, exprListR) || Utils.isExpressionMatchesUDF(exprE, exprListR)) {
-        true
-      } else {
-        false
-      }
-    } else if (compensation.getOrElse(throw new RuntimeException("compensation cannot be None"))
-      .asInstanceOf[Select].predicateList.contains(exprE)) {
-      if (canEvaluate(exprE, exprListR) || exprListR.exists(_.semanticEquals(exprE)) ||
-          isDerivableForUDF(exprE, exprListR) || Utils.isExpressionMatchesUDF(exprE, exprListR)) {
-        true
-      } else {
-        false
-      }
-    } else {
-      false
-    }
-  }
-
-  /**
-   * org.apache.carbondata.mv.plans.MorePredicateHelper#canEvaluate will be checking the
-   * exprE.references as subset of AttibuteSet(exprListR), which will just take the column name from
-   * UDF, so it will be always false for ScalaUDF.
-   * This method takes care of checking whether the exprE references can be derived form list
-   *
-   * Example:
-   * exprE has attribute reference for timeseries column like UDF:timeseries(projectjoindate, month)
-   * So exprE.references will give UDF:timeseries(projectjoindate, month)
-   * exprListR has ScalaUDF also, so AttributeSet(exprListR) contains just column name like
-   * projectjoindate, so canEvaluate method returns false.
-   *
-   * Here checking whether the exprListR(ScalaUDF) .sql gives UDF:timeseries(projectjoindate, month)
-   * which can be checked with exprE.references
-   */
-  private def isDerivableForUDF(exprE: Expression, exprListR: Seq[Expression]): Boolean = {
-    var canBeDerived = false
-    exprE match {
-      case f: ScalaUDF =>
-        canEvaluate(f, exprListR)
-      case _ =>
-        exprListR.forall {
-          case a: ScalaUDF =>
-            a.references.foreach { a =>
-              canBeDerived = exprE.sql.contains(a.name)
-            }
-            canBeDerived
-          case _ =>
-            canBeDerived
-        }
-    }
-  }
-
-  def apply(
-      subsumer: ModularPlan,
-      subsumee: ModularPlan,
-      compensation: Option[ModularPlan],
-      rewrite: QueryRewrite): Seq[ModularPlan] = {
-    val aggInputEinR = subsumee.expressions
-      .collect { case agg: aggregate.AggregateExpression => AttributeSet(Seq(agg))
-        .subsetOf(subsumer.outputSet)
-      }.forall(identity)
-    val compensationSelectOnly = !compensation.map { _.collect { case n => n.getClass } }
-      .exists(_.contains(modular.GroupBy))
-
-    (subsumer, subsumee, compensation, aggInputEinR, compensationSelectOnly) match {
-      case (
-        gb_2a @ modular.GroupBy(_, _, _, _, _, _, _, _),
-        gb_2q @ modular.GroupBy(_, _, _, _, _, _, _, _),
-        Some(sel_1c1 @ modular.Select(_, _, _, _, _, _, _, _, _, _)),
-        true,
-        true)
-        if !gb_2q.flags.hasFlag(EXPAND) && !gb_2a.flags.hasFlag(EXPAND) =>
-
-        val rejoinOutputList = sel_1c1.children.tail.flatMap(_.output)
-        val isGroupingEdR = gb_2q.predicateList.forall(expr =>
-          isDerivable(expr, gb_2a.predicateList ++ rejoinOutputList, gb_2q, gb_2a, compensation))
-        val needRegrouping = !gb_2a.predicateList
-          .forall(f => gb_2q.predicateList.contains(f) ||
-                       Utils.isExpressionMatchesUDF(f, gb_2q.predicateList))
-        val canPullup = sel_1c1.predicateList.forall(expr =>
-          isDerivable(expr, gb_2a.predicateList ++ rejoinOutputList, gb_2q, gb_2a, compensation))
-        val isAggEmR = gb_2q.outputList.collect {
-          case agg: aggregate.AggregateExpression =>
-            gb_2a.outputList.exists(_.semanticEquals(agg))
-        }.forall(identity)
-
-        if (isGroupingEdR && ((!needRegrouping && isAggEmR) || needRegrouping) && canPullup) {
-          // pull up
-          val pullupOutputList = gb_2a.outputList.map(_.toAttribute) ++ rejoinOutputList
-          val myOutputList = gb_2a.outputList.filter {
-            case alias: Alias =>
-              val aliasList = gb_2q.outputList.filter(_.isInstanceOf[Alias])
-              aliasList.exists(_.asInstanceOf[Alias].child.semanticEquals(alias.child)) ||
-              Utils.isExpressionMatchesUDF(alias.child, aliasList)
-            case attr: Attribute =>
-              gb_2q.outputList.exists(_.semanticEquals(attr))
-          }.map(_.toAttribute) ++ rejoinOutputList
-          // TODO: find out if we really need to check needRegrouping or just use myOutputList
-          val sel_2c1 = if (needRegrouping) {
-            sel_1c1
-              .copy(outputList = pullupOutputList,
-                inputList = pullupOutputList,
-                children = sel_1c1.children
-                  .map { _ match { case s: modular.Select => gb_2a; case other => other } })
-          } else {
-            sel_1c1
-              .copy(outputList = myOutputList,
-                inputList = pullupOutputList,
-                children = sel_1c1.children
-                  .map { _ match { case s: modular.Select => gb_2a; case other => other } })
-          }
-          // sel_1c1.copy(outputList = pullupOutputList, inputList = pullupOutputList, children =
-          // sel_1c1.children.map { _ match { case s: modular.Select => gb_2a; case other =>
-          // other } })
-
-          if (rejoinOutputList.isEmpty) {
-            val aliasMap = AttributeMap(gb_2a.outputList.collect {
-              case a: Alias => (a.toAttribute, a)
-            })
-            val res =
-            Utils.tryMatch(gb_2a, gb_2q, aliasMap).flatMap {
-              case g: GroupBy =>
-
-                // Check any agg function exists on outputlist, in case of expressions like
-                // sum(a)+sum(b) , outputlist directly replaces with alias with in place of function
-                // so we should remove the groupby clause in those cases.
-                val aggFunExists = g.outputList.exists { f =>
-                  f.find {
-                    case ag: AggregateExpression => true
-                    case _ => false
-                  }.isDefined
-                }
-                if (aggFunExists) {
-                  Some(g.copy(child = sel_2c1))
-                } else {
-                  // Remove group by clause.
-                  Some(g.copy(child = sel_2c1, predicateList = Seq.empty))
-                }
-              case _ => None
-            }.map { wip =>
-              factorOutSubsumer(wip, gb_2a, sel_1c1.aliasMap)
-            }.map(Seq(_))
-              .getOrElse(Nil)
-            res
-          }
-          // TODO: implement regrouping with 1:N rejoin (rejoin tables being the "1" side)
-          // via catalog service
-          else if (!needRegrouping && isAggEmR) {
-            Seq(sel_2c1).map(wip => factorOutSubsumer(wip, gb_2a, sel_1c1.aliasMap))
-          } else Nil
-        } else Nil
-
-      case _ => Nil
-    }
-  }
-}
-
-object GroupbyGroupbyGroupbyChildDelta extends DefaultMatchPattern {
-  def apply(
-      subsumer: ModularPlan,
-      subsumee: ModularPlan,
-      compensation: Option[ModularPlan],
-      rewrite: QueryRewrite): Seq[ModularPlan] = {
-    val groupbys = compensation.map { _.collect { case g: GroupBy => g } }.getOrElse(Nil).toSet
-
-    (subsumer, subsumee, groupbys.nonEmpty) match {
-      case (
-        modular.Select(_, _, _, _, _, _, _, _, _, _),
-        modular.Select(_, _, _, _, _, _, _, _, _, _),
-        true) =>
-        // TODO: implement me
-        Nil
-
-      case _ => Nil
-    }
-  }
-}
-
-
-object SelectSelectSelectChildDelta extends DefaultMatchPattern {
-  def apply(
-      subsumer: ModularPlan,
-      subsumee: ModularPlan,
-      compensation: Option[ModularPlan],
-      rewrite: QueryRewrite): Seq[ModularPlan] = {
-    val compensationSelectOnly =
-      !compensation
-        .map { _.collect { case n => n.getClass } }
-        .exists(_.contains(modular.GroupBy))
-
-    (subsumer, subsumee, compensationSelectOnly) match {
-      case (
-        modular.Select(_, _, _, _, _, _, _, _, _, _),
-        modular.Select(_, _, _, _, _, _, _, _, _, _),
-        true) =>
-        // TODO: implement me
-        Nil
-      case _ => Nil
-    }
-  }
-}
-
-object SelectSelectGroupbyChildDelta extends DefaultMatchPattern with PredicateHelper {
-  private def isDerivable(
-      exprE: Expression,
-      exprListR: Seq[Expression],
-      subsumee: ModularPlan,
-      subsumer: ModularPlan,
-      compensation: Option[ModularPlan]) = {
-    Utils.isDerivable(
-      exprE: Expression,
-      exprListR: Seq[Expression],
-      subsumee: ModularPlan,
-      subsumer: ModularPlan,
-      compensation: Option[ModularPlan])
-  }
-
-  def apply(
-      subsumer: ModularPlan,
-      subsumee: ModularPlan,
-      compensation: Option[ModularPlan],
-      rewrite: QueryRewrite): Seq[ModularPlan] = {
-    (subsumer, subsumee, compensation, subsumer.children, subsumee.children) match {
-      case (
-        sel_3a@modular.Select(
-        _, _, Nil, _, _,
-        Seq(gb_2a@modular.GroupBy(_, _, _, _, _, _, _, _)), _, _, _, _),
-        sel_3q@modular.Select(
-        _, _, _, _, _,
-        Seq(gb_2q@modular.GroupBy(_, _, _, _, _, _, _, _)), _, _, _, _),
-        Some(gb_2c@modular.GroupBy(_, _, _, _, _, _, _, _)),
-        rchild :: Nil,
-        echild :: Nil) =>
-        val tbls_sel_3a = sel_3a.collect { case tbl: modular.LeafNode => tbl }
-        val tbls_sel_3q = sel_3q.collect { case tbl: modular.LeafNode => tbl }
-
-        val extrajoin = tbls_sel_3a.filterNot(tbls_sel_3q.contains)
-        val rejoin = tbls_sel_3q.filterNot(tbls_sel_3a.contains)
-        val rejoinOutputList = rejoin.flatMap(_.output)
-
-        val isPredicateRmE = sel_3a.predicateList.forall(expr =>
-          sel_3q.predicateList.exists(_.semanticEquals(expr)) ||
-          Utils.isExpressionMatchesUDF(expr, sel_3q.predicateList) ||
-          gb_2c.predicateList.exists(_.semanticEquals(expr)) ||
-          Utils.isExpressionMatchesUDF(expr, gb_2c.predicateList))
-        val isPredicateEmdR = sel_3q.predicateList
-          .forall(expr =>
-            sel_3a.predicateList.exists(_.semanticEquals(expr)) ||
-            Utils.isExpressionMatchesUDF(expr, sel_3a.predicateList) ||
-            isDerivable(
-              expr,
-              sel_3a.outputList ++ rejoinOutputList,
-              sel_3q,
-              sel_3a,
-              compensation))
-        val isOutputEdR = sel_3q.outputList
-          .forall(expr =>
-            isDerivable(
-              expr,
-              sel_3a.outputList ++ rejoinOutputList,
-              sel_3q,
-              sel_3a,
-              compensation))
-
-        val canSELPullup = gb_2c.child.isInstanceOf[Select] &&
-                           gb_2c.child.asInstanceOf[Select].predicateList
-                             .forall(expr =>
-                               isDerivable(
-                                 expr,
-                                 sel_3a.outputList ++ rejoinOutputList,
-                                 sel_3q,
-                                 sel_3a,
-                                 compensation))
-        val canGBPullup = gb_2c.predicateList
-          .forall(expr =>
-            isDerivable(
-              expr,
-              sel_3a.outputList ++ rejoinOutputList,
-              sel_3q,
-              sel_3a,
-              compensation))
-
-        if (extrajoin.isEmpty && isPredicateRmE &&
-            isPredicateEmdR &&
-            isOutputEdR &&
-            canSELPullup &&
-            canGBPullup) {
-          gb_2c.child match {
-            case s: Select =>
-              val sel_3c1 = s.withNewChildren(
-                s.children.map {
-                  case gb: GroupBy => sel_3a.setSkip()
-                  case other => other })
-              val gb_3c2 = gb_2c.copy(child = sel_3c1)
-
-              val aliasMap_exp = AttributeMap(
-                gb_2c.outputList.collect {
-                  case a: Alias => (a.toAttribute, AliasWrapper(a)) })
-              val sel_3q_exp = sel_3q.transformExpressions({
-                case attr: Attribute if aliasMap_exp.contains(attr) => aliasMap_exp(attr)
-              }).transformExpressions {
-                case AliasWrapper(alias: Alias) => alias
-              }
-              // Mappings of output of two plans by checking semantic equals.
-              val mappings = sel_3q_exp.outputList.zipWithIndex.map { case(exp, index) =>
-                (exp, gb_2c.outputList.find {
-                  case a: Alias if exp.isInstanceOf[Alias] =>
-                    a.child.semanticEquals(exp.children.head) ||
-                    Utils.isExpressionMatchesUDF(a.child, exp.children.head)
-                  case a: Alias => a.child.semanticEquals(exp)
-                  case other => other.semanticEquals(exp)
-                }.getOrElse(gb_2c.outputList(index)))
-              }
-
-              val oList = CarbonToSparkAdapter.createAliases(mappings)
-
-              val wip = sel_3q_exp.copy(outputList = oList, children = Seq(gb_3c2))
-              val sel_3c3 = Some(factorOutSubsumer(wip, sel_3a, s.aliasMap))
-              sel_3c3.map(Seq(_)).getOrElse(Nil)
-
-            case _ => Nil
-          }
-        } else {
-          Nil
-        }
-
-      case _ => Nil
-    }
-  }
-
-
-  case class AliasWrapper(alias: Alias) extends UnaryExpression {
-    override def child: Expression = null
-
-    override protected def doGenCode(ctx: CodegenContext,
-        ev: ExprCode): ExprCode = ev
-
-    override def dataType: DataType = alias.dataType
-  }
-
-}
-
-
diff --git a/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/MVUdf.scala b/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/MVUdf.scala
deleted file mode 100644
index 23c406a..0000000
--- a/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/MVUdf.scala
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.rewrite
-
-import scala.language.implicitConversions
-
-object MVUdf {
-  lazy val MV_SKIP_RULE_UDF = "mv"
... 3033 lines suppressed ...