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

    https://github.com/apache/spark/pull/9240#discussion_r42889239
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/text/DefaultSource.scala
 ---
    @@ -0,0 +1,160 @@
    +/*
    + * 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.execution.datasources.text
    +
    +import com.google.common.base.Objects
    +import org.apache.hadoop.fs.{Path, FileStatus}
    +import org.apache.hadoop.io.{NullWritable, Text, LongWritable}
    +import org.apache.hadoop.mapred.{TextInputFormat, JobConf}
    +import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat
    +import org.apache.hadoop.mapreduce.{RecordWriter, TaskAttemptContext, Job}
    +import org.apache.hadoop.mapreduce.lib.input.FileInputFormat
    +
    +import org.apache.spark.deploy.SparkHadoopUtil
    +import org.apache.spark.mapred.SparkHadoopMapRedUtil
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.catalyst.InternalRow
    +import org.apache.spark.sql.catalyst.expressions.GenericMutableRow
    +import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
    +import org.apache.spark.sql.execution.datasources.PartitionSpec
    +import org.apache.spark.sql.sources._
    +import org.apache.spark.sql.types.{StringType, StructType}
    +import org.apache.spark.unsafe.types.UTF8String
    +
    +/**
    + * A data source for reading text files.
    + */
    +class DefaultSource extends HadoopFsRelationProvider with 
DataSourceRegister {
    +
    +  override def createRelation(
    +      sqlContext: SQLContext,
    +      paths: Array[String],
    +      dataSchema: Option[StructType],
    +      partitionColumns: Option[StructType],
    +      parameters: Map[String, String]): HadoopFsRelation = {
    +    dataSchema.foreach(verifySchema)
    +    new TextRelation(None, partitionColumns, paths)(sqlContext)
    +  }
    +
    +  override def shortName(): String = "text"
    +
    +  private def verifySchema(schema: StructType): Unit = {
    +    if (schema.size != 1) {
    +      throw new AnalysisException(
    +        s"Text data source supports only a single column, and you have 
${schema.size} columns.")
    +    }
    +    val tpe = schema(0).dataType
    +    if (tpe != StringType) {
    +      throw new AnalysisException(
    +        s"Text data source supports only a string column, but you have 
${tpe.simpleString}.")
    +    }
    +  }
    +}
    +
    +private[sql] class TextRelation(
    +    val maybePartitionSpec: Option[PartitionSpec],
    +    override val userDefinedPartitionColumns: Option[StructType],
    +    override val paths: Array[String] = Array.empty[String])
    +    (@transient val sqlContext: SQLContext)
    +  extends HadoopFsRelation(maybePartitionSpec) {
    +
    +  /** Data schema is always a single column, named "text". */
    +  override def dataSchema: StructType = new StructType().add("text", 
StringType)
    +
    +  /** This is an internal data source that outputs internal row format. */
    +  override val needConversion: Boolean = false
    +
    +  /** Read path. */
    +  override def buildScan(inputPaths: Array[FileStatus]): RDD[Row] = {
    +    val job = new Job(sqlContext.sparkContext.hadoopConfiguration)
    +    val conf = SparkHadoopUtil.get.getConfigurationFromJobContext(job)
    +    val paths = inputPaths.map(_.getPath).sorted
    --- End diff --
    
    I got a 
    ```
    [error] 
/Users/yhuai/Projects/Spark/yin-spark-1/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/text/DefaultSource.scala:86:
 No implicit Ordering defined for org.apache.hadoop.fs.Path.
    [error]     val paths = inputPaths.map(_.getPath).sorted
    [error]                                           ^
    ```


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to