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

    https://github.com/apache/spark/pull/3269#discussion_r20587713
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/parquet/newParquet.scala ---
    @@ -0,0 +1,291 @@
    +/*
    + * 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.parquet
    +
    +import java.util.{List => JList}
    +
    +import org.apache.hadoop.fs.{FileStatus, FileSystem, Path}
    +import org.apache.hadoop.conf.{Configurable, Configuration}
    +import org.apache.hadoop.io.Writable
    +import org.apache.hadoop.mapreduce.{JobContext, InputSplit, Job}
    +
    +import parquet.hadoop.ParquetInputFormat
    +import parquet.hadoop.util.ContextUtil
    +
    +import org.apache.spark.annotation.DeveloperApi
    +import org.apache.spark.{Partition => SparkPartition, Logging}
    +import org.apache.spark.rdd.{NewHadoopPartition, RDD}
    +
    +import org.apache.spark.sql.{SQLConf, Row, SQLContext}
    +import org.apache.spark.sql.catalyst.expressions.{SpecificMutableRow, And, 
Expression, Attribute}
    +import org.apache.spark.sql.catalyst.types.{IntegerType, StructField, 
StructType}
    +import org.apache.spark.sql.sources._
    +
    +import scala.collection.JavaConversions._
    +
    +/**
    + * Allows creation of parquet based tables using the syntax
    + * `CREATE TABLE ... USING org.apache.spark.sql.parquet`.  Currently the 
only option required
    + * is `path`, which is should be the location of a collection of, 
optionally partitioned,
    + * parquet files.
    + */
    +class DefaultSource extends RelationProvider {
    +  /** Returns a new base relation with the given parameters. */
    +  override def createRelation(
    +      sqlContext: SQLContext,
    +      parameters: Map[String, String]): BaseRelation = {
    +    val path =
    +      parameters.getOrElse("path", sys.error("'path' must be specifed for 
parquet tables."))
    +
    +    ParquetRelation2(path)(sqlContext)
    +  }
    +}
    +
    +private[parquet] case class Partition(partitionValues: Map[String, Any], 
files: Seq[FileStatus])
    +
    +/**
    + * An alternative to [[ParquetRelation]] that plugs in using the data 
sources API.  This class is
    + * currently not intended as a full replacement of the parquet support in 
Spark SQL though it is
    + * likely that it will eventually subsume the existing physical plan 
implementation.
    + *
    + * Compared with the current implementation, this class has the following 
notable differences:
    + *
    + * Partitioning: Partitions are auto discovered and must be in the form of 
directories `key=value/`
    + * located at `path`.  Currently only a single partitioning column is 
supported and it must
    + * be an integer.  This class supports both fully self-describing data, 
which contains the partition
    + * key, and data where the partition key is only present in the folder 
structure.  The presence
    + * of the partitioning key in the data is also auto-detected.
    + *
    + * Metadata: The metadata is automatically discovered by reading the first 
parquet file present.
    + * There is currently no support for working with files that have 
different schema.  Additionally,
    + * when parquet metadata caching is turned on, the FileStatus objects for 
all data will be cached
    + * to improve the speed of interactive querying.  When data is added to a 
table it must be dropped
    + * and recreated to pick up any changes.
    + *
    + * Statistics: Statistics for the size of the table are automatically 
populated during metadata
    + * discovery.
    + */
    +@DeveloperApi
    +case class ParquetRelation2(path: String)(@transient val sqlContext: 
SQLContext)
    +  extends CatalystScan with Logging {
    +
    +  def sparkContext = sqlContext.sparkContext
    +
    +  // Minor Hack: scala doesnt seem to respect @transient for vals declared 
via extraction
    +  @transient
    +  private var partitionKeys: Seq[String] = _
    +  @transient
    +  private var partitions: Seq[Partition] = _
    +  discoverPartitions()
    +
    +  // TODO: Only finds the first partition, assumes the key is of type 
Integer...
    +  private def discoverPartitions() = {
    +    val fs = FileSystem.get(new java.net.URI(path), 
sparkContext.hadoopConfiguration)
    +    val partValue = "([^=]+)=([^=]+)".r
    +
    +    val childrenOfPath = fs.listStatus(new 
Path(path)).filterNot(_.getPath.getName.startsWith("_"))
    +    val childDirs = childrenOfPath.filter(s => s.isDir)
    +
    +    if (childDirs.size > 0) {
    +      val partitionPairs = childDirs.map(_.getPath.getName).map {
    +        case partValue(key, value) => (key, value)
    +      }
    +
    +      val foundKeys = partitionPairs.map(_._1).distinct
    +      if (foundKeys.size > 1) {
    +        sys.error(s"Too many distinct partition keys: $foundKeys")
    +      }
    +
    +      // Do a parallel lookup of partition metadata.
    +      val partitionFiles =
    +        childDirs.par
    +          .map(d => 
fs.listStatus(d.getPath).filterNot(_.getPath.getName.startsWith("_"))).seq
    +
    +      partitionKeys = foundKeys.toSeq
    +      partitions = partitionFiles.zip(partitionPairs).map { case (files, 
(key, value)) =>
    +        Partition(Map(key -> value.toInt), files)
    +      }.toSeq
    +    } else {
    +      partitionKeys = Nil
    +      partitions = Partition(Map.empty, childrenOfPath) :: Nil
    +    }
    +  }
    +
    +  override val sizeInBytes = partitions.flatMap(_.files).map(_.getLen).sum
    +
    +  val dataSchema = StructType.fromAttributes(// TODO: Parquet code should 
not deal with attributes.
    --- End diff --
    
    Space before `//`


---
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