Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-12576][SQL] Enable expression parsing in CatalystQl #10649

Closed
wants to merge 10 commits into from

Conversation

hvanhovell
Copy link
Contributor

The PR allows us to use the new SQL parser to parse SQL expressions such as: 1 + sin(x*x)

We enable this functionality in this PR, but we will not start using this actively yet. This will be done as soon as we have reached grammar parity with the existing parser stack.

cc @rxin


/** Creates LogicalPlan for a given HiveQL string. */
def createPlan(sql: String): LogicalPlan = {
protected def safeParse[T](sql: String, ast: ASTNode, toResult: ASTNode => T): T = {
Copy link
Contributor

Choose a reason for hiding this comment

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

use multi parameter list?

protected  def safeParse[T](sql: String, ast: ASTNode)(toResult: ASTNode => T): T

then you can call it in a slightly nicer way

safeParse(sql, ParseDriver.parseExpression(sql, conf)) { ast =>
  ...
}

@SparkQA
Copy link

SparkQA commented Jan 7, 2016

Test build #48965 has finished for PR 10649 at commit 7f37d81.

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

@SparkQA
Copy link

SparkQA commented Jan 8, 2016

Test build #48983 has finished for PR 10649 at commit c2b35b7.

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

@SparkQA
Copy link

SparkQA commented Jan 8, 2016

Test build #49005 has finished for PR 10649 at commit b070bf9.

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

@SparkQA
Copy link

SparkQA commented Jan 8, 2016

Test build #49022 has finished for PR 10649 at commit bc0e298.

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

def parseExpression(sql: String): Expression =
safeParse(sql, ParseDriver.parseExpression(sql, conf))(selExprNodeToExpr(_).get)

/** Creates Expression for a given SQL string. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Expression -> TableIdentifier


/** Creates LogicalPlan for a given HiveQL string. */
def createPlan(sql: String): LogicalPlan = {
protected def safeParse[T](sql: String, ast: ASTNode)(toResult: ASTNode => T): T = {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a extra space before the def.

can you also add some doc explaining what this function does (e.g. what "safe" means)?

@yhuai
Copy link
Contributor

yhuai commented Jan 11, 2016

@cloud-fan can you also take a look?

@SparkQA
Copy link

SparkQA commented Jan 12, 2016

Test build #49184 has finished for PR 10649 at commit 81588d2.

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

@rxin
Copy link
Contributor

rxin commented Jan 12, 2016

I'm going to merge this. @cloud-fan it would be great for you to still take a look post-hoc and @hvanhovell can address feedback in his next pull request. Thanks.

@asfgit asfgit closed this in fe9eb0b Jan 12, 2016
assert(TableIdentifier("q", Some("d")) === parser.parseTableIdentifier("d.q"))
intercept[AnalysisException](parser.parseTableIdentifier(""))
// TODO parser swallows third identifier.
// intercept[AnalysisException](parser.parseTableIdentifier("d.q.g"))
Copy link
Contributor

Choose a reason for hiding this comment

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

are we going to support this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should support this. Are there use cases for this? I'll create a fix, that'll throw an AnalysisException when we encounter this.

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, throw exception seems reasonable to me

asfgit pushed a commit that referenced this pull request Feb 11, 2016
…xpression string

The parser currently parses the following strings without a hitch:
* Table Identifier:
  * `a.b.c` should fail, but results in the following table identifier `a.b`
  * `table!#` should fail, but results in the following table identifier `table`
* Expression
  * `1+2 r+e` should fail, but results in the following expression `1 + 2`

This PR fixes this by adding terminated rules for both expression parsing and table identifier parsing.

cc cloud-fan (we discussed this in #10649) jayadevanmurali (this causes your PR #11051 to fail)

Author: Herman van Hovell <hvanhovell@questtec.nl>

Closes #11159 from hvanhovell/SPARK-13276.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants