lidavidm commented on code in PR #38404:
URL: https://github.com/apache/arrow/pull/38404#discussion_r1382142636


##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverter.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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 org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.TimeStampMicroTZVector;
+import org.apache.arrow.vector.TimeStampMicroVector;
+import org.apache.arrow.vector.TimeStampMilliTZVector;
+import org.apache.arrow.vector.TimeStampMilliVector;
+import org.apache.arrow.vector.TimeStampNanoTZVector;
+import org.apache.arrow.vector.TimeStampNanoVector;
+import org.apache.arrow.vector.TimeStampSecTZVector;
+import org.apache.arrow.vector.TimeStampSecVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.calcite.avatica.AvaticaParameter;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * AvaticaParameterConverter for Timestamp Arrow types.
+ */
+public class TimestampAvaticaParameterConverter extends 
BaseAvaticaParameterConverter {
+
+  public TimestampAvaticaParameterConverter(ArrowType.Timestamp type) {
+  }
+
+  @Override
+  public boolean bindParameter(FieldVector vector, TypedValue typedValue, int 
index) {
+    // FIXME: how should we handle TZ? Do we need to convert the value to the 
TZ on the vector?

Review Comment:
   The timezone on the vector is purely for display; the underlying value is 
always UTC in Arrow.



##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/AvaticaParameterBinder.java:
##########
@@ -0,0 +1,233 @@
+/*
+ * 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.utils;
+
+import java.util.List;
+
+import 
org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler.PreparedStatement;
+import 
org.apache.arrow.driver.jdbc.converter.impl.BinaryAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.BoolAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.DateAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.DecimalAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.DurationAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.FixedSizeBinaryAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.FixedSizeListAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.FloatingPointAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.IntAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.IntervalAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.LargeBinaryAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.LargeListAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.LargeUtf8AvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.ListAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.MapAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.NullAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.StructAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.TimeAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.TimestampAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.UnionAvaticaParameterConverter;
+import 
org.apache.arrow.driver.jdbc.converter.impl.Utf8AvaticaParameterConverter;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Convert Avatica PreparedStatement parameters from a list of TypedValue to 
Arrow and bind them to the
+ * VectorSchemaRoot representing the PreparedStatement parameters.
+ * <p>
+ * NOTE: Make sure to close the parameters VectorSchemaRoot once we're done 
with them.
+ */
+public class AvaticaParameterBinder {
+  private final PreparedStatement preparedStatement;
+  private final VectorSchemaRoot parameters;
+
+  public AvaticaParameterBinder(PreparedStatement preparedStatement, 
BufferAllocator bufferAllocator) {
+    this.parameters = 
VectorSchemaRoot.create(preparedStatement.getParameterSchema(), 
bufferAllocator);
+    this.preparedStatement = preparedStatement;
+  }
+
+  /**
+   * Bind the given Avatica values to the prepared statement.
+   * @param typedValues The parameter values.
+   */
+  public void bind(List<TypedValue> typedValues) {
+    bind(typedValues, 0);
+  }
+
+  /**
+   * Bind the given Avatica values to the prepared statement at the given 
index.
+   * @param typedValues The parameter values.
+   * @param index index for parameter.
+   */
+  public void bind(List<TypedValue> typedValues, int index) {
+    if (preparedStatement.getParameterSchema().getFields().size() != 
typedValues.size()) {
+      throw new IllegalStateException(
+          String.format("Prepared statement has %s parameters, but only 
received %s",
+              preparedStatement.getParameterSchema().getFields().size(),
+              typedValues.size()));
+    }
+
+    for (int i = 0; i < typedValues.size(); i++) {
+      bind(parameters.getVector(i), typedValues.get(i), index);
+    }
+
+    if (!typedValues.isEmpty()) {
+      parameters.setRowCount(index + 1);
+      preparedStatement.setParameters(parameters);
+    }
+  }
+
+  /**
+   * Bind a TypedValue to the given index on the FieldVctor.
+   *
+   * @param vector     FieldVector to bind to.
+   * @param typedValue TypedValue to bind to the vector.
+   * @param index      Vector index to bind the value at.
+   */
+  private void bind(FieldVector vector, TypedValue typedValue, int index) {
+    try {
+      if (!vector.getField().getType().accept(new BinderVisitor(vector, 
typedValue, index))) {
+        throw new RuntimeException(

Review Comment:
   nit: is there a more appropriate exception than RuntimeException?



##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/AvaticaParameterConverter.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.calcite.avatica.AvaticaParameter;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * Interface for a class in charge of converting between AvaticaParameters and 
TypedValues and
+ * Arrow.
+ */
+public interface AvaticaParameterConverter {
+
+  /**
+   * Bind a TypedValue to a FieldVector at the given index.
+   *
+   * @param vector FieldVector that the parameter should be bound to.
+   * @param typedValue TypedValue to bind as a parameter.
+   * @param index Vector index that the TypedValue should be bound to.

Review Comment:
   0-index, right? (I ask because JDBC is often 1-indexed)



##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BinaryAvaticaParameterConverter.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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 org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.calcite.avatica.AvaticaParameter;
+import org.apache.calcite.avatica.remote.TypedValue;
+
+/**
+ * AvaticaParameterConverter for Binary Arrow types.
+ */
+public class BinaryAvaticaParameterConverter extends 
BaseAvaticaParameterConverter {
+
+  public BinaryAvaticaParameterConverter(ArrowType.Binary type) {
+  }
+
+  @Override
+  public boolean bindParameter(FieldVector vector, TypedValue typedValue, int 
index) {
+    byte[] value = (byte[]) typedValue.toJdbc(null);

Review Comment:
   Do we need to handle `value == null`? Or in general how does Avatica handle 
null bind parameters?



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