Skip to content

Commit 95cfd12

Browse files
authored
[AURON #1533] Implement native function of lpad, rpad. (#1534)
Signed-off-by: slfan1989 <slfan1989@apache.org>
1 parent a737fbf commit 95cfd12

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

spark-extension-shims-spark/src/test/scala/org/apache/spark/sql/auron/AuronQuerySuite.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,22 @@ class AuronQuerySuite
286286
}
287287
}
288288
}
289+
290+
test("lpad/rpad basic") {
291+
Seq(
292+
("select lpad('abc', 5, '*')", Row("**abc")),
293+
("select rpad('abc', 5, '*')", Row("abc**")),
294+
("select lpad('spark', 2, '0')", Row("sp")),
295+
("select rpad('spark', 2, '0')", Row("sp")),
296+
("select lpad('9', 5, 'ab')", Row("abab9")),
297+
("select rpad('9', 5, 'ab')", Row("9abab")),
298+
("select lpad('hi', 5, '')", Row("hi")),
299+
("select rpad('hi', 5, '')", Row("hi")),
300+
("select lpad('x', 0, 'a')", Row("")),
301+
("select rpad('x', -1, 'a')", Row("")),
302+
("select lpad('Z', 3, '++')", Row("++Z")),
303+
("select rpad('Z', 3, 'AB')", Row("ZAB"))).foreach { case (q, expected) =>
304+
checkAnswer(sql(q), Seq(expected))
305+
}
306+
}
289307
}

spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,11 @@ object NativeConverters extends Logging {
930930
val children = e.children.map(Cast(_, e.dataType))
931931
buildScalarFunction(pb.ScalarFunction.Coalesce, children, e.dataType)
932932

933+
case e: StringLPad =>
934+
buildScalarFunction(pb.ScalarFunction.Lpad, e.children, StringType)
935+
case e: StringRPad =>
936+
buildScalarFunction(pb.ScalarFunction.Rpad, e.children, StringType)
937+
933938
case e @ If(predicate, trueValue, falseValue) =>
934939
val castedTrueValue = trueValue match {
935940
case t if t.dataType != e.dataType => Cast(t, e.dataType)

0 commit comments

Comments
 (0)