Skip to content
Snippets Groups Projects
Commit 04d55d8e authored by Reynold Xin's avatar Reynold Xin Committed by Michael Armbrust
Browse files

[SPARK-5040][SQL] Support expressing unresolved attributes using $"attribute...

[SPARK-5040][SQL] Support expressing unresolved attributes using $"attribute name" notation in SQL DSL.

Author: Reynold Xin <rxin@databricks.com>

Closes #3862 from rxin/stringcontext-attr and squashes the following commits:

9b10f57 [Reynold Xin] Rename StrongToAttributeConversionHelper
72121af [Reynold Xin] [SPARK-5040][SQL] Support expressing unresolved attributes using $"attribute name" notation in SQL DSL.
parent bbcba3a9
No related branches found
No related tags found
No related merge requests found
......@@ -135,6 +135,15 @@ package object dsl {
implicit def symbolToUnresolvedAttribute(s: Symbol): analysis.UnresolvedAttribute =
analysis.UnresolvedAttribute(s.name)
/** Converts $"col name" into an [[analysis.UnresolvedAttribute]]. */
implicit class StringToAttributeConversionHelper(val sc: StringContext) {
// Note that if we make ExpressionConversions an object rather than a trait, we can
// then make this a value class to avoid the small penalty of runtime instantiation.
def $(args: Any*): analysis.UnresolvedAttribute = {
analysis.UnresolvedAttribute(sc.s(args :_*))
}
}
def sum(e: Expression) = Sum(e)
def sumDistinct(e: Expression) = SumDistinct(e)
def count(e: Expression) = Count(e)
......
......@@ -56,6 +56,18 @@ class DslQuerySuite extends QueryTest {
)
}
test("convert $\"attribute name\" into unresolved attribute") {
checkAnswer(
testData.where($"key" === 1).select($"value"),
Seq(Seq("1")))
}
test("convert Scala Symbol 'attrname into unresolved attribute") {
checkAnswer(
testData.where('key === 1).select('value),
Seq(Seq("1")))
}
test("select *") {
checkAnswer(
testData.select(Star(None)),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment