Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ package object dsl {

implicit def symbolToUnresolvedAttribute(s: Symbol) = 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)
Expand Down
12 changes: 12 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/DslQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down