You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by cloud-fan <gi...@git.apache.org> on 2018/01/31 04:47:08 UTC

[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

GitHub user cloud-fan opened a pull request:

    https://github.com/apache/spark/pull/20448

    [SPARK-23203][SQL] make DataSourceV2Relation immutable

    ## What changes were proposed in this pull request?
    
    This is inspired by https://github.com/apache/spark/pull/20387, but only focus on making the plan immutable.
    
    The idea is simple, instead of keeping the mutable `DataSourceReader` in the plan, we should keep `DataSourceV2`, and create the reader when needed. The pushdown information will be stored in the plan, instead of relying on the mutable reader.
    
    This can also help us removing 2 unnecessary APIs from `SupportsPushDownCatalystFilters` and `SupportsPushDownFilters`.
    
    ## How was this patch tested?
    
    I improved the test in `DataSourceV2Suite`, to make sure this new change doesn't break the column pruning and filter push down.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/cloud-fan/spark immutable-plan

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/20448.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #20448
    
----
commit 7441334e210944e1419be4059d12c06385c586cb
Author: Wenchen Fan <we...@...>
Date:   2018-01-31T03:12:00Z

    make DataSourceV2Relation immutable

----


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution/419/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/86876/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86876 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86876/testReport)** for PR 20448 at commit [`11220db`](https://github.com/apache/spark/commit/11220db7879798967cda85d2aa4e68fefb8ec646).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86862 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86862/testReport)** for PR 20448 at commit [`0665282`](https://github.com/apache/spark/commit/0665282cca2b690b2bc54e179496e03f7d77596c).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/86867/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164954221
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    --- End diff --
    
    `An` ->  `A`


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86867 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86867/testReport)** for PR 20448 at commit [`11220db`](https://github.com/apache/spark/commit/11220db7879798967cda85d2aa4e68fefb8ec646).
     * This patch **fails from timeout after a configured wait of \`300m\`**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by rdblue <gi...@git.apache.org>.
Github user rdblue commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r165132718
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,36 +17,84 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader A mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    +
    +  override def references: AttributeSet = AttributeSet.empty
    +
    +  override def sourceClass: Class[_ <: DataSourceV2] = source.getClass
     
       override def canEqual(other: Any): Boolean = other.isInstanceOf[DataSourceV2Relation]
     
    +  def reader: DataSourceReader = existingReader.getOrElse {
    +    (source, userSpecifiedSchema) match {
    +      case (ds: ReadSupportWithSchema, Some(schema)) =>
    +        ds.createReader(schema, options)
    +
    +      case (ds: ReadSupport, None) =>
    +        ds.createReader(options)
    +
    +      case (ds: ReadSupport, Some(schema)) =>
    +        val reader = ds.createReader(options)
    +        // Sanity check, this should be guaranteed by `DataFrameReader.load`
    +        assert(reader.readSchema() == schema)
    +        reader
    +
    +      case _ => throw new IllegalStateException()
    +    }
    +  }
    +
       override def computeStats(): Statistics = reader match {
         case r: SupportsReportStatistics =>
           Statistics(sizeInBytes = r.getStatistics.sizeInBytes().orElse(conf.defaultSizeInBytes))
         case _ =>
           Statistics(sizeInBytes = conf.defaultSizeInBytes)
       }
    +
    +  override def simpleString: String = s"Relation $metadataString"
     }
     
     /**
      * A specialization of DataSourceV2Relation with the streaming bit set to true. Otherwise identical
      * to the non-streaming relation.
      */
    -class StreamingDataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends DataSourceV2Relation(fullOutput, reader) {
    +case class StreamingDataSourceV2Relation(
    --- End diff --
    
    Agreed. That was the plan here.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    retest this please


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86861 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86861/testReport)** for PR 20448 at commit [`7441334`](https://github.com/apache/spark/commit/7441334e210944e1419be4059d12c06385c586cb).
     * This patch **fails to build**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164955297
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    +
    +  override def references: AttributeSet = AttributeSet.empty
    +
    +  override def sourceClass: Class[_ <: DataSourceV2] = source.getClass
     
       override def canEqual(other: Any): Boolean = other.isInstanceOf[DataSourceV2Relation]
     
    +  def reader: DataSourceReader = existingReader.getOrElse {
    +    (source, userSpecifiedSchema) match {
    +      case (ds: ReadSupportWithSchema, Some(schema)) =>
    +        ds.createReader(schema, options)
    +
    +      case (ds: ReadSupport, None) =>
    +        ds.createReader(options)
    +
    +      case (ds: ReadSupport, Some(schema)) =>
    +        val reader = ds.createReader(options)
    +        // Sanity check, this should be guaranteed by `DataFrameReader.load`
    +        assert(reader.readSchema() == schema)
    +        reader
    +
    +      case _ => throw new IllegalStateException()
    +    }
    +  }
    +
    --- End diff --
    
    Do we need to override a `def doCanonicalize`?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164952844
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2QueryPlan.scala ---
    @@ -19,50 +19,31 @@ package org.apache.spark.sql.execution.datasources.v2
     
     import java.util.Objects
     
    -import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
    -import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeSet, Expression}
    +import org.apache.spark.sql.sources.v2.DataSourceV2
     
     /**
    - * A base class for data source reader holder with customized equals/hashCode methods.
    + * A base class for data source v2 related query plan. It defines the equals/hashCode methods
    + * according to some common information.
      */
    -trait DataSourceReaderHolder {
    +trait DataSourceV2QueryPlan {
     
    -  /**
    -   * The full output of the data source reader, without column pruning.
    -   */
    -  def fullOutput: Seq[AttributeReference]
    +  def output: Seq[Attribute]
    +  def sourceClass: Class[_ <: DataSourceV2]
    +  def filters: Set[Expression]
     
    -  /**
    -   * The held data source reader.
    -   */
    -  def reader: DataSourceReader
    -
    -  /**
    -   * The metadata of this data source reader that can be used for equality test.
    -   */
    -  private def metadata: Seq[Any] = {
    -    val filters: Any = reader match {
    -      case s: SupportsPushDownCatalystFilters => s.pushedCatalystFilters().toSet
    -      case s: SupportsPushDownFilters => s.pushedFilters().toSet
    -      case _ => Nil
    -    }
    -    Seq(fullOutput, reader.getClass, reader.readSchema(), filters)
    -  }
    +  // The metadata of this data source relation that can be used for equality test.
    +  private def metadata: Seq[Any] = Seq(output, sourceClass, filters)
     
       def canEqual(other: Any): Boolean
     
       override def equals(other: Any): Boolean = other match {
    -    case other: DataSourceReaderHolder =>
    -      canEqual(other) && metadata.length == other.metadata.length &&
    -        metadata.zip(other.metadata).forall { case (l, r) => l == r }
    +    case other: DataSourceV2QueryPlan =>
    +      canEqual(other) && metadata == other.metadata
         case _ => false
       }
     
       override def hashCode(): Int = {
         metadata.map(Objects.hashCode).foldLeft(0)((a, b) => 31 * a + b)
       }
    -
    -  lazy val output: Seq[Attribute] = reader.readSchema().map(_.name).map { name =>
    --- End diff --
    
    We don't need to do this anymore. Now the plan is immutable, we have to create a new plan when applying push down optimizations, and we can also update `output` at that time.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan closed the pull request at:

    https://github.com/apache/spark/pull/20448


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by rdblue <gi...@git.apache.org>.
Github user rdblue commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    @cloud-fan, **please close this PR**. There is already a pull request for these changes, #20387, and ongoing discussion there.
    
    If you want the proposed implementation to change, please ask for changes in a review.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution/416/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86862 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86862/testReport)** for PR 20448 at commit [`0665282`](https://github.com/apache/spark/commit/0665282cca2b690b2bc54e179496e03f7d77596c).
     * This patch **fails to build**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution/431/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86876 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86876/testReport)** for PR 20448 at commit [`11220db`](https://github.com/apache/spark/commit/11220db7879798967cda85d2aa4e68fefb8ec646).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164956171
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    +
    +  override def references: AttributeSet = AttributeSet.empty
    +
    +  override def sourceClass: Class[_ <: DataSourceV2] = source.getClass
     
       override def canEqual(other: Any): Boolean = other.isInstanceOf[DataSourceV2Relation]
     
    +  def reader: DataSourceReader = existingReader.getOrElse {
    +    (source, userSpecifiedSchema) match {
    +      case (ds: ReadSupportWithSchema, Some(schema)) =>
    +        ds.createReader(schema, options)
    +
    +      case (ds: ReadSupport, None) =>
    +        ds.createReader(options)
    +
    +      case (ds: ReadSupport, Some(schema)) =>
    +        val reader = ds.createReader(options)
    +        // Sanity check, this should be guaranteed by `DataFrameReader.load`
    +        assert(reader.readSchema() == schema)
    +        reader
    +
    +      case _ => throw new IllegalStateException()
    +    }
    +  }
    +
    --- End diff --
    
    What is the behavior we expect when users call `REFRESH TABLE`?
    
    Also another potential issue is about storing the statistics in the external catalog? Do we still have the previous issues discussed in https://github.com/apache/spark/pull/14712?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86865 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86865/testReport)** for PR 20448 at commit [`11220db`](https://github.com/apache/spark/commit/11220db7879798967cda85d2aa4e68fefb8ec646).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164954926
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    --- End diff --
    
    Could you add a test for self join? Just to ensure it still works.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    cc @rdblue @tdas @gatorsmile 


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86861 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86861/testReport)** for PR 20448 at commit [`7441334`](https://github.com/apache/spark/commit/7441334e210944e1419be4059d12c06385c586cb).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    retest this please


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164958102
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    +
    +  override def references: AttributeSet = AttributeSet.empty
    +
    +  override def sourceClass: Class[_ <: DataSourceV2] = source.getClass
     
       override def canEqual(other: Any): Boolean = other.isInstanceOf[DataSourceV2Relation]
     
    +  def reader: DataSourceReader = existingReader.getOrElse {
    +    (source, userSpecifiedSchema) match {
    +      case (ds: ReadSupportWithSchema, Some(schema)) =>
    +        ds.createReader(schema, options)
    +
    +      case (ds: ReadSupport, None) =>
    +        ds.createReader(options)
    +
    +      case (ds: ReadSupport, Some(schema)) =>
    +        val reader = ds.createReader(options)
    +        // Sanity check, this should be guaranteed by `DataFrameReader.load`
    +        assert(reader.readSchema() == schema)
    +        reader
    +
    +      case _ => throw new IllegalStateException()
    +    }
    +  }
    +
    --- End diff --
    
    data source v2 doesn't support tables yet, so we don't have this problem now.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86863 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86863/testReport)** for PR 20448 at commit [`d96a48f`](https://github.com/apache/spark/commit/d96a48ff8f03daff23633b700a1374c89f3675e2).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/86861/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86863 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86863/testReport)** for PR 20448 at commit [`d96a48f`](https://github.com/apache/spark/commit/d96a48ff8f03daff23633b700a1374c89f3675e2).
     * This patch **fails to build**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/86865/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution/417/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/86862/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/86863/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164954392
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    --- End diff --
    
    Why this plan does not extend `MultiInstanceRelation`?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86865 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86865/testReport)** for PR 20448 at commit [`11220db`](https://github.com/apache/spark/commit/11220db7879798967cda85d2aa4e68fefb8ec646).
     * This patch **fails due to an unknown error code, -9**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164953600
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2QueryPlan.scala ---
    @@ -19,50 +19,31 @@ package org.apache.spark.sql.execution.datasources.v2
     
     import java.util.Objects
     
    -import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
    -import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeSet, Expression}
    +import org.apache.spark.sql.sources.v2.DataSourceV2
     
     /**
    - * A base class for data source reader holder with customized equals/hashCode methods.
    + * A base class for data source v2 related query plan. It defines the equals/hashCode methods
    + * according to some common information.
    --- End diff --
    
    We might need to emphasize this is for both physical and logical plans.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    **[Test build #86867 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/86867/testReport)** for PR 20448 at commit [`11220db`](https://github.com/apache/spark/commit/11220db7879798967cda85d2aa4e68fefb8ec646).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution/423/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164955518
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    +
    +  override def references: AttributeSet = AttributeSet.empty
    +
    +  override def sourceClass: Class[_ <: DataSourceV2] = source.getClass
     
       override def canEqual(other: Any): Boolean = other.isInstanceOf[DataSourceV2Relation]
     
    +  def reader: DataSourceReader = existingReader.getOrElse {
    +    (source, userSpecifiedSchema) match {
    +      case (ds: ReadSupportWithSchema, Some(schema)) =>
    +        ds.createReader(schema, options)
    +
    +      case (ds: ReadSupport, None) =>
    +        ds.createReader(options)
    +
    +      case (ds: ReadSupport, Some(schema)) =>
    +        val reader = ds.createReader(options)
    +        // Sanity check, this should be guaranteed by `DataFrameReader.load`
    +        assert(reader.readSchema() == schema)
    +        reader
    +
    +      case _ => throw new IllegalStateException()
    +    }
    +  }
    +
    --- End diff --
    
    What is the output of this node in `Explain`?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r165049675
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,36 +17,84 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader A mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    +
    +  override def references: AttributeSet = AttributeSet.empty
    +
    +  override def sourceClass: Class[_ <: DataSourceV2] = source.getClass
     
       override def canEqual(other: Any): Boolean = other.isInstanceOf[DataSourceV2Relation]
     
    +  def reader: DataSourceReader = existingReader.getOrElse {
    +    (source, userSpecifiedSchema) match {
    +      case (ds: ReadSupportWithSchema, Some(schema)) =>
    +        ds.createReader(schema, options)
    +
    +      case (ds: ReadSupport, None) =>
    +        ds.createReader(options)
    +
    +      case (ds: ReadSupport, Some(schema)) =>
    +        val reader = ds.createReader(options)
    +        // Sanity check, this should be guaranteed by `DataFrameReader.load`
    +        assert(reader.readSchema() == schema)
    +        reader
    +
    +      case _ => throw new IllegalStateException()
    +    }
    +  }
    +
       override def computeStats(): Statistics = reader match {
         case r: SupportsReportStatistics =>
           Statistics(sizeInBytes = r.getStatistics.sizeInBytes().orElse(conf.defaultSizeInBytes))
         case _ =>
           Statistics(sizeInBytes = conf.defaultSizeInBytes)
       }
    +
    +  override def simpleString: String = s"Relation $metadataString"
     }
     
     /**
      * A specialization of DataSourceV2Relation with the streaming bit set to true. Otherwise identical
      * to the non-streaming relation.
      */
    -class StreamingDataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends DataSourceV2Relation(fullOutput, reader) {
    +case class StreamingDataSourceV2Relation(
    --- End diff --
    
    Similar to `LogicalRelation`, I think we can simply add a `isStream` parameter to `DataSourceV2Relation`. This can be addressed in a follow up PR.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #20448: [SPARK-23203][SQL] make DataSourceV2Relation immutable

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/20448
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #20448: [SPARK-23203][SQL] make DataSourceV2Relation immu...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20448#discussion_r164966631
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Relation.scala ---
    @@ -17,16 +17,57 @@
     
     package org.apache.spark.sql.execution.datasources.v2
     
    -import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.expressions.{AttributeReference, AttributeSet, Expression}
     import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
    +import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2, ReadSupport, ReadSupportWithSchema}
     import org.apache.spark.sql.sources.v2.reader._
    +import org.apache.spark.sql.types.StructType
     
    +/**
    + * A logical plan representing a data source relation, which will be planned to a data scan
    + * operator finally.
    + *
    + * @param output The output of this relation.
    + * @param source The instance of a data source v2 implementation.
    + * @param options The options specified for this scan, used to create the `DataSourceReader`.
    + * @param userSpecifiedSchema The user specified schema, used to create the `DataSourceReader`.
    + * @param filters The predicates which are pushed and handled by this data source.
    + * @param existingReader An mutable reader carrying some temporary stats during optimization and
    + *                       planning. It's always None before optimization, and does not take part in
    + *                       the equality of this plan, which means this plan is still immutable.
    + */
     case class DataSourceV2Relation(
    -    fullOutput: Seq[AttributeReference],
    -    reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
    +    output: Seq[AttributeReference],
    +    source: DataSourceV2,
    +    options: DataSourceOptions,
    +    userSpecifiedSchema: Option[StructType],
    +    filters: Set[Expression],
    +    existingReader: Option[DataSourceReader]) extends LeafNode with DataSourceV2QueryPlan {
    --- End diff --
    
    good catch! Yea this is a bug, but to respect the rule about solving different issues in different PR, I'd like to fix it in a new PR.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org