mihaibudiu commented on code in PR #3681:
URL: https://github.com/apache/calcite/pull/3681#discussion_r1576540675
##########
linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java:
##########
@@ -349,6 +348,55 @@ private static void escapeString(StringBuilder buf, String
s) {
buf.append('"');
}
+ private static @Nullable Object getFieldValue(Object source, Field field) {
+ if (isRecord(source.getClass())) {
+ return getValueFromGetterMethod(source, field);
+ }
+ return getValueFromField(source, field);
+ }
+
+ private static @Nullable Object getValueFromGetterMethod(Object source,
Field field) {
+ try {
+ return findPublicGetter(field,
source.getClass().getMethods()).invoke(source);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new IllegalArgumentException("Could not invoke method");
Review Comment:
From my experience more information in error messages helps debugging
significantly.
##########
linq4j/src/main/java/org/apache/calcite/linq4j/util/Compatible.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.calcite.linq4j.util;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Proxy;
+import java.util.Locale;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Compatibility layer.
+ *
+ * <p>Allows to use advanced functionality if the latest JDK or Guava version
is present.
Review Comment:
how does Guava help?
##########
linq4j/src/test/java/org/apache/calcite/linq4j/test/ExpressionTest.java:
##########
@@ -883,6 +887,28 @@ public class ExpressionTest {
Expressions.constant(Linq4jTest.emps)));
}
+ @Test void testWriteRecordConstant(@TempDir Path tempDir) {
Review Comment:
if this is the test for this issue, you may want a corresponding JavaDoc.
there are plenty of examples.
--
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]