alamb commented on code in PR #21353:
URL: https://github.com/apache/datafusion/pull/21353#discussion_r3477019701


##########
datafusion/functions-json/src/json_get_str.rs:
##########
@@ -0,0 +1,512 @@
+// 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.
+
+//! [`JsonGetStr`] UDF implementation for extracting string values from JSON.
+
+use arrow::array::{Array, AsArray, StringArray, StringBuilder};
+use arrow::datatypes::DataType;
+use datafusion_common::{Result, ScalarValue, exec_err, plan_err};
+use datafusion_expr::{
+    ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature,
+    TypeSignature, Volatility,
+};
+use datafusion_macros::user_doc;
+use std::sync::Arc;
+
+#[user_doc(
+    doc_section(label = "JSON Functions"),
+    description = r#"Extract a string value from a JSON string at the given 
path.
+
+The path is specified as zero or more keys (strings for object access) or
+indices (integers for array access). With no path keys, the function returns
+the JSON value itself if it is a string (jq `.` semantics). Otherwise, the
+function navigates into the JSON document and returns the value at the path.
+
+Returns NULL if the input JSON is not a valid JSON string, the path does not
+exist, the value at the path is not a string, or any argument (input JSON or
+path key) is NULL. Invalid JSON is silently treated as NULL — no error is
+returned."#,
+    syntax_example = "json_get_str(json_string [, key1, key2, ...])",
+    sql_example = r#"```sql
+> select json_get_str('{"a": {"b": "hello"}}', 'a', 'b');
++-----------------------------------------------------------+
+| json_get_str(Utf8("{"a": {"b": "hello"}}"),Utf8("a"),Utf8("b")) |

Review Comment:
   I know you are just porting stuff from the existing json crate, but I when 
trying to find precedent for this  functions it is in neither duckDB or Spark
   
   https://spark.apache.org/docs/preview/api/sql/json-functions/
   https://duckdb.org/docs/lts/data/json/json_functions
   https://www.postgresql.org/docs/9.5/functions-json.html
   
   
   I think we should sort out which functions we want to provide, rather than 
just blindly copy over the functions from the existing crate



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to