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

    https://github.com/apache/carbondata/pull/1099#discussion_r126093559
  
    --- Diff: 
hadoop/src/main/java/org/apache/carbondata/hadoop/CarbonInputFormatNew.java ---
    @@ -0,0 +1,566 @@
    +/*
    + * 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.hadoop;
    +
    +import java.io.IOException;
    +import java.lang.reflect.Constructor;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.BitSet;
    +import java.util.HashMap;
    +import java.util.LinkedList;
    +import java.util.List;
    +import java.util.Map;
    +
    +import org.apache.carbondata.core.constants.CarbonCommonConstants;
    +import org.apache.carbondata.core.datastore.TableSegmentUniqueIdentifier;
    +import org.apache.carbondata.core.indexstore.AbstractTableDataMap;
    +import org.apache.carbondata.core.indexstore.Blocklet;
    +import org.apache.carbondata.core.indexstore.DataMapStoreManager;
    +import org.apache.carbondata.core.indexstore.DataMapType;
    +import org.apache.carbondata.core.keygenerator.KeyGenException;
    +import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier;
    +import org.apache.carbondata.core.metadata.ColumnarFormatVersion;
    +import org.apache.carbondata.core.metadata.schema.PartitionInfo;
    +import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
    +import org.apache.carbondata.core.mutate.CarbonUpdateUtil;
    +import org.apache.carbondata.core.mutate.SegmentUpdateDetails;
    +import org.apache.carbondata.core.mutate.UpdateVO;
    +import org.apache.carbondata.core.mutate.data.BlockMappingVO;
    +import org.apache.carbondata.core.scan.expression.Expression;
    +import org.apache.carbondata.core.scan.filter.FilterExpressionProcessor;
    +import org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf;
    +import org.apache.carbondata.core.scan.model.CarbonQueryPlan;
    +import org.apache.carbondata.core.scan.model.QueryModel;
    +import org.apache.carbondata.core.scan.partition.PartitionUtil;
    +import org.apache.carbondata.core.scan.partition.Partitioner;
    +import org.apache.carbondata.core.stats.QueryStatistic;
    +import org.apache.carbondata.core.stats.QueryStatisticsConstants;
    +import org.apache.carbondata.core.stats.QueryStatisticsRecorder;
    +import org.apache.carbondata.core.statusmanager.SegmentStatusManager;
    +import org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager;
    +import org.apache.carbondata.core.util.CarbonTimeStatisticsFactory;
    +import org.apache.carbondata.core.util.CarbonUtil;
    +import org.apache.carbondata.core.util.path.CarbonStorePath;
    +import org.apache.carbondata.core.util.path.CarbonTablePath;
    +import org.apache.carbondata.hadoop.readsupport.CarbonReadSupport;
    +import 
org.apache.carbondata.hadoop.readsupport.impl.DictionaryDecodeReadSupport;
    +import org.apache.carbondata.hadoop.util.CarbonInputFormatUtil;
    +import org.apache.carbondata.hadoop.util.ObjectSerializationUtil;
    +import org.apache.carbondata.hadoop.util.SchemaReader;
    +
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.fs.FileSystem;
    +import org.apache.hadoop.fs.InvalidPathException;
    +import org.apache.hadoop.fs.LocalFileSystem;
    +import org.apache.hadoop.fs.Path;
    +import org.apache.hadoop.mapreduce.InputSplit;
    +import org.apache.hadoop.mapreduce.JobContext;
    +import org.apache.hadoop.mapreduce.RecordReader;
    +import org.apache.hadoop.mapreduce.TaskAttemptContext;
    +import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    +import org.apache.hadoop.mapreduce.lib.input.FileSplit;
    +import org.apache.hadoop.mapreduce.security.TokenCache;
    +import org.apache.hadoop.util.StringUtils;
    +
    +/**
    + * Carbon Input format class representing one carbon table
    + */
    +public class CarbonInputFormatNew<T> extends FileInputFormat<Void, T> {
    +
    +  // comma separated list of input segment numbers
    +  public static final String INPUT_SEGMENT_NUMBERS =
    +      "mapreduce.input.carboninputformat.segmentnumbers";
    +  // comma separated list of input files
    +  public static final String INPUT_FILES = 
"mapreduce.input.carboninputformat.files";
    +  private static final Log LOG = 
LogFactory.getLog(CarbonInputFormatNew.class);
    +  private static final String FILTER_PREDICATE =
    +      "mapreduce.input.carboninputformat.filter.predicate";
    +  private static final String COLUMN_PROJECTION = 
"mapreduce.input.carboninputformat.projection";
    +  private static final String CARBON_TABLE = 
"mapreduce.input.carboninputformat.table";
    +  private static final String CARBON_READ_SUPPORT = 
"mapreduce.input.carboninputformat.readsupport";
    +
    +  /**
    +   * It is optional, if user does not set then it reads from store
    +   *
    +   * @param configuration
    +   * @param carbonTable
    +   * @throws IOException
    +   */
    +  public static void setCarbonTable(Configuration configuration, 
CarbonTable carbonTable)
    +      throws IOException {
    +    if (null != carbonTable) {
    +      configuration.set(CARBON_TABLE, 
ObjectSerializationUtil.convertObjectToString(carbonTable));
    +    }
    +  }
    +
    +  public static CarbonTable getCarbonTable(Configuration configuration) 
throws IOException {
    +    String carbonTableStr = configuration.get(CARBON_TABLE);
    +    if (carbonTableStr == null) {
    +      populateCarbonTable(configuration);
    +      // read it from schema file in the store
    +      carbonTableStr = configuration.get(CARBON_TABLE);
    +      return (CarbonTable) 
ObjectSerializationUtil.convertStringToObject(carbonTableStr);
    +    }
    +    return (CarbonTable) 
ObjectSerializationUtil.convertStringToObject(carbonTableStr);
    +  }
    +
    +  /**
    +   * this method will read the schema from the physical file and populate 
into CARBON_TABLE
    +   *
    +   * @param configuration
    +   * @throws IOException
    +   */
    +  private static void populateCarbonTable(Configuration configuration) 
throws IOException {
    +    String dirs = configuration.get(INPUT_DIR, "");
    +    String[] inputPaths = StringUtils.split(dirs);
    +    if (inputPaths.length == 0) {
    +      throw new InvalidPathException("No input paths specified in job");
    +    }
    +    AbsoluteTableIdentifier absoluteTableIdentifier =
    +        AbsoluteTableIdentifier.fromTablePath(inputPaths[0]);
    +    // read the schema file to get the absoluteTableIdentifier having the 
correct table id
    +    // persisted in the schema
    +    CarbonTable carbonTable = 
SchemaReader.readCarbonTableFromStore(absoluteTableIdentifier);
    +    setCarbonTable(configuration, carbonTable);
    +  }
    +
    +  public static void setTablePath(Configuration configuration, String 
tablePath)
    +      throws IOException {
    +    configuration.set(FileInputFormat.INPUT_DIR, tablePath);
    +  }
    +
    +  /**
    +   * It sets unresolved filter expression.
    +   *
    +   * @param configuration
    +   * @param filterExpression
    +   */
    +  public static void setFilterPredicates(Configuration configuration, 
Expression filterExpression) {
    +    if (filterExpression == null) {
    +      return;
    +    }
    +    try {
    +      String filterString = 
ObjectSerializationUtil.convertObjectToString(filterExpression);
    +      configuration.set(FILTER_PREDICATE, filterString);
    +    } catch (Exception e) {
    +      throw new RuntimeException("Error while setting filter expression to 
Job", e);
    +    }
    +  }
    +
    +  public static void setColumnProjection(Configuration configuration, 
CarbonProjection projection) {
    +    if (projection == null || projection.isEmpty()) {
    +      return;
    +    }
    +    String[] allColumns = projection.getAllColumns();
    +    StringBuilder builder = new StringBuilder();
    +    for (String column : allColumns) {
    +      builder.append(column).append(",");
    +    }
    +    String columnString = builder.toString();
    +    columnString = columnString.substring(0, columnString.length() - 1);
    +    configuration.set(COLUMN_PROJECTION, columnString);
    +  }
    +
    +  public static String getColumnProjection(Configuration configuration) {
    +    return configuration.get(COLUMN_PROJECTION);
    +  }
    +
    +  public static void setCarbonReadSupport(Configuration configuration,
    +      Class<? extends CarbonReadSupport> readSupportClass) {
    +    if (readSupportClass != null) {
    +      configuration.set(CARBON_READ_SUPPORT, readSupportClass.getName());
    +    }
    +  }
    +
    +  private static CarbonTablePath getTablePath(AbsoluteTableIdentifier 
absIdentifier) {
    +    return CarbonStorePath.getCarbonTablePath(absIdentifier);
    +  }
    +
    +  /**
    +   * Set list of segments to access
    +   */
    +  public static void setSegmentsToAccess(Configuration configuration, 
List<String> validSegments) {
    +    configuration.set(CarbonInputFormatNew.INPUT_SEGMENT_NUMBERS,
    +        CarbonUtil.getSegmentString(validSegments));
    +  }
    +
    +  /**
    +   * Set list of files to access
    +   */
    +  public static void setFilesToAccess(Configuration configuration, 
List<String> validFiles) {
    +    configuration.set(CarbonInputFormatNew.INPUT_FILES, 
CarbonUtil.getSegmentString(validFiles));
    +  }
    +
    +  private static AbsoluteTableIdentifier 
getAbsoluteTableIdentifier(Configuration configuration)
    +      throws IOException {
    +    return getCarbonTable(configuration).getAbsoluteTableIdentifier();
    +  }
    +
    +  /**
    +   * {@inheritDoc}
    +   * Configurations FileInputFormat.INPUT_DIR
    +   * are used to get table path to read.
    +   *
    +   * @param job
    +   * @return List<InputSplit> list of CarbonInputSplit
    +   * @throws IOException
    +   */
    +  @Override public List<InputSplit> getSplits(JobContext job) throws 
IOException {
    +    AbsoluteTableIdentifier identifier = 
getAbsoluteTableIdentifier(job.getConfiguration());
    +    AbstractTableDataMap blockletMap =
    +        DataMapStoreManager.getInstance().getDataMap(identifier, 
"blocklet", DataMapType.BLOCKLET);
    +    List<String> invalidSegments = new ArrayList<>();
    +    List<UpdateVO> invalidTimestampsList = new ArrayList<>();
    +
    +    // get all valid segments and set them into the configuration
    +    if (getSegmentsToAccess(job).length == 0) {
    +      SegmentStatusManager segmentStatusManager = new 
SegmentStatusManager(identifier);
    +      SegmentStatusManager.ValidAndInvalidSegmentsInfo segments =
    +          segmentStatusManager.getValidAndInvalidSegments();
    +      SegmentUpdateStatusManager updateStatusManager = new 
SegmentUpdateStatusManager(identifier);
    +      setSegmentsToAccess(job.getConfiguration(), 
segments.getValidSegments());
    --- End diff --
    
    ok


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to