Skip to content

Commit

Permalink
[SPARK-23293][SQL] fix data source v2 self join
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?

`DataSourceV2Relation` should extend `MultiInstanceRelation`, to take care of self-join.

## How was this patch tested?

a new test

Author: Wenchen Fan <[email protected]>

Closes #20466 from cloud-fan/dsv2-selfjoin.
  • Loading branch information
cloud-fan authored and gatorsmile committed Feb 1, 2018
1 parent f051f83 commit 73da3b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

package org.apache.spark.sql.execution.datasources.v2

import org.apache.spark.sql.catalyst.analysis.MultiInstanceRelation
import org.apache.spark.sql.catalyst.expressions.AttributeReference
import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
import org.apache.spark.sql.sources.v2.reader._

case class DataSourceV2Relation(
fullOutput: Seq[AttributeReference],
reader: DataSourceReader) extends LeafNode with DataSourceReaderHolder {
reader: DataSourceReader)
extends LeafNode with MultiInstanceRelation with DataSourceReaderHolder {

override def canEqual(other: Any): Boolean = other.isInstanceOf[DataSourceV2Relation]

Expand All @@ -33,6 +35,10 @@ case class DataSourceV2Relation(
case _ =>
Statistics(sizeInBytes = conf.defaultSizeInBytes)
}

override def newInstance(): DataSourceV2Relation = {
copy(fullOutput = fullOutput.map(_.newInstance()))
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ class DataSourceV2Suite extends QueryTest with SharedSQLContext {
}
}
}

test("SPARK-23293: data source v2 self join") {
val df = spark.read.format(classOf[SimpleDataSourceV2].getName).load()
val df2 = df.select(($"i" + 1).as("k"), $"j")
checkAnswer(df.join(df2, "j"), (0 until 10).map(i => Row(-i, i, i + 1)))
}
}

class SimpleDataSourceV2 extends DataSourceV2 with ReadSupport {
Expand Down

0 comments on commit 73da3b6

Please sign in to comment.