martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010701197


##########
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/BaseAvroProducer.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.adapter.avro.producers;
+
+import org.apache.arrow.vector.FieldVector;
+
+/**
+ * Base class for avro producers.
+ *
+ * @param <T> vector type.
+ */
+public abstract class BaseAvroProducer<T extends FieldVector> implements 
Producer<T> {
+
+  protected T vector;
+  protected int currentIndex;
+
+  /**
+   * Constructs a base avro consumer.
+   *
+   * @param vector the vector to consume.
+   */
+  protected BaseAvroProducer(T vector) {
+    this.vector = vector;
+  }
+
+  @Override
+  public void skipNull() {
+    currentIndex++;
+  }
+
+  @Override
+  public void setPosition(int index) {
+    currentIndex = index;

Review Comment:
   I have added check, index < 0 or index > value count will throw an illegal 
argument exception.
   
   I've allowed index == value count, because that is the final state after 
production is complete. Since the producer can get into that state naturally, 
and it has a valid meaning (production complete), it seemed wrong to disallow 
it. Thoughts welcome on that point!
   
   Worth noting, there are several ways value count can not be set on the 
vector, either because client code doesn't set it, or a writer doesn't (e.g. 
UnionMapWriter does not update the entries data vector count) in which case the 
cause of the error may not be obvious (at least it wasn't for me)!  Probably 
still the check is the right thing to do, but something to be aware of.



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