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

    https://github.com/apache/carbondata/pull/2310#discussion_r188847107
  
    --- Diff: 
core/src/main/java/org/apache/carbondata/core/datamap/DataMapUtil.java ---
    @@ -0,0 +1,132 @@
    +/*
    + * 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.datamap;
    +
    +import java.io.IOException;
    +import java.lang.reflect.Constructor;
    +import java.util.List;
    +
    +import org.apache.carbondata.common.logging.LogService;
    +import org.apache.carbondata.common.logging.LogServiceFactory;
    +import org.apache.carbondata.core.datamap.dev.expr.DataMapExprWrapper;
    +import org.apache.carbondata.core.indexstore.ExtendedBlocklet;
    +import org.apache.carbondata.core.indexstore.PartitionSpec;
    +import 
org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMapFactory;
    +import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
    +import org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf;
    +import org.apache.carbondata.core.statusmanager.SegmentStatusManager;
    +import org.apache.carbondata.core.util.ObjectSerializationUtil;
    +
    +import org.apache.hadoop.conf.Configuration;
    +
    +public class DataMapUtil {
    +
    +  private static final String DATA_MAP_DSTR = 
"mapreduce.input.carboninputformat.datamapdstr";
    +
    +  private static final LogService LOGGER =
    +      LogServiceFactory.getLogService(DataMapUtil.class.getName());
    +
    +  /**
    +   * This method set DataMapJob if configured
    +   *
    +   * @param conf
    +   * @throws IOException
    +   */
    +  public static void setDataMapJobIfConfigured(Configuration conf) throws 
IOException {
    +    String className = "org.apache.carbondata.spark.rdd.SparkDataMapJob";
    +    setDataMapJob(conf, createDataMapJob(className));
    +  }
    +
    +  /**
    +   * Creates instance for the DataMap Job class
    +   *
    +   * @param className
    +   * @return
    +   */
    +  public static Object createDataMapJob(String className) {
    +    try {
    +      return 
Class.forName(className).getDeclaredConstructors()[0].newInstance();
    +    } catch (Exception e) {
    +      LOGGER.error(e);
    +      return null;
    +    }
    +  }
    +
    +  public static void setDataMapJob(Configuration configuration, Object 
dataMapJob)
    +      throws IOException {
    +    if (dataMapJob != null) {
    +      String toString = 
ObjectSerializationUtil.convertObjectToString(dataMapJob);
    +      configuration.set(DATA_MAP_DSTR, toString);
    +    }
    +  }
    +
    +  public static DataMapJob getDataMapJob(Configuration configuration) 
throws IOException {
    +    String jobString = configuration.get(DATA_MAP_DSTR);
    +    if (jobString != null) {
    +      return (DataMapJob) 
ObjectSerializationUtil.convertStringToObject(jobString);
    +    }
    +    return null;
    +  }
    +
    +  public static void executeDataMapJobForClearingDataMaps(CarbonTable 
carbonTable)
    +      throws IOException {
    +    String dataMapJobClassName = 
"org.apache.carbondata.spark.rdd.SparkDataMapJob";
    +    DataMapJob dataMapJob = (DataMapJob) 
createDataMapJob(dataMapJobClassName);
    +    String className = 
"org.apache.carbondata.core.datamap.DistributableDataMapFormat";
    +    SegmentStatusManager ssm = new 
SegmentStatusManager(carbonTable.getAbsoluteTableIdentifier());
    +    List<Segment> validSegments = 
ssm.getValidAndInvalidSegments().getValidSegments();
    +    DataMapExprWrapper dataMapExprWrapper = null;
    +    if 
(DataMapStoreManager.getInstance().getAllDataMap(carbonTable).size() > 0) {
    +      DataMapChooser dataMapChooser = new DataMapChooser(carbonTable);
    +      dataMapExprWrapper = 
dataMapChooser.getAllDataMapsForClear(carbonTable);
    +    } else {
    +      return;
    +    }
    +    DistributableDataMapFormat dataMapFormat =
    +        createDataMapJob(carbonTable, dataMapExprWrapper, validSegments, 
null, className, true);
    +    dataMapJob.execute((DistributableDataMapFormat) dataMapFormat, null);
    +  }
    +
    +  public static DistributableDataMapFormat createDataMapJob(CarbonTable 
carbonTable,
    --- End diff --
    
    Make it private


---

Reply via email to