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

    https://github.com/apache/carbondata/pull/2055#discussion_r174212055
  
    --- Diff: 
integration/spark2/src/main/scala/org/apache/spark/sql/execution/datasources/CarbonFileLevelFormat.scala
 ---
    @@ -0,0 +1,266 @@
    +/*
    + * 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
    +
    +import java.net.URI
    +
    +import scala.collection.mutable.ArrayBuffer
    +
    +import org.apache.hadoop.conf.Configuration
    +import org.apache.hadoop.fs.{FileStatus, Path}
    +import org.apache.hadoop.mapred.JobConf
    +import org.apache.hadoop.mapreduce._
    +import org.apache.hadoop.mapreduce.lib.input.FileSplit
    +import org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl
    +import org.apache.spark.{SparkException, TaskContext}
    +import org.apache.spark.deploy.SparkHadoopUtil
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.sql.catalyst.InternalRow
    +import org.apache.spark.sql.execution.datasources._
    +import org.apache.spark.sql.execution.datasources.text.TextOutputWriter
    +import org.apache.spark.sql.optimizer.CarbonFilters
    +import org.apache.spark.sql.sources.{DataSourceRegister, Filter}
    +import org.apache.spark.sql.types.{AtomicType, StructField, StructType}
    +
    +import org.apache.carbondata.common.logging.LogServiceFactory
    +import org.apache.carbondata.core.constants.CarbonCommonConstants
    +import org.apache.carbondata.core.datamap.{DataMapChooser, 
DataMapStoreManager, Segment}
    +import org.apache.carbondata.core.indexstore.PartitionSpec
    +import 
org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore
    +import org.apache.carbondata.core.metadata.{AbsoluteTableIdentifier, 
CarbonMetadata, ColumnarFormatVersion}
    +import org.apache.carbondata.core.reader.CarbonHeaderReader
    +import org.apache.carbondata.core.scan.expression.Expression
    +import org.apache.carbondata.core.scan.expression.logical.AndExpression
    +import org.apache.carbondata.core.scan.model.QueryModel
    +import org.apache.carbondata.core.util.{CarbonProperties, CarbonUtil}
    +import org.apache.carbondata.core.util.path.CarbonTablePath
    +import org.apache.carbondata.hadoop.{CarbonInputSplit, CarbonProjection, 
CarbonRecordReader, InputMetricsStats}
    +import org.apache.carbondata.hadoop.api.{CarbonFileInputFormat, DataMapJob}
    +import org.apache.carbondata.spark.util.CarbonScalaUtil
    +
    +class CarbonFileLevelFormat extends FileFormat
    +  with DataSourceRegister
    +  with Logging
    +  with Serializable {
    +
    +  @transient val LOGGER = 
LogServiceFactory.getLogService(this.getClass.getName)
    +
    +  override def inferSchema(sparkSession: SparkSession,
    +      options: Map[String, String],
    +      files: Seq[FileStatus]): Option[StructType] = {
    +    val filePaths = CarbonUtil.getFilePathExternalFilePath(
    +      options.get("path").get)
    +    if (filePaths.size() == 0) {
    +      throw new SparkException("CarbonData file is not present in the 
location mentioned in DDL")
    +    }
    +    val carbonHeaderReader: CarbonHeaderReader = new 
CarbonHeaderReader(filePaths.get(0))
    +    val fileHeader = carbonHeaderReader.readHeader
    +    val table_columns: 
java.util.List[org.apache.carbondata.format.ColumnSchema] = fileHeader
    +      .getColumn_schema
    +    var colArray = ArrayBuffer[StructField]()
    +    for (i <- 0 to table_columns.size() - 1) {
    +      val col = 
CarbonUtil.thriftColumnSchmeaToWrapperColumnSchema(table_columns.get(i))
    +      colArray += (new StructField(col.getColumnName,
    +        CarbonScalaUtil.convertCarbonToSparkDataType(col.getDataType), 
false))
    +    }
    +    colArray.+:(Nil)
    +
    +    Some(StructType(colArray))
    +  }
    +
    +  override def prepareWrite(sparkSession: SparkSession,
    +      job: Job,
    +      options: Map[String, String],
    +      dataSchema: StructType): OutputWriterFactory = {
    +
    +    new OutputWriterFactory {
    +      override def newInstance(
    +          path: String,
    +          dataSchema: StructType,
    +          context: TaskAttemptContext): OutputWriter = {
    +        new TextOutputWriter(path, dataSchema, context)
    +      }
    +
    +      override def getFileExtension(context: TaskAttemptContext): String = 
{
    +        CarbonTablePath.CARBON_DATA_EXT
    +      }
    +    }
    +  }
    +
    +  override def shortName(): String = "CarbonDataFileFormat"
    --- End diff --
    
    change the shortName to `carbonfile`. So, `carbondata` is for table level 
and `carbonfile` is for file level


---

Reply via email to