Copilot commented on code in PR #2448:
URL: https://github.com/apache/auron/pull/2448#discussion_r3718079582


##########
auron-flink-extension/auron-flink-planner/src/main/java/org/apache/auron/flink/table/planner/converter/RexLiteralConverter.java:
##########
@@ -112,6 +112,37 @@ private static boolean isSupportedType(SqlTypeName 
typeName) {
         return SUPPORTED_TYPES.contains(typeName);
     }
 
+    /**
+     * Builds a literal expression node from a plain {@link String} that is 
not backed by a
+     * {@link RexNode}. Used for plan-time constants (such as a session 
timezone read from
+     * configuration) that must travel to the native side as a string 
argument. The value is
+     * serialized as a single-element {@code Utf8} Arrow record batch in IPC 
stream format, matching
+     * the encoding {@link #convert} produces for CHAR/VARCHAR {@link 
RexLiteral}s.
+     *
+     * @param value the constant string to encode
+     * @return a {@link PhysicalExprNode} carrying the value as a native 
literal
+     */
+    public static PhysicalExprNode stringLiteral(String value) {
+        RowType rowType = RowType.of(new VarCharType(VarCharType.MAX_LENGTH));
+        try (BufferAllocator allocator =
+                        
FlinkArrowUtils.getRootAllocator().newChildAllocator("literal", 0, 
Long.MAX_VALUE);
+                VectorSchemaRoot root = 
VectorSchemaRoot.create(FlinkArrowUtils.toArrowSchema(rowType), allocator)) {
+
+            GenericRowData rowData = new GenericRowData(1);
+            rowData.setField(0, StringData.fromString(value));
+

Review Comment:
   stringLiteral(String) doesn’t define behavior for a null input. Passing null 
currently throws a NullPointerException from StringData.fromString(value), 
which is hard to diagnose and can surface as an opaque planner failure. Add an 
explicit null check with a clear exception (or encode a NULL literal if that’s 
intended).



##########
auron-flink-extension/auron-flink-planner/src/main/java/org/apache/auron/flink/table/planner/converter/FlinkDateTimeFormatConverter.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * 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.auron.flink.table.planner.converter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Translates a {@code java.text.SimpleDateFormat} pattern into the native 
parser's
+ * {@code strftime}-style format string, or reports that the pattern cannot be 
translated.
+ *
+ * <p>The native {@code Flink_UnixTimestamp} function replicates {@code 
SimpleDateFormat} lenient
+ * parsing only for a fixed set of numeric fields. This converter is the 
plan-time gate: it accepts
+ * a pattern only when every token maps to a field the native parser handles 
identically, and
+ * returns {@link Optional#empty()} otherwise so the whole {@code Calc} falls 
back to Flink's engine.
+ *
+ * <p>Accepted fields and their native specifiers:
+ * <ul>
+ *   <li>{@code yyy} / {@code yyyy} &rarr; {@code %Y} (year)
+ *   <li>{@code M} / {@code MM} &rarr; {@code %m} (month)
+ *   <li>{@code d} / {@code dd} &rarr; {@code %d} (day of month)
+ *   <li>{@code H} / {@code HH} &rarr; {@code %H} (hour of day)
+ *   <li>{@code m} / {@code mm} &rarr; {@code %M} (minute)
+ *   <li>{@code s} / {@code ss} &rarr; {@code %S} (second)
+ * </ul>
+ *
+ * <p>Non-alphabetic characters are literals (a literal {@code %} is emitted 
as {@code %%}).
+ * {@code SimpleDateFormat} single-quote escaping applies, including the 
doubled {@code ''} that
+ * denotes a literal quote. Every other ASCII letter and every unlisted run 
length forces a fall
+ * back, because Java reserves all letters and the omitted forms either depend 
on a locale or on the
+ * clock at parse time.
+ *
+ * <p>Adjacency rule: run length is erased by the translation ({@code M} and 
{@code MM} both become
+ * {@code %m}), yet the native parser reads each numeric field at a canonical 
width (year 4; month,
+ * day, hour, minute, second 2) while Java's lenient scan window equals the 
run length. When two
+ * numeric fields are adjacent with no literal separator, those two widths 
must agree, so the left
+ * field's run length must equal its canonical width; otherwise the pattern 
falls back to avoid a
+ * silent divergence (e.g. {@code yyyyMd} on {@code 20201010} yields month 1 
in Java but month 10
+ * natively).
+ */
+public final class FlinkDateTimeFormatConverter {
+
+    private FlinkDateTimeFormatConverter() {
+        // utility class
+    }
+
+    /**
+     * Translates the given Java {@code SimpleDateFormat} pattern to the 
native {@code strftime}-style
+     * format string.
+     *
+     * @param javaPattern the Java date-time format pattern
+     * @return the translated native format string, or {@link 
Optional#empty()} if any part of the
+     *     pattern is outside the natively supported surface
+     */
+    public static Optional<String> translate(String javaPattern) {
+        List<Token> tokens = scan(javaPattern);
+        if (tokens == null) {

Review Comment:
   translate(String) will throw a NullPointerException for a null javaPattern 
(scan() calls pattern.length()). Since this is a public utility used as a 
plan-time gate, it’s safer to treat null as “not translatable” and return 
Optional.empty() (or explicitly reject null with a clear exception).



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