twalthr commented on a change in pull request #16691:
URL: https://github.com/apache/flink/pull/16691#discussion_r686744132



##########
File path: 
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/SymbolArgumentTypeStrategy.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.table.types.inference.strategies;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.expressions.TableSymbol;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.ArgumentTypeStrategy;
+import org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.inference.Signature;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.SymbolType;
+
+import java.util.Objects;
+import java.util.Optional;
+
+/** Strategy for a symbol argument of a specific {@link TableSymbol} enum. */
+@Internal
+public class SymbolArgumentTypeStrategy implements ArgumentTypeStrategy {

Review comment:
       add a test

##########
File path: 
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonExistsFunctionITCase.java
##########
@@ -47,6 +47,17 @@
         }
 
         final String jsonValue = IOUtils.toString(jsonResource, 
Charset.defaultCharset());
+        if (1 + 1 > 0) {

Review comment:
       typo ;-)

##########
File path: 
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonExistsFunctionITCase.java
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.table.planner.functions;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.JsonExistsOnError;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.runners.Parameterized;
+
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.table.api.Expressions.$;
+import static org.apache.flink.table.api.Expressions.nullOf;
+
+/** Tests for {@link BuiltInFunctionDefinitions#JSON_EXISTS}. */
+public class JsonExistsFunctionITCase extends BuiltInFunctionTestBase {
+
+    @Parameterized.Parameters(name = "{index}: {0}")
+    public static List<TestSpec> testData() throws Exception {
+        final InputStream jsonResource =
+                
JsonExistsFunctionITCase.class.getResourceAsStream("/json/json-exists.json");
+        if (jsonResource == null) {
+            throw new IllegalStateException(
+                    String.format(
+                            "%s: Missing test data.", 
JsonExistsFunctionITCase.class.getName()));
+        }
+
+        final String jsonValue = IOUtils.toString(jsonResource, 
Charset.defaultCharset());
+        if (1 + 1 > 0) {
+            return Arrays.asList(
+                    
TestSpec.forFunction(BuiltInFunctionDefinitions.JSON_EXISTS)
+                            .onFieldsWithData(jsonValue)
+                            .andDataTypes(DataTypes.STRING())
+                            .testSqlResult(
+                                    "JSON_EXISTS('{\"a\": true}', 'strict $.b' 
FALSE ON ERROR)",
+                                    false,
+                                    DataTypes.BOOLEAN()));
+        }
+
+        return Arrays.asList(
+                TestSpec.forFunction(BuiltInFunctionDefinitions.JSON_EXISTS)
+                        .onFieldsWithData(jsonValue)
+                        .andDataTypes(DataTypes.STRING())
+
+                        // NULL
+                        .testResult(
+                                nullOf(DataTypes.STRING()).jsonExists("lax $"),
+                                "JSON_EXISTS(CAST(NULL AS STRING), 'lax $')",
+                                null,
+                                DataTypes.BOOLEAN())
+
+                        // Path variants
+                        .testResult(
+                                $("f0").jsonExists("lax $"),
+                                "JSON_EXISTS(f0, 'lax $')",
+                                true,
+                                DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("lax $.type"),
+                                "JSON_EXISTS(f0, 'lax $.type')",
+                                true,
+                                DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("lax 
$.author.address.city"),
+                                "JSON_EXISTS(f0, 'lax $.author.address.city')",
+                                true,
+                                DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("lax $.metadata.tags[0]"),
+                                "JSON_EXISTS(f0, 'lax $.metadata.tags[0]')",
+                                true,
+                                DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("lax $.metadata.tags[3]"),
+                                "JSON_EXISTS(f0, 'lax $.metadata.tags[3]')",
+                                false,
+                                DataTypes.BOOLEAN())
+                        // This should pass, but is broken due to
+                        // https://issues.apache.org/jira/browse/CALCITE-4717.
+                        // .testResult(
+                        //        $("f0").jsonExists("lax 
$.metadata.references.url"),
+                        //        "JSON_EXISTS(f0, 'lax 
$.metadata.references.url')",
+                        //        true,
+                        //        DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("lax 
$.metadata.references[0].url"),
+                                "JSON_EXISTS(f0, 'lax 
$.metadata.references[0].url')",
+                                true,
+                                DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("lax 
$.metadata.references[0].invalid"),
+                                "JSON_EXISTS(f0, 'lax 
$.metadata.references[0].invalid')",
+                                false,
+                                DataTypes.BOOLEAN())
+
+                        // ON ERROR
+                        .testResult(
+                                $("f0").jsonExists("strict $.invalid", 
JsonExistsOnError.TRUE),
+                                "JSON_EXISTS(f0, 'strict $.invalid' TRUE ON 
ERROR)",
+                                true,
+                                DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("strict $.invalid", 
JsonExistsOnError.FALSE),
+                                "JSON_EXISTS(f0, 'strict $.invalid' FALSE ON 
ERROR)",
+                                false,
+                                DataTypes.BOOLEAN())
+                        .testResult(
+                                $("f0").jsonExists("strict $.invalid", 
JsonExistsOnError.UNKNOWN),
+                                "JSON_EXISTS(f0, 'strict $.invalid' UNKNOWN ON 
ERROR)",

Review comment:
       `ERROR ON ERROR` is not tested.

##########
File path: docs/data/sql_functions.yml
##########
@@ -580,9 +580,20 @@ json:
       This follows the ISO/IEC TR 19075-6 specification for JSON support in 
SQL.
 
       ```
-      SELECT JSON_EXISTS(
-        '{"items": [{"name": "Item 1"}]}',
-        'lax $.items[0].name' TRUE ON ERROR);
+      // TRUE

Review comment:
       I'm still not happy with the docs. As someone from outside, I still have 
a couple of questions. This doc should answer:
   
   - Which path modes exists?
   - What is the default path mode?
   - What does every mode mean?
   - The example implicitly shows that `FALSE ON ERROR` is the default strategy 
but we should mention this explicitly as well.




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