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


##########
docs/data/functions/collection/map_subscript.yml:
##########
@@ -0,0 +1,86 @@
+# 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: MAP subscript
+summary: Returns the value of a key in a map.
+
+syntax:
+  sql: m[key_expr]
+  java: $("m").at(keyExpr)
+  python: col("m").at(key_expr)
+
+arguments:
+  - name: m
+    type: A map
+    required: true
+    description: The map to read from.
+  - name: key_expr
+    type: A value of the same kind as the keys of `m`
+    required: true
+    description: The key to look up, such as a number for numeric keys or a 
string for string keys.
+
+returns:
+  description: The value of `key_expr` in `m`.
+  nulls: Returns NULL if `m` or `key_expr` is NULL, if `m` has no key 
`key_expr`, or if its value is NULL.

Review Comment:
   On a MAP<INT, STRING> from STR_TO_MAP or a format, a DOUBLE key of 1.5 
returns the value of key 1, and so does a BIGINT 4294967297. I think that's 
worth a note.



##########
docs/data/functions/row-and-structured-types/object_of.yml:
##########
@@ -0,0 +1,116 @@
+# 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: OBJECT_OF
+summary: Returns a structured object of a class, with a field for each 
name-value pair.
+
+syntax:
+  sql: OBJECT_OF(class_name [, field_name, expr]*)
+  java: objectOf(className, fieldName, $("expr"), ...)
+
+arguments:
+  - name: class_name
+    type: A string literal
+    required: true
+    description: The name of the class, such as `'com.example.User'`. It must 
be a valid Java class name, but the class doesn't have to exist. In Java, a 
`Class` such as `User.class` works too.
+  - name: field_name
+    type: A string literal
+    required: false
+    description: The name of a field. Names are case-sensitive, and each name 
can occur once.
+  - name: expr
+    type: Any type
+    required: false
+    description: The value of the field named before it.
+
+returns:
+  description: An object of class `class_name` with a field for each pair, in 
the order of the pairs. Each field has the type of its value.
+  nulls: Never returns NULL. A NULL value gives a NULL field.
+  type: "`STRUCTURED` of class `class_name` with a field of the type of each 
`expr`, nullable."
+
+notes:
+  - If the class is on the classpath, a Java program that collects the result 
receives instances of it, and the pairs must match the fields of the class, or 
the query fails. Otherwise, the program receives a `Row`.

Review Comment:
   This doesn't match master. With a User class on the classpath the pairs 
aren't checked and are mapped by position, so `'name', name, 'age', age` 
collects as `age=1667853377`. The note should say that.



##########
docs/data/functions/collection/array_contains.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: ARRAY_CONTAINS
+summary: Returns whether an array holds an element equal to a value.
+
+syntax:
+  sql: ARRAY_CONTAINS(arr, needle)
+  java: $("arr").arrayContains(needle)
+  python: col("arr").array_contains(needle)
+
+arguments:
+  - name: arr
+    type: An array
+    required: true
+    description: The array to search.
+  - name: needle
+    type: A value of the element type of `arr`
+    required: true
+    description: The value to look for.
+
+returns:
+  description: TRUE if an element of `arr` equals `needle`, FALSE otherwise, 
also for an empty array. A NULL `needle` looks for a NULL element, so it 
returns TRUE if `arr` holds a NULL element and FALSE if not.
+  nulls: Returns NULL if `arr` is NULL.
+  type: "`BOOLEAN`, NOT NULL if `arr` is NOT NULL."
+
+notes:
+  - "`needle` is cast to the element type of `arr` first, so a longer string 
is cut and a number is rounded to the element's scale: 
`ARRAY_CONTAINS(ARRAY['USA', 'CAN'], 'CANADA')` returns TRUE instead of FALSE. 
A number too large for the element type becomes NULL, so it returns TRUE for an 
array that holds a NULL element. A `needle` that doesn't cast implicitly fails 
the statement, such as a `STRING` column against `ARRAY['US', 'CA']`, whose 
elements are `CHAR(2)`, or a `BIGINT` against an `ARRAY<INT>`."

Review Comment:
   ARRAY_CONTAINS loses the cast inside UNNEST too: a DECIMAL(5, 2) needle 
returns FALSE instead of TRUE. ARRAY_SLICE with a SMALLINT offset fails there. 
Neither page has the note.



##########
docs/data/functions/collection/map_keys.yml:
##########
@@ -0,0 +1,85 @@
+# 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: MAP_KEYS
+summary: Returns an array of the keys of a map.
+
+syntax:
+  sql: MAP_KEYS(m)
+  java: $("m").mapKeys()
+  python: col("m").map_keys
+
+arguments:
+  - name: m
+    type: A map
+    required: true
+    description: The map to read the keys of.
+
+returns:
+  description: The keys of `m`, one element for each entry. A NULL key is a 
NULL element. An empty map gives an empty array.
+  nulls: Returns NULL if `m` is NULL.
+  type: "`ARRAY` of the key type of `m`, NOT NULL if `m` is NOT NULL."
+
+notes:
+  - The keys aren't sorted. They come in the order of the entries of `m`, the 
order in which `m` prints. MAP_VALUES and MAP_ENTRIES use the same order, so 
`MAP_KEYS(m)[i]` is the key of `MAP_VALUES(m)[i]`.

Review Comment:
   The PyFlink docstrings still say no order is guaranteed, and a Java 
`collect()` gives a HashMap in another order. Might make sense to only promise 
that the three functions use the same order?



##########
docs/data/functions/collection/map_subscript.yml:
##########
@@ -0,0 +1,86 @@
+# 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: MAP subscript
+summary: Returns the value of a key in a map.
+
+syntax:
+  sql: m[key_expr]
+  java: $("m").at(keyExpr)
+  python: col("m").at(key_expr)
+
+arguments:
+  - name: m
+    type: A map
+    required: true
+    description: The map to read from.
+  - name: key_expr
+    type: A value of the same kind as the keys of `m`
+    required: true
+    description: The key to look up, such as a number for numeric keys or a 
string for string keys.
+
+returns:
+  description: The value of `key_expr` in `m`.
+  nulls: Returns NULL if `m` or `key_expr` is NULL, if `m` has no key 
`key_expr`, or if its value is NULL.
+  type: The value type of `m`, nullable.
+
+notes:
+  - If `m` holds a key twice, which the MAP constructor allows for keys that 
are equal only at runtime, the first of their values comes back.
+  - In SQL, a `DECIMAL` `key_expr` on a map with keys of another numeric type 
fails the query, and so does a key of another numeric type on a map with 
`DECIMAL` keys, such as `m[1]`. Cast `key_expr` to the key type of `m` first. 
In the Table API, `key_expr` is cast to the key type of `m` instead, as in 
MAP_CONTAINS_KEY.

Review Comment:
   This isn't the same as in MAP_CONTAINS_KEY. `at` rejects a nullable INT key 
on a map with NOT NULL keys, where `mapContainsKey` returns a result for the 
same column.



##########
docs/data/functions/collection/array_union.yml:
##########
@@ -0,0 +1,84 @@
+# 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: ARRAY_UNION
+summary: Returns an array of the distinct elements of two arrays.
+
+syntax:
+  sql: ARRAY_UNION(arr1, arr2)
+  java: $("arr1").arrayUnion(arr2)
+  python: col("arr1").array_union(arr2)
+
+arguments:
+  - name: arr1
+    type: An array
+    required: true
+  - name: arr2
+    type: An array
+    required: true
+
+returns:
+  description: The elements of `arr1` and `arr2`, each value once. First the 
elements of `arr1`, in the order in which they first occur, then the elements 
of `arr2` that aren't in `arr1`. NULL elements are equal to each other, so the 
result holds at most one NULL.
+  nulls: Returns NULL if `arr1` or `arr2` is NULL.
+  type: "`ARRAY` of the common element type of `arr1` and `arr2`, NOT NULL if 
both arguments are NOT NULL."
+
+notes:
+  - Outside the argument of `UNNEST`, the elements of both arrays are cast to 
their common type first, such as `DOUBLE` for an `ARRAY<INT>` and an 
`ARRAY<DOUBLE>`.
+  - "Inside the argument of `UNNEST`, the elements aren't cast to their common 
type unless both arguments are constants, so a number of another type comes 
back wrong or fails the job: `UNNEST(ARRAY_UNION(ARRAY[a], ARRAY[2.5E0]))` 
returns 4.9E-324 instead of 1.0 for an `INT` column `a` of 1. Compute the array 
in a subquery and unnest its column instead."

Review Comment:
   The trigger is an unqualified column in the UNNEST argument, not constants: 
with `ARRAY[t.a]` this returns 1.0. Same on APPEND, PREPEND, CONCAT, REMOVE, 
EXCEPT, INTERSECT and MAP_CONTAINS_KEY.



##########
docs/data/functions/collection/array_append.yml:
##########
@@ -0,0 +1,95 @@
+# 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: ARRAY_APPEND
+summary: Returns an array with an element added at the end.
+
+syntax:
+  sql: ARRAY_APPEND(arr, new_element)
+  java: $("arr").arrayAppend(newElement)
+  python: col("arr").array_append(new_element)
+
+arguments:
+  - name: arr
+    type: An array
+    required: true
+    description: The array to add to.
+  - name: new_element
+    type: A value of the element type of `arr`
+    required: true
+
+returns:
+  description: A new array with the elements of `arr`, followed by 
`new_element`.
+  nulls: Returns NULL if `arr` is NULL. A NULL `new_element` is added as a 
NULL element.
+  type: The type of `arr`, with nullable elements if `new_element` is 
nullable. NOT NULL if both arguments are NOT NULL.
+
+notes:
+  - "`new_element` is cast to the element type of `arr` first, so a longer 
string is cut and a number is rounded to the element's scale: 
`ARRAY_APPEND(ARRAY['USA', 'CAN'], 'CANADA')` returns `[USA, CAN, CAN]` instead 
of `[USA, CAN, CANADA]`. A number too large for the element type becomes NULL, 
so `ARRAY_APPEND(ARRAY[1.5, 2.0], x)` with an `x` of 12.5 adds NULL instead of 
12.5, although the element type stays NOT NULL. After `UNNEST`, `IS NULL` 
returns FALSE for that element, and selecting it fails the job. A `new_element` 
that doesn't cast implicitly fails the statement, such as a `STRING` column 
against `ARRAY['US', 'CA']`, whose elements are `CHAR(2)`, or a `BIGINT` 
against an `ARRAY<INT>`. In SQL, `ARRAY_CONCAT(arr, ARRAY[new_element])` keeps 
the whole value and accepts a wider type, since it widens the elements to a 
common type."

Review Comment:
   Selecting it only fails into a NOT NULL column, like collect(). Into a 
nullable sink column the NULL is written, and `COALESCE(e, -1)` still gives 
NULL. Same on ARRAY_PREPEND.



##########
docs/data/sql_functions.yml:
##########
@@ -671,130 +671,92 @@ conversion:
 collection:
   - sql: ARRAY '[' value1 [, value2 ]* ']'
     table: array(ANY1, ANY2, ...)
-    description: Returns an array created from a list of values (value1, 
value2, ...).
-  - sql: CARDINALITY(array)
-    table: ARRAY.cardinality()
-    description: Returns the number of elements in array.
+    page: array-constructor
   - sql: array '[' INT ']'
     table: ARRAY.at(INT)
-    description: Returns the element at position INT in array. The index 
starts from 1.
-  - sql: ELEMENT(array)
-    table: ARRAY.element()
-    description: Returns the sole element of array (whose cardinality should 
be one); returns NULL if array is empty. Throws an exception if array has more 
than one element.
-  - sql: MAP '[' value1, value2 [, value3, value4 ]* ']'
-    table: map(ANY1, ANY2, ANY3, ANY4, ...)
-    description: Returns a map created from a list of key-value pairs 
((value1, value2), (value3, value4), ...).
-  - sql: CARDINALITY(map)
-    table: MAP.cardinality()
-    description: Returns the number of entries in map.
-  - sql: map '[' value ']'
-    table: MAP.at(ANY)
-    description: Returns the value specified by key value in map.
+    page: array-subscript
   - sql: ARRAY_APPEND(array, element)
     table: array.arrayAppend(element)
-    description: Appends an element to the end of the array and returns the 
result. If the array itself is null, the function will return null. If an 
element to add is null, the null element will be added to the end of the array.
+    page: array-append
+  - sql: ARRAY_CONCAT(array1, ...)
+    table: array1.arrayConcat(...)

Review Comment:
   The page has no Java tab but the row still shows `arrayConcat`. It only 
works with Java arrays, `$("a").arrayConcat($("b"))` fails at planning. Drop it 
like ARRAY_JOIN, also in the zh table?



##########
docs/data/functions/row-and-structured-types/object_of.yml:
##########
@@ -0,0 +1,116 @@
+# 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: OBJECT_OF
+summary: Returns a structured object of a class, with a field for each 
name-value pair.
+
+syntax:
+  sql: OBJECT_OF(class_name [, field_name, expr]*)
+  java: objectOf(className, fieldName, $("expr"), ...)
+
+arguments:
+  - name: class_name
+    type: A string literal
+    required: true
+    description: The name of the class, such as `'com.example.User'`. It must 
be a valid Java class name, but the class doesn't have to exist. In Java, a 
`Class` such as `User.class` works too.
+  - name: field_name
+    type: A string literal
+    required: false
+    description: The name of a field. Names are case-sensitive, and each name 
can occur once.
+  - name: expr
+    type: Any type
+    required: false
+    description: The value of the field named before it.
+
+returns:
+  description: An object of class `class_name` with a field for each pair, in 
the order of the pairs. Each field has the type of its value.
+  nulls: Never returns NULL. A NULL value gives a NULL field.
+  type: "`STRUCTURED` of class `class_name` with a field of the type of each 
`expr`, nullable."
+
+notes:
+  - If the class is on the classpath, a Java program that collects the result 
receives instances of it, and the pairs must match the fields of the class, or 
the query fails. Otherwise, the program receives a `Row`.
+  - Two objects compare only if they have the same `class_name`, field names 
and field types, including the length of a string and nullability. So 
`OBJECT_OF('com.example.P', 'n', name) = OBJECT_OF('com.example.P', 'n', 
'Bob')` fails the statement for a `VARCHAR(5)` column `name`, and so do `CASE` 
and `UNION ALL` over such objects. Cast the values to the same type, such as 
`CAST('Bob' AS VARCHAR(5))`.

Review Comment:
   The cast only helps because `name` is NOT NULL in this example. For a 
nullable column the cast literal is still NOT NULL and the comparison still 
fails.



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