Skip to content

Commit 5014b75

Browse files
authored
[AURON #1549] Implement native function of InitCap. (#1550)
Signed-off-by: slfan1989 <slfan1989@apache.org>
1 parent 16ee971 commit 5014b75

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,39 @@ class AuronQuerySuite
317317
checkAnswer(sql(q), Seq(expected))
318318
}
319319
}
320+
321+
test("initcap basic") {
322+
Seq(
323+
("select initcap('spark sql')", Row("Spark Sql")),
324+
("select initcap('SPARK')", Row("Spark")),
325+
("select initcap('sPaRk')", Row("Spark")),
326+
("select initcap('')", Row("")),
327+
("select initcap(null)", Row(null))).foreach { case (q, expected) =>
328+
checkAnswer(sql(q), Seq(expected))
329+
}
330+
}
331+
332+
test("initcap: word boundaries and punctuation") {
333+
Seq(
334+
("select initcap('hello world')", Row("Hello World")),
335+
("select initcap('hello_world')", Row("Hello_world")),
336+
("select initcap('über-alles')", Row("Über-alles")),
337+
("select initcap('foo.bar/baz')", Row("Foo.bar/baz")),
338+
("select initcap('v2Ray is COOL')", Row("V2ray Is Cool")),
339+
("select initcap('rock''n''roll')", Row("Rocknroll")),
340+
("select initcap('hi\\tthere')", Row("Hi\tthere")),
341+
("select initcap('hi\\nthere')", Row("Hi\nthere"))).foreach { case (q, expected) =>
342+
checkAnswer(sql(q), Seq(expected))
343+
}
344+
}
345+
346+
test("initcap: mixed cases and edge cases") {
347+
Seq(
348+
("select initcap('a1b2 c3D4')", Row("A1b2 C3d4")),
349+
("select initcap('---abc---')", Row("---abc---")),
350+
("select initcap(' multiple spaces ')", Row(" Multiple Spaces "))).foreach {
351+
case (q, expected) =>
352+
checkAnswer(sql(q), Seq(expected))
353+
}
354+
}
320355
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ object NativeConverters extends Logging {
858858
buildScalarFunction(pb.ScalarFunction.MD5, Seq(unpackBinaryTypeCast(_1)), StringType)
859859
case Reverse(_1) =>
860860
buildScalarFunction(pb.ScalarFunction.Reverse, Seq(unpackBinaryTypeCast(_1)), StringType)
861+
case InitCap(_1) =>
862+
buildScalarFunction(pb.ScalarFunction.InitCap, Seq(unpackBinaryTypeCast(_1)), StringType)
861863
case Sha2(_1, Literal(224, _)) =>
862864
buildExtScalarFunction("Sha224", Seq(unpackBinaryTypeCast(_1)), StringType)
863865
case Sha2(_1, Literal(0, _)) =>

0 commit comments

Comments
 (0)