Skip to content

Conversation

@gatorsmile
Copy link
Member

@gatorsmile gatorsmile commented Nov 10, 2017

What changes were proposed in this pull request?

The current internal table() API of SparkSession bypasses the Analyzer and directly calls sessionState.catalog.lookupRelation API. This skips the view resolution logics in our Analyzer rule ResolveRelations. This internal API is widely used by various DDL commands, public and internal APIs.

Users might get the strange error caused by view resolution when the default database is different.

Table or view not found: t1; line 1 pos 14
org.apache.spark.sql.AnalysisException: Table or view not found: t1; line 1 pos 14
	at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42)

This PR is to fix it by enforcing it to use ResolveRelations to resolve the table.

How was this patch tested?

Added a test case and modified the existing test cases

@gatorsmile
Copy link
Member Author

cc @cloud-fan @jiangxb1987

@SparkQA
Copy link

SparkQA commented Nov 10, 2017

Test build #83664 has finished for PR 19713 at commit d87f333.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

}

test("rename temporary view") {
test("rename temporary table") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temporary view is more accurate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from 2.2 version... : )

table(sessionState.sqlParser.parseTableIdentifier(tableName))
}

private[sql] def table(tableIdent: TableIdentifier): DataFrame = {
Copy link
Contributor

@cloud-fan cloud-fan Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also called by the public table API, so this bug affects the public interface too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. many public APIs and DDL command processing are based on this internal API.

@cloud-fan
Copy link
Contributor

LGTM

@SparkQA
Copy link

SparkQA commented Nov 10, 2017

Test build #83678 has finished for PR 19713 at commit db2292f.

  • This patch fails SparkR unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 10, 2017

Test build #83674 has finished for PR 19713 at commit 99936cc.

  • This patch fails SparkR unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

it's a valid failure

Failed -------------------------------------------------------------------------
1. Failure: test cache, uncache and clearCache (@test_sparkSQL.R#735) ----------
error$message does not match "Error in uncacheTable : no such table - Table or view 'foo' not found in database 'default'".
Actual value: "Error in uncacheTable : analysis error - Table or view not found: foo;"

@SparkQA
Copy link

SparkQA commented Nov 11, 2017

Test build #83717 has finished for PR 19713 at commit c491974.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.


expect_error(uncacheTable("foo"),
"Error in uncacheTable : no such table - Table or view 'foo' not found in database 'default'")
"Error in uncacheTable : analysis error - Table or view not found: foo")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit:

expect_error(uncacheTable("foo"),
             "Error in uncacheTable : analysis error - Table or view not found: foo")

@SparkQA
Copy link

SparkQA commented Nov 11, 2017

Test build #83721 has finished for PR 19713 at commit c491974.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

@jiangxb1987 jiangxb1987 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@asfgit asfgit closed this in d6ee69e Nov 11, 2017
@cloud-fan
Copy link
Contributor

thanks, merging to master! can you send a new PR for 2.2?

@felixcheung
Copy link
Member

felixcheung commented Nov 11, 2017 via email

gatorsmile added a commit to gatorsmile/spark that referenced this pull request Nov 11, 2017
…internal table() API

The current internal `table()` API of `SparkSession` bypasses the Analyzer and directly calls `sessionState.catalog.lookupRelation` API. This skips the view resolution logics in our Analyzer rule `ResolveRelations`. This internal API is widely used by various DDL commands, public and internal APIs.

Users might get the strange error caused by view resolution when the default database is different.
```
Table or view not found: t1; line 1 pos 14
org.apache.spark.sql.AnalysisException: Table or view not found: t1; line 1 pos 14
	at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42)
```

This PR is to fix it by enforcing it to use `ResolveRelations` to resolve the table.

Added a test case and modified the existing test cases

Author: gatorsmile <[email protected]>

Closes apache#19713 from gatorsmile/viewResolution.
@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented Dec 5, 2017

Hi, All.
It seems that we missed DROP TABLE IF EXISTS case here.
(I also forgot to check that during 2.2-backporting of this PR.)
This PR swallows NoSuchTableException and emits AnalysisException. DROP TABLE IF EXISTS expected NoSuchTableException in ddl.scala. It becomes a regression on 2.2.1.

ghost pushed a commit to dbtsai/spark that referenced this pull request Dec 6, 2017
…tion

## What changes were proposed in this pull request?

During [SPARK-22488](apache#19713) to fix view resolution issue, there occurs a regression at `2.2.1` and `master` branch like the following. This PR fixes that.

```scala
scala> spark.version
res2: String = 2.2.1

scala> sql("DROP TABLE IF EXISTS t").show
17/12/04 21:01:06 WARN DropTableCommand: org.apache.spark.sql.AnalysisException:
Table or view not found: t;
org.apache.spark.sql.AnalysisException: Table or view not found: t;
```

## How was this patch tested?

Manual.

Author: Dongjoon Hyun <[email protected]>

Closes apache#19888 from dongjoon-hyun/SPARK-22686.
asfgit pushed a commit that referenced this pull request Dec 6, 2017
…tion

## What changes were proposed in this pull request?

During [SPARK-22488](#19713) to fix view resolution issue, there occurs a regression at `2.2.1` and `master` branch like the following. This PR fixes that.

```scala
scala> spark.version
res2: String = 2.2.1

scala> sql("DROP TABLE IF EXISTS t").show
17/12/04 21:01:06 WARN DropTableCommand: org.apache.spark.sql.AnalysisException:
Table or view not found: t;
org.apache.spark.sql.AnalysisException: Table or view not found: t;
```

## How was this patch tested?

Manual.

Author: Dongjoon Hyun <[email protected]>

Closes #19888 from dongjoon-hyun/SPARK-22686.

(cherry picked from commit 82183f7)
Signed-off-by: Wenchen Fan <[email protected]>
MatthewRBruce pushed a commit to Shopify/spark that referenced this pull request Jul 31, 2018
…tion

## What changes were proposed in this pull request?

During [SPARK-22488](apache#19713) to fix view resolution issue, there occurs a regression at `2.2.1` and `master` branch like the following. This PR fixes that.

```scala
scala> spark.version
res2: String = 2.2.1

scala> sql("DROP TABLE IF EXISTS t").show
17/12/04 21:01:06 WARN DropTableCommand: org.apache.spark.sql.AnalysisException:
Table or view not found: t;
org.apache.spark.sql.AnalysisException: Table or view not found: t;
```

## How was this patch tested?

Manual.

Author: Dongjoon Hyun <[email protected]>

Closes apache#19888 from dongjoon-hyun/SPARK-22686.

(cherry picked from commit 82183f7)
Signed-off-by: Wenchen Fan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants