lidavidm commented on code in PR #852:
URL: https://github.com/apache/arrow-java/pull/852#discussion_r2358212286


##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverter.java:
##########
@@ -37,7 +38,34 @@ public 
TimestampAvaticaParameterConverter(ArrowType.Timestamp type) {}
 
   @Override
   public boolean bindParameter(FieldVector vector, TypedValue typedValue, int 
index) {
-    long value = (long) typedValue.toLocal();
+    Object valueObj = typedValue.toLocal();
+    if (valueObj instanceof String) {
+      return bindTimestampAsString(vector, (String) valueObj, index);
+    } else if (valueObj instanceof Long) {
+      return bindTimestampAsLong(vector, (Long) valueObj, index);
+    } else {
+      return false;
+    }

Review Comment:
   We do extra checking here to avoid a failed cast - should the other 
converters do the same?



##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverter.java:
##########


Review Comment:
   Hmm, so we only allow timestamps with the `Z` suffix - but we can bind to 
naive timestamp vectors too. And we don't allow timestamps without the suffix. 
(We could always relax that later, though.)



##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/converter/impl/TimeAvaticaParameterConverterTest.java:
##########


Review Comment:
   Why doesn't this test use the same `@BeforeEach` setup as the date tests?



##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverterTest.java:
##########


Review Comment:
   Ditto here - this should use the same structure as the date tests.



##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/converter/impl/DateAvaticaParameterConverterTest.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.arrow.driver.jdbc.converter.impl;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.time.LocalDate;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.DateDayVector;
+import org.apache.arrow.vector.DateMilliVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.types.DateUnit;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.avatica.remote.TypedValue;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class DateAvaticaParameterConverterTest {
+  private RootAllocator allocator;
+
+  @BeforeEach
+  void setUp() {
+    allocator = new RootAllocator(Long.MAX_VALUE);
+  }
+
+  @AfterEach
+  void tearDown() {
+    allocator.close();
+  }
+
+  @Test
+  void testBindParameterWithStringDateMilliVector() {
+    try (DateMilliVector vector = new DateMilliVector("date", allocator)) {
+      DateAvaticaParameterConverter converter =
+          new DateAvaticaParameterConverter(new ArrowType.Date(DateUnit.DAY));
+      String dateStr = "2023-09-15";
+      TypedValue typedValue = 
TypedValue.create(ColumnMetaData.Rep.STRING.toString(), dateStr);
+      boolean result = converter.bindParameter(vector, typedValue, 0);
+      assertTrue(result);
+      assertEquals((int) LocalDate.parse(dateStr).toEpochDay(), vector.get(0));

Review Comment:
   Isn't this wrong? DateMilliVector is supposed to store millisecond 
timestamps representing dates (yes, this is a bad representation) so it should 
be `toEpochDay() * 24 * 60 * 60 * 1000`.



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