GitHub user cloud-fan opened a pull request:
https://github.com/apache/spark/pull/2230
SPARK-2096 Correctly parse dot notations
First let me write down the current `projections` grammar of spark sql:
expression : orExpression
orExpression : andExpression {"or" andExpression}
andExpression : comparisonExpression {"and"
comparisonExpression}
comparisonExpression : termExpression | termExpression "="
termExpression | termExpression ">" termExpression | ...
termExpression : productExpression {"+"|"-"
productExpression}
productExpression : baseExpression {"*"|"/"|"%" baseExpression}
baseExpression : expression "[" expression "]" | "("
expression ")" | ident | ...
ident : identChar {identChar | digit} | delimiters
| ...
identChar : letter | "_" | "."
delimiters : "," | ";" | "(" | ")" | "[" | "]" | ...
projection : expression [["AS"] ident]
projections : projection { "," projection}
For something like `a.b.c[1]`, it will be parsed as:
<img src="http://img51.imgspice.com/i/03008/4iltjsnqgmtt_t.jpg" border=0>
But for something like `a[1].b`, the current grammar can't parse it
correctly.
A simple solution is written in `ParquetQuerySuite#NestedSqlParser`,
changed grammars are:
identChar : letter | "_"
baseExpression : expression "[" expression "]" | expression
"." ident | "(" expression ")" | ident | ...
This works well, but can't cover some corner case like `select t.a.b from
table as t`:
<img src="http://img51.imgspice.com/i/03008/v2iau3hoxoxg_t.jpg" border=0>
`t.a.b` parsed as `GetField(GetField(UnResolved("t"), "a"), "b")` instead
of `GetField(UnResolved("t.a"), "b")` using this new grammar.
However, we can't resolve `t` as it's not a filed, but the whole table.(if
we could do this, then `select t from table as t` is legal, which is unexpected)
My solution is:
dotExpressionHeader : ident "." ident
baseExpression : expression "[" expression "]" |
dotExpressionHeader | expression "." ident | "(" expression ")" | ident | ...
I passed all test cases under sql locally and add a more complex case.
I'm not familiar with the latter optimize phase, please correct me if I
missed something.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cloud-fan/spark dot
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/2230.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 #2230
----
commit de630829028d9d4a7ef55b8a0ff31e09f0b549d9
Author: Wenchen Fan <[email protected]>
Date: 2014-09-01T11:10:02Z
SPARK-2096 Correctly parse dot notations
----
---
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]