xumingming commented on code in PR #1681:
URL: https://github.com/apache/auron/pull/1681#discussion_r2576594384


##########
native-engine/datafusion-ext-functions/src/spark_initcap.rs:
##########
@@ -0,0 +1,119 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+use std::sync::Arc;
+
+use arrow::array::{ArrayRef, StringArray};
+use datafusion::{
+    common::{Result, ScalarValue, cast::as_string_array},
+    logical_expr::ColumnarValue,
+};
+use datafusion_ext_commons::df_execution_err;
+
+pub fn string_initcap(args: &[ColumnarValue]) -> Result<ColumnarValue> {
+    match &args[0] {
+        ColumnarValue::Array(array) => {
+            let input_array = as_string_array(array)?;
+            let output_array =
+                StringArray::from_iter(input_array.into_iter().map(|s| 
s.map(|s| initcap(s))));
+            Ok(ColumnarValue::Array(Arc::new(output_array) as ArrayRef))
+        }
+        ColumnarValue::Scalar(ScalarValue::Utf8(Some(str))) => {
+            Ok(ColumnarValue::Scalar(ScalarValue::Utf8(Some(initcap(str)))))
+        }
+        _ => df_execution_err!("string_initcap only supports literal utf8"),

Review Comment:
   how about "string_initcap only accepts string input"?



##########
spark-extension-shims-spark/src/test/scala/org.apache.auron/AuronQuerySuite.scala:
##########
@@ -312,39 +312,56 @@ class AuronQuerySuite extends AuronQueryTest with 
BaseAuronSQLSuite with AuronSQ
   }
 
   test("initcap basic") {
-    Seq(
-      ("select initcap('spark sql')", Row("Spark Sql")),
-      ("select initcap('SPARK')", Row("Spark")),
-      ("select initcap('sPaRk')", Row("Spark")),
-      ("select initcap('')", Row("")),
-      ("select initcap(null)", Row(null))).foreach { case (q, expected) =>
-      checkAnswer(sql(q), Seq(expected))
+    withTable("initcap_basic_tbl") {
+      sql(s"CREATE TABLE initcap_basic_tbl(id INT, txt STRING) USING parquet")

Review Comment:
   It would better not to use parquet table to do testing, the test would fail 
on second run because it would create a directory on local disk, on second run, 
the directory name is already taken.
   
   Use temp view or something similar would be better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to