Skip to content

Commit

Permalink
[SPARK-9154][SQL] build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekbecker committed Jul 21, 2015
1 parent 1487602 commit dcae272
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,17 @@ object functions {
*/
def rtrim(e: Column): Column = StringTrimRight(e.expr)

/**
* Format strings in printf-style.
*
* @group string_funcs
* @since 1.5.0
*/
@scala.annotation.varargs
def formatString(format: Column, arguments: Column*): Column = {
StringFormat((format +: arguments).map(_.expr): _*)
}

/**
* Format strings in printf-style.
* NOTE: `format` is the string value of the formatter, not column name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ class StringFunctionsSuite extends QueryTest {
checkAnswer(
df.selectExpr("printf(a, b, c)"),
Row("aa123cc"))

val df2 = Seq(("aa%d%s".getBytes, 123, "cc")).toDF("a", "b", "c")

checkAnswer(
df2.select(formatString($"a", $"b", $"c"), formatString("aa%d%s", "b", "c")),
Row("aa123cc", "aa123cc"))

checkAnswer(
df2.selectExpr("printf(a, b, c)"),
Row("aa123cc"))
}

test("string instr function") {
Expand Down

0 comments on commit dcae272

Please sign in to comment.