raminqaf commented on code in PR #29617:
URL: https://github.com/apache/flink/pull/29617#discussion_r4401655031


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java:
##########
@@ -1481,6 +1483,70 @@ public OutType tryParseXml(InType forceArray) {
                 unresolvedCall(TRY_PARSE_XML, toExpr(), 
objectToExpression(forceArray)));
     }
 
+    /**
+     * Returns the value of a {@link DataTypes#VARIANT()} at a path as a {@link
+     * DataTypes#VARIANT()}. If the variant or the path is {@code NULL}, or 
nothing is at the path,
+     * {@code NULL} is returned. A variant null at the path stays a variant 
null, which is not
+     * {@code NULL}.
+     *
+     * <p>This is a shortcut for {@code variantGet(path, 
DataTypes.VARIANT())}. See {@link
+     * #variantGet(Object, DataType)}.
+     */
+    public OutType variantGet(InType path) {
+        return toApiSpecificExpression(
+                unresolvedCall(VARIANT_GET, toExpr(), 
objectToExpression(path)));
+    }
+
+    /**
+     * Returns the value of a {@link DataTypes#VARIANT()} at a path such as 
{@code $.items[0].qty},
+     * cast to the given type. Array indices start at 0. If the variant or the 
path is {@code NULL},
+     * or nothing is at the path, {@code NULL} is returned. If the value 
cannot be cast to the type,
+     * an error is thrown. To return {@code NULL} instead, use {@link 
#tryVariantGet(Object,
+     * DataType)}.
+     *
+     * <p>The value is cast like {@code CAST}, so a variant null gives {@code 
NULL} unless the type
+     * is {@link DataTypes#VARIANT()}. See the SQL function {@code 
VARIANT_GET} for the path syntax.
+     *
+     * @param returnType the type of the result, always nullable. Only its 
logical type is used.
+     */
+    public OutType variantGet(InType path, DataType returnType) {
+        return toApiSpecificExpression(
+                unresolvedCall(
+                        VARIANT_GET,
+                        toExpr(),
+                        objectToExpression(path),
+                        
valueLiteral(returnType.getLogicalType().asSerializableString())));
+    }
+
+    /**
+     * Returns the value of a {@link DataTypes#VARIANT()} at a path as a {@link
+     * DataTypes#VARIANT()}. If nothing is at the path, or a path that is not 
a literal is
+     * malformed, {@code NULL} is returned.
+     *
+     * <p>This is a shortcut for {@code tryVariantGet(path, 
DataTypes.VARIANT())}. See {@link
+     * #tryVariantGet(Object, DataType)}.
+     */
+    public OutType tryVariantGet(InType path) {
+        return toApiSpecificExpression(
+                unresolvedCall(TRY_VARIANT_GET, toExpr(), 
objectToExpression(path)));
+    }
+
+    /**
+     * Returns the value of a {@link DataTypes#VARIANT()} at a path, cast to 
the given type. Unlike
+     * {@link #variantGet(Object, DataType)}, {@code NULL} is returned instead 
of an error if the
+     * value cannot be cast to the type or a path that is not a literal is 
malformed.
+     *
+     * @param returnType the type of the result, always nullable. Only its 
logical type is used.

Review Comment:
   done



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