MartijnVisser commented on code in PR #30033:
URL: https://github.com/apache/flink/pull/30033#discussion_r4640898748


##########
docs/data/functions/json/json_array.yml:
##########
@@ -0,0 +1,91 @@
+# 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
+
+name: JSON_ARRAY
+summary: Returns a JSON array built from its arguments.
+
+syntax:
+  sql: JSON_ARRAY([expr [, ...]] [{NULL | ABSENT} ON NULL])
+  java: jsonArray(JsonOnNull.ABSENT, expr1, expr2, ...)
+  python: json_array(JsonOnNull.ABSENT, expr1, expr2, ...)

Review Comment:
   This call fails in PyFlink: py4j doesn't pack Java varargs, so it reports 
`Method jsonArray(...) does not exist`. Same for `json_object`. I think it's 
better to leave it out, like DESCRIPTOR.



##########
docs/data/functions/comparison/like.yml:
##########
@@ -0,0 +1,101 @@
+# 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
+
+name: LIKE
+summary: Returns whether a string matches a pattern with the wildcards `%` and 
`_`.
+
+syntax:
+  sql: string [NOT] LIKE pattern [ESCAPE escape_char]
+  java: |
+    $("string").like(pattern)
+    $("string").like(pattern, escapeChar)
+  python: |
+    col("string").like(pattern)
+    col("string").like(pattern, escape_char)
+
+arguments:
+  - name: string
+    type: CHAR, VARCHAR, STRING
+    required: true
+    description: The string to test.
+  - name: pattern
+    type: CHAR, VARCHAR, STRING
+    required: true
+    description: The pattern. `%` matches any number of characters, and `_` 
exactly one.

Review Comment:
   `_` doesn't match a newline, while `%` does: `'a' || CHR(10) || 'b' LIKE 
'a_b'` is FALSE, because `SqlLikeUtils` turns `_` into `.` without DOTALL. 
That's a bug for Jira, and a note here.



##########
docs/content/docs/sql/built-in-functions/variant/xml.md:
##########
@@ -0,0 +1,245 @@
+---
+title: "XML and VARIANT"
+type: docs
+---
+<!--
+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.
+-->
+
+# XML and VARIANT
+
+`PARSE_XML` and `TRY_PARSE_XML` map an XML document to a `VARIANT`, and 
`XML_STRING` maps a `VARIANT` back to XML. This page describes both mappings.
+
+## XML to VARIANT
+
+The `PARSE_XML` function maps the root element of an XML document to a 
`VARIANT` object. For
+example:
+
+```sql
+-- 
{"book":{"#":{"price":[1,2],"title":0},"@pages":"320","price":["12.50","13.50"],"title":"Dune"}}
+PARSE_XML('<book 
pages="320"><title>Dune</title><price>12.50</price><price>13.50</price></book>')
+```
+
+Attributes become fields with an `@` prefix, and a child element that occurs 
more than once becomes
+an array. The `#` field records the order of the children, as described below. 
It can be ignored
+when reading fields.
+
+Values are strings, unless the document declares a type with `xsi:type`, see 
below. Since a cast
+from a `VARIANT` never parses a string, cast a value to `STRING` first and 
convert it with a regular
+cast:
+
+```sql
+CAST(v['book']['title'] AS STRING)                -- 'Dune'
+CAST(v['book']['price'][2] AS STRING)             -- '13.50'
+CAST(CAST(v['book']['@pages'] AS STRING) AS INT)  -- 320
+```
+
+Each element is mapped by the following rules:
+
+| XML input                                                          | Stored 
`VARIANT` value                                      |
+|--------------------------------------------------------------------|-------------------------------------------------------------|
+| Element with `xsi:nil="true"`                                      | `null`, 
or field `$` with `null` if it has other attributes |
+| Element without attributes and child elements                      | its 
text, or `""` if it is empty                            |
+| Any other element                                                  | object  
                                                    |
+| Attribute `name`                                                   | field 
`@name`, a `STRING`                                   |
+| Child element `name`                                               | field 
`name`                                                |
+| Text of an element with attributes or child elements               | field 
`$`                                                   |
+| Child element or text that occurs more than once                   | array, 
in document order                                    |
+| Element with differently named children, or with children and text | field 
`#` with the order of its content                     |
+
+A `VARIANT` object doesn't keep the order of its fields, so the `#` field 
records it. It maps each
+key to the position of its item, or to an array of positions if the key occurs 
more than once.
+Positions count the child elements and texts of the element, starting at 0. 
For example:
+
+```sql
+-- {"book":{"#":{"$":[1,3],"price":[2,4],"title":0},
+--          "$":["This is a description","Text in between"],
+--          "@pages":"320",
+--          "price":["12.50",{"$":"13.50","@currency":"EUR"}],
+--          "title":"Dune"}}
+PARSE_XML('
+  <book pages="320">
+    <title>Dune</title>
+    This is a description
+    <price>12.50</price>
+    Text in between
+    <price currency="EUR">13.50</price>
+  </book>')
+```
+
+Here, `title` is the first item, the two texts are the second and the fourth, 
and the two `price`
+elements are the third and the fifth. The second `price` has an attribute, so 
it is stored as an
+object, while the first one is a string. An element whose content has only one 
key has no `#` field,
+since the order of an array is the document order.
+
+Whether a child element is stored as a single value or as an array depends on 
how often it occurs,
+so two documents that follow the same schema can map to different shapes. The 
default behavior
+ensures a space-efficient representation. With `PARSE_XML(xml, TRUE)`, every 
child element, text,
+and position in a `#` field is stored as an array, even if it occurs only 
once. The root element is never wrapped, since a document has exactly one.
+
+```sql
+-- {"book":{"title":["Dune"]}}
+PARSE_XML('<book><title>Dune</title></book>', TRUE)
+```
+
+An `xsi:type` attribute parses the text of an element as the matching kind, 
which replaces the text,
+or the `$` field if the element has other attributes. The prefix of the type 
is ignored, so `xs:int`,
+`xsd:int`, and `int` are the same type. If the element has child elements or 
no text, the type isn't
+listed below, or the text isn't a valid value of the type, the text stays a 
`STRING` and `xsi:type`
+is kept as an attribute. For example, `<a xsi:type="int">5</a>` maps to 
`{"a":5}`, and
+`<a xsi:type="int">five</a>` maps to `{"a":{"$":"five","@xsi:type":"int"}}`. 
The text has to be in
+the lexical form that XML Schema defines for the type, so `1e5` isn't a 
`decimal`, `1f` isn't a
+`float`, and `12:30` isn't a `time`. Years after 9999 and the time `24:00:00` 
stay a `STRING` as well.
+For a `dateTime` with an offset, this checks both the year in the text and the 
year in UTC. So
+`10000-01-01T00:00:00+14:00` stays a `STRING`, and so does 
`9999-12-31T23:00:00-08:00`, which is
+`10000-01-01 07:00:00` in UTC.
+
+| `xsi:type`                   | Stored `VARIANT` kind                        |
+|------------------------------|----------------------------------------------|
+| `string`                     | `STRING`                                     |
+| `boolean`                    | `BOOLEAN`, from `true`, `false`, `1`, or `0` |
+| `byte`                       | `TINYINT`                                    |
+| `short`                      | `SMALLINT`                                   |
+| `int`                        | `INT`                                        |
+| `long`                       | `BIGINT`                                     |
+| `integer`, `decimal`         | `DECIMAL`, with at most 38 digits            |
+| `float`                      | `FLOAT`, except for `NaN` and infinity       |
+| `double`                     | `DOUBLE`, except for `NaN` and infinity      |
+| `date` without an offset     | `DATE`                                       |
+| `time` without an offset     | `TIME`                                       |
+| `dateTime` with an offset    | `TIMESTAMP_LTZ`                              |
+| `dateTime` without an offset | `TIMESTAMP`                                  |
+| `base64Binary`               | `BYTES`                                      |
+
+`float` and `double` keep the sign of zero, so `-0` maps to `-0.0`. The other 
numeric types have no
+negative zero, so `-0` maps to `0`.
+
+The offset of a `dateTime` is `Z` or a signed `hh:mm` of at most 14 hours. It 
is used to compute the
+instant and isn't stored, since a `TIMESTAMP_LTZ` has no offset. For example,
+`2026-09-30T12:30:00+02:00`, `2026-09-30T10:30:00Z`, and 
`2026-09-30T06:00:00-04:30` map to the same
+`TIMESTAMP_LTZ`. A `date` or `time` with an offset stays a `STRING`, since it 
can't be converted to an
+instant without a date or a time.
+
+`TIME` keeps microseconds, so `12:30:45.1234567` is stored as 
`12:30:45.123456`. `TIMESTAMP` and
+`TIMESTAMP_LTZ` keep nanoseconds if the value has digits below a microsecond 
and is in the
+nanosecond range. A 64-bit count of nanoseconds since `1970-01-01 00:00:00` 
UTC covers
+`1677-09-21 00:12:43.145224192` to `2262-04-11 23:47:16.854775807` UTC. A 
`dateTime` without an

Review Comment:
   The lower bound loses its nanoseconds: this value reads back as `1677-09-21 
00:12:43.145224`, and so does anything before 00:12:44. I think 
`ChronoUnit.NANOS.between` in `BinaryVariantUtil` overflows there.



##########
docs/data/functions/json/json_exists.yml:
##########
@@ -0,0 +1,107 @@
+# 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
+
+name: JSON_EXISTS
+summary: Returns whether a JSON path finds a value in a JSON string.
+
+syntax:
+  sql: JSON_EXISTS(jsonValue, path [{TRUE | FALSE | UNKNOWN | ERROR} ON ERROR])
+  java: |
+    $("jsonValue").jsonExists(path)
+    $("jsonValue").jsonExists(path, JsonExistsOnError.TRUE)
+  python: |
+    col("jsonValue").json_exists(path)
+    col("jsonValue").json_exists(path, JsonExistsOnError.TRUE)
+
+arguments:
+  - name: jsonValue
+    type: CHAR, VARCHAR, STRING
+    required: true
+    description: The JSON text.
+  - name: path
+    type: A string literal

Review Comment:
   In SQL a column works too: `JSON_EXISTS(j, p)` over VALUES returns TRUE and 
FALSE. Only the Table API needs a literal. JSON_VALUE and JSON_QUERY list CHAR, 
VARCHAR, STRING for the same argument.



##########
docs/README.md:
##########
@@ -314,6 +314,8 @@ Every page has the same sections, in this order. A section 
is left out when the
 
 NULL handling has no section of its own. It goes into Returns, and the 
examples show it.
 
+Name an argument that takes any expression `expr`, or `expr1`, `expr2` when 
there are several, as other engines do: `expr1 = expr2`, `LAG(expr [, n])`. 
Give an argument with a fixed type or role a name that says so, such as `str`, 
`pattern` or `lower_bound`. The Java tab writes the same names in camelCase. 
Don't name an argument or an alias in an example after an SQL keyword, such as 
`type`, `key` or `default`. The syntax highlighter colors those like SQL, so 
write `data_type`, `field_name` or `default_value` instead.

Review Comment:
   The SQL syntax of eight new pages uses `jsonValue`, `hashLength` and 
`returnType`, while this asks for names like `lower_bound` there. Should those 
become `json_value`, `hash_length` and `return_type`?



##########
docs/data/functions/json/json_length.yml:
##########
@@ -0,0 +1,101 @@
+# 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
+
+name: JSON_LENGTH
+summary: Returns the number of elements of a JSON array or of fields of a JSON 
object.
+
+syntax:
+  sql: JSON_LENGTH(jsonValue [, path])
+  java: |
+    $("jsonValue").jsonLength()
+    $("jsonValue").jsonLength(path)
+  python: |
+    col("jsonValue").json_length()
+    col("jsonValue").json_length(path)
+
+arguments:
+  - name: jsonValue
+    type: CHAR, VARCHAR, STRING, VARIANT
+    required: true
+    description: The JSON text, or a `VARIANT` such as a result of 
`PARSE_JSON`.
+  - name: path
+    type: A string literal
+    required: false
+    default: "`'$'`"
+    description: A JSON path without a `lax` or `strict` mode. See [JSON 
functions]({{< ref "docs/sql/built-in-functions/json" >}}) for the syntax.
+
+returns:
+  description: The number of fields of an object or of elements of an array, 
at `path` or of the whole value. A scalar has length 1, also a JSON `null`.
+  nulls: Returns NULL if `jsonValue` is NULL or isn't valid JSON, or if `path` 
finds no value or more than one.

Review Comment:
   Content after the first value is ignored here, as on the IS JSON page: 
`JSON_LENGTH('[1,2] x')` returns 2, and `JSON_TYPE('{"a":1} x')` returns 
`object`.



##########
docs/data/sql_functions_zh.yml:
##########
@@ -16,140 +16,96 @@
 # under the License
 
 comparison:
-  - sql: value1 = value2
-    table: value1 === value2
-    description: 如果 value1 等于 value2 返回 `TRUE`;如果 value1 或者 value2 为 `NULL` 返回 
`UNKNOW`。
-  - sql: value1 <> value2
-    table: value1 !== value2
-    description: 如果 value1 不等于 value2 返回 `TRUE`;如果 value1 或 value2 为 `NULL` 返回 
`UNKNOWN`。
-  - sql: value1 > value2
-    table: value1 > value2
-    description: 如果 value1 大于 value2 返回 `TRUE`;如果 value1 或 value2 为 `NULL` 返回 
`UNKNOWN`。
-  - sql: value1 >= value2
-    table: value1 >= value2
-    description: 如果 value1 大于或等于 value2 返回 `TRUE`;如果 value1 或 value2 为 `NULL` 
返回 `UNKNOWN`。
-  - sql: value1 < value2
-    table: value1 < value2
-    description: 如果 value1 小于 value2 返回 `TRUE`;如果 value1 或 value2 为 `NULL` 返回 
`UNKNOWN`。
-  - sql: value1 <= value2
-    table: value1 <= value2
-    description: 如果 value1 小于或等于 value2 返回 `TRUE`;如果 value1 或 value2 为 `NULL` 
返回 `UNKNOWN`。
-  - sql: value IS NULL
-    table: value.isNull
-    description: 如果值为 `NULL` 返回 `TRUE`。
-  - sql: value IS NOT NULL
-    table: value.isNotNull
-    description: 如果值不为 `NULL` 返回 `TRUE`。
+  - sql: expr BETWEEN [ ASYMMETRIC | SYMMETRIC ] lower_bound AND upper_bound

Review Comment:
   This drops about 1,600 characters of Chinese text from these five 
categories, and FLINK-41529 only covers the previous five. Could you extend it 
or open a translation ticket for these?



##########
docs/data/functions/variant/variant_subscript.yml:
##########
@@ -0,0 +1,108 @@
+# 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
+
+name: VARIANT subscript
+summary: Returns the element at an index of a `VARIANT` array, or the field 
with a name of a `VARIANT` object.
+
+syntax:
+  sql: |
+    variant[n]
+    variant[field_name]
+  java: |
+    $("variant").at(n)
+    $("variant").at(fieldName)
+  python: |
+    col("variant").at(n)
+    col("variant").at(field_name)
+
+arguments:
+  - name: variant
+    type: VARIANT
+    required: true
+    description: An array or an object.
+  - name: n

Review Comment:
   YAML reads an unquoted `n` as a boolean, so the Arguments table renders 
`false` here. LAG and LEAD show the same since the rename, and NTILE already 
did. Quoting it as `"n"` fixes it.



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