Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2015644238
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroListProducer.java:
##
@@ -0,0 +1,73 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces array values from a {@link ListVector}, writes data
to an avro encoder.
+ */
+public class AvroListProducer extends BaseAvroProducer {
+
+ private final Producer delegate;
+
+ /** Instantiate an AvroListProducer. */
+ public AvroListProducer(ListVector vector, Producer
delegate) {
+super(vector);
+this.delegate = delegate;
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+
+int startOffset = vector.getOffsetBuffer().getInt(currentIndex * (long)
Integer.BYTES);
+int endOffset = vector.getOffsetBuffer().getInt((currentIndex + 1) *
(long) Integer.BYTES);
+int nItems = endOffset - startOffset;
+
+encoder.writeArrayStart();
+encoder.setItemCount(nItems);
+
+for (int i = 0; i < nItems; i++) {
+ encoder.startItem();
+ delegate.produce(encoder);
+}
+
+encoder.writeArrayEnd();
+currentIndex++;
+ }
+
+ // Do not override skipNull(), delegate will not have an entry if the list
is null
+
+ @Override
+ public void setPosition(int index) {
+if (index < 0 || index > vector.getValueCount()) {
Review Comment:
Ah, I see your comment below now. It might be worth noting this somewhere
(perhaps the docstring of the base class?)
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroListProducer.java:
##
@@ -0,0 +1,73 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces array values from a {@link ListVector}, writes data
to an avro encoder.
+ */
+public class AvroListProducer extends BaseAvroProducer {
+
+ private final Producer delegate;
+
+ /** Instantiate an AvroListProducer. */
+ public AvroListProducer(ListVector vector, Producer
delegate) {
+super(vector);
+this.delegate = delegate;
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+
+int startOffset = vector.getOffsetBuffer().getInt(currentIndex * (long)
Integer.BYTES);
+int endOffset = vector.getOffsetBuffer().getInt((currentIndex + 1) *
(long) Integer.BYTES);
+int nItems = endOffset - startOffset;
+
+encoder.writeArrayStart();
+encoder.setItemCount(nItems);
+
+for (int i = 0; i < nItems; i++) {
+ encoder.startItem();
+ delegate.produce(encoder);
+}
+
+encoder.writeArrayEnd();
+currentIndex++;
+ }
+
+ // Do not override skipNull(), delegate will not have an entry if the list
is null
+
+ @Override
+ public void setPosition(int index) {
+if (index < 0 || index > vector.getValueCount()) {
Review Comment:
Should these checks be `index >= getValueCount()`?
##
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010637729
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/logical/AvroTimeNanoProducer.java:
##
@@ -0,0 +1,46 @@
+/*
+ * 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.logical;
+
+import java.io.IOException;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.vector.TimeNanoVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that converts nanoseconds from a {@link TimeNanoVector} and
produces time (microseconds)
+ * values, writes data to an Avro encoder.
+ */
+public class AvroTimeNanoProducer extends BaseAvroProducer {
+
+ // Convert nanoseconds to microseconds for Avro time-micros (LONG) type
+ // Range is 1000 times less than for microseconds, so the type will fit
(with loss of precision)
+
+ private static final long NANOS_PER_MICRO = 1000;
+
+ public AvroTimeNanoProducer(TimeNanoVector vector) {
+super(vector);
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+long nanos = vector.getDataBuffer().getLong(currentIndex * (long)
TimeNanoVector.TYPE_WIDTH);
+long micros = nanos / NANOS_PER_MICRO;
Review Comment:
I don't think this will truncate since we are going nanos -> micros so there
is more range available. There is loss of precision - I think that is
acceptable, since Avro does not have a time-nanos type (at least not yet)!
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2771599238 Hi @lidavidm - Thanks so much for merging, I'm really happy to get this first piece in :-) Have started work on the second bit, once the main pieces are ready I will raise a new PR. I'm snowed under too so may have to put it down and come back a week later etc., very happy to work in async mode! -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm merged PR #638: URL: https://github.com/apache/arrow-java/pull/638 -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2771358197 Ok well these CI failures aren't related to the PR, merging... -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2770979645 The proposal looks good to me. Sorry, I will try to give a hopefully final review here this week - as you have seen I tend to be scattered about so I appreciate your patience -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2770756352 This last update uses Avro's logical type classes instead of setting the raw schema props. The output to disk is the same, but if you want to use the generated Avro Schema directly these structures should be available. Needed for round-trip testing. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2770501896 Hello - Thought I would make a start on step 2 in the Avro series. I have raised #698 to describe what I'm thinking. Still very happy to do another round of updates on this one if there are more comments as / when people have time to review - lmk :-) But since there are a few more PRs in the series to get the full capability I thought it was worth starting on the second one! -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2759141103 Hi - I think I have addressed all the new comments. Also found an issue in the fixed list producer - I updated the test cases to show this up and included a fix. Fairly sure all the complex type producers are correct now but would be worth a set of eyes!! The four I have are list, fixed size list, map and struct. Please let me know if there is anything else needs addressing. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638: URL: https://github.com/apache/arrow-java/pull/638#discussion_r2017458056 ## adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java: ## @@ -0,0 +1,729 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; +import org.apache.arrow.adapter.avro.producers.AvroBigIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroBooleanProducer; +import org.apache.arrow.adapter.avro.producers.AvroBytesProducer; +import org.apache.arrow.adapter.avro.producers.AvroDenseUnionProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeBinaryProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeListProducer; +import org.apache.arrow.adapter.avro.producers.AvroFloat2Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat4Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat8Producer; +import org.apache.arrow.adapter.avro.producers.AvroIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroListProducer; +import org.apache.arrow.adapter.avro.producers.AvroMapProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullableProducer; +import org.apache.arrow.adapter.avro.producers.AvroSmallIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroStringProducer; +import org.apache.arrow.adapter.avro.producers.AvroStructProducer; +import org.apache.arrow.adapter.avro.producers.AvroTinyIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroUint1Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint2Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint4Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint8Producer; +import org.apache.arrow.adapter.avro.producers.AvroUnionProducer; +import org.apache.arrow.adapter.avro.producers.BaseAvroProducer; +import org.apache.arrow.adapter.avro.producers.CompositeAvroProducer; +import org.apache.arrow.adapter.avro.producers.Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateDayProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimal256Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimalProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecTzProducer; +import org.apache.arrow.util.Preconditions; +import org.apache.arrow.vector.BigIntVector; +import org.apache.arrow.vector.BitVector; +import org.apache.arrow.vector.DateDayVector; +import org.apache.arrow.vector.DateMilliVector; +import org.apache.arrow.vector.Decimal256Vector; +import org.apache.arrow.vector.DecimalVector; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.FixedSizeBinaryVector; +import org.apache.arrow.vector.Float2Vector; +import org.apache.arrow.vector.Float4Vector; +import org.apache.arrow.vector.Float8Vector; +import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.NullVector; +import org.apache.arrow.vector.SmallIntVector; +import org.apache.arrow.vector.TimeMicroVector; +import
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638: URL: https://github.com/apache/arrow-java/pull/638#discussion_r2017456583 ## adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java: ## @@ -0,0 +1,718 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; +import org.apache.arrow.adapter.avro.producers.AvroBigIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroBooleanProducer; +import org.apache.arrow.adapter.avro.producers.AvroBytesProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeBinaryProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeListProducer; +import org.apache.arrow.adapter.avro.producers.AvroFloat2Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat4Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat8Producer; +import org.apache.arrow.adapter.avro.producers.AvroIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroListProducer; +import org.apache.arrow.adapter.avro.producers.AvroMapProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullableProducer; +import org.apache.arrow.adapter.avro.producers.AvroSmallIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroStringProducer; +import org.apache.arrow.adapter.avro.producers.AvroStructProducer; +import org.apache.arrow.adapter.avro.producers.AvroTinyIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroUint1Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint2Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint4Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint8Producer; +import org.apache.arrow.adapter.avro.producers.BaseAvroProducer; +import org.apache.arrow.adapter.avro.producers.CompositeAvroProducer; +import org.apache.arrow.adapter.avro.producers.Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateDayProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimal256Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimalProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecTzProducer; +import org.apache.arrow.util.Preconditions; +import org.apache.arrow.vector.BigIntVector; +import org.apache.arrow.vector.BitVector; +import org.apache.arrow.vector.DateDayVector; +import org.apache.arrow.vector.DateMilliVector; +import org.apache.arrow.vector.Decimal256Vector; +import org.apache.arrow.vector.DecimalVector; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.FixedSizeBinaryVector; +import org.apache.arrow.vector.Float2Vector; +import org.apache.arrow.vector.Float4Vector; +import org.apache.arrow.vector.Float8Vector; +import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.NullVector; +import org.apache.arrow.vector.SmallIntVector; +import org.apache.arrow.vector.TimeMicroVector; +import org.apache.arrow.vector.TimeMilliVector; +import org.apache.arrow.vector.TimeNanoVector; +import org.apache.arrow.vector.TimeSecVector; +import
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2017456018
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroListProducer.java:
##
@@ -0,0 +1,73 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces array values from a {@link ListVector}, writes data
to an avro encoder.
+ */
+public class AvroListProducer extends BaseAvroProducer {
+
+ private final Producer delegate;
+
+ /** Instantiate an AvroListProducer. */
+ public AvroListProducer(ListVector vector, Producer
delegate) {
+super(vector);
+this.delegate = delegate;
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+
+int startOffset = vector.getOffsetBuffer().getInt(currentIndex * (long)
Integer.BYTES);
+int endOffset = vector.getOffsetBuffer().getInt((currentIndex + 1) *
(long) Integer.BYTES);
+int nItems = endOffset - startOffset;
+
+encoder.writeArrayStart();
+encoder.setItemCount(nItems);
+
+for (int i = 0; i < nItems; i++) {
+ encoder.startItem();
+ delegate.produce(encoder);
+}
+
+encoder.writeArrayEnd();
+currentIndex++;
+ }
+
+ // Do not override skipNull(), delegate will not have an entry if the list
is null
+
+ @Override
+ public void setPosition(int index) {
+if (index < 0 || index > vector.getValueCount()) {
Review Comment:
I have added a doc comment on the base class as you suggested
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010629007
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java:
##
@@ -0,0 +1,194 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.arrow.adapter.avro.producers.AvroArraysProducer;
+import org.apache.arrow.adapter.avro.producers.AvroBooleanProducer;
+import org.apache.arrow.adapter.avro.producers.AvroBytesProducer;
+import org.apache.arrow.adapter.avro.producers.AvroDoubleProducer;
+import org.apache.arrow.adapter.avro.producers.AvroFixedProducer;
+import org.apache.arrow.adapter.avro.producers.AvroFloatProducer;
+import org.apache.arrow.adapter.avro.producers.AvroIntProducer;
+import org.apache.arrow.adapter.avro.producers.AvroLongProducer;
+import org.apache.arrow.adapter.avro.producers.AvroMapProducer;
+import org.apache.arrow.adapter.avro.producers.AvroNullProducer;
+import org.apache.arrow.adapter.avro.producers.AvroNullableProducer;
+import org.apache.arrow.adapter.avro.producers.AvroStringProducer;
+import org.apache.arrow.adapter.avro.producers.AvroStructProducer;
+import org.apache.arrow.adapter.avro.producers.AvroUnionsProducer;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.adapter.avro.producers.CompositeAvroProducer;
+import org.apache.arrow.adapter.avro.producers.Producer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroDateProducer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroDecimalProducer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMicroProducer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMillisProducer;
+import
org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroProducer;
+import
org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMillisProducer;
+import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.vector.BigIntVector;
+import org.apache.arrow.vector.BitVector;
+import org.apache.arrow.vector.DateDayVector;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.FixedSizeBinaryVector;
+import org.apache.arrow.vector.Float4Vector;
+import org.apache.arrow.vector.Float8Vector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.NullVector;
+import org.apache.arrow.vector.TimeMicroVector;
+import org.apache.arrow.vector.TimeMilliVector;
+import org.apache.arrow.vector.TimeStampMicroVector;
+import org.apache.arrow.vector.TimeStampMilliVector;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.arrow.vector.complex.MapVector;
+import org.apache.arrow.vector.complex.StructVector;
+import org.apache.arrow.vector.complex.UnionVector;
+import org.apache.arrow.vector.types.Types;
+
+public class ArrowToAvroUtils {
+
+ /**
+ * Create a composite Avro producer for a set of field vectors (typically
the root set of a VSR).
+ *
+ * @param vectors The vectors that will be used to produce Avro data
+ * @return The resulting composite Avro producer
+ */
+ public static CompositeAvroProducer
createCompositeProducer(List vectors) {
+
+List> producers = new
ArrayList<>(vectors.size());
+
+for (FieldVector vector : vectors) {
+ BaseAvroProducer producer =
createProducer(vector);
+ producers.add(producer);
+}
+
+return new CompositeAvroProducer(producers);
+ }
+
+ private static BaseAvroProducer createProducer(FieldVector vector) {
+boolean nullable = vector.getField().isNullable();
+return createProducer(vector, nullable);
+ }
+
+ private static BaseAvroProducer createProducer(FieldVector vector,
boolean nullable) {
+
+Preconditions.checkNotNull(vector, "Arrow vector object can't be null");
+
+final Types.MinorType minorType = vector.getMinorType();
+
+// Avro understands nullable types as a union of type | null
+// Most nullable fields in a VSR will not be
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2755511607 > Please ignore the check 😬 Ok great - in that case I think the CI is done :) -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2753625036 Please ignore the check :grimacing: -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2753580739 I think the PR check hit [this issue](https://github.com/apache/arrow-java/pull/673) - could you add the milestone to the issue manually for now? -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2751468881 CI looks good now - just the link missing on the PR to issue #615, sorry I don't have permission to add that! -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2750984663 Hi @lidavidm - There were two test failures in CI relating to nano precision time values that didn't show up in my local machine. I have pushed a fix. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2750660875 Thanks @lidavidm - good to know it is not just me going crazy! I have removed support of data production for unions for now. Also rebased on master. Totally understand the time pressure. I might work on some of the other pieces in the meantime as separate PRs if that's OK, to have a couple of bits ready for you to look at :-) Also read the thread on Unions. My company uses Arrow Java heavily in our product - time is a big issue for us as well but if I can find some I'll try to raise a few fixes that we're interested in. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2750182221 I'm fine splitting things into other PRs if it makes your life easier. It is known that the Java Union implementation is wrong, unfortunately. See https://github.com/apache/arrow-java/issues/108 If you want to punt on Union for now that's fine by me. I'm a bit backlogged and will try to re-review when I get a chance but that may not be for a week or two, sorry. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
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 vector type.
+ */
+public abstract class BaseAvroProducer implements
Producer {
+
+ 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010643616
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/logical/BaseTimestampTzProducer.java:
##
@@ -0,0 +1,58 @@
+/*
+ * 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.logical;
+
+import java.io.IOException;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.vector.TimeStampVector;
+import org.apache.avro.io.Encoder;
+
+abstract class BaseTimestampTzProducer
+extends BaseAvroProducer {
+
+ // Convert TZ values to UTC to encode Avro timestamp types
Review Comment:
This is great! I took out all the timezone conversion logic, the TZ aware
producers are much simpler now :-)
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2749052296 Hi @lidavidm , @wgtmac - Have pushed another update, here is a quick summary: * I have been through all the comments above and responded. Please do come back on any you think need further attention! * I have added tests for both schema and data production. Tests cover primitive types, logical types and containers of primitive and logical types. Some edges cases (max int values, UTF 8 text) are included. * Tests do not include nested containers (e.g. list of lists), these may work but I've not tried it. Negative test cases are also not included (i.e. invalid / illegal / badly initialised data structures). * Dictionary encoding not supported yet (we could push this to a second PR) * Nullable types. I have [type, null] for nullable types instead of [null, type]. There was a comment on this. The current reader framework won't allow the latter, so we can't round-trip if we do it that way, but if you think it is preferable we could do it anyway now we have full coverage on the producers. Anyway I think a separate PR is needed to address issues in the consumers. Lmk what you'd like to do on this. * Union data. Union schema production is working fine, but union data I really struggled with. Is there an issue with the field writers? I don't see how [this code](https://github.com/apache/arrow-java/blob/48a20ba91605ebb44df845671782acd8f869bd4b/vector/src/main/codegen/templates/DenseUnionWriter.java#L55) is ever going to work, since writers are not alll initialized. Also, per my understanding, the semantics of UnionWriter and DenseUnionWriter seem like they're the wrong way around. Fairly sure my understanding is the problem but I don't see where! Can you point me to any example code that populates a UnionVector and/or DenseUnionVector? Apologies for the delay, lots else going on as usual but I think this is getting closer now. If you let me know what else you'd like to see for this to be considered ready, I'll try to turn it around as quickly as I can. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
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 vector type.
+ */
+public abstract class BaseAvroProducer implements
Producer {
+
+ 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 because some code paths
that probably should set it don't (e.g. FieldWriter for Map entries). Users may
encounter problems because of that (I did)! 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010630423
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/Producer.java:
##
@@ -0,0 +1,53 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Interface that is used to produce values to avro encoder.
+ *
+ * @param The vector within producer or its delegate, used for partially
produce purpose.
+ */
+public interface Producer {
+
+ /**
+ * Produce a specific type value from the vector and write it to avro
encoder.
+ *
+ * @param encoder avro encoder to write data
+ * @throws IOException on error
+ */
+ void produce(Encoder encoder) throws IOException;
+
+ /** Skip null value in the vector by setting reader position + 1. */
+ void skipNull();
+
+ /** Set the position to read value from vector. */
+ void setPosition(int index);
+
+ /**
+ * Reset the vector within producer.
+ *
+ * @return true if reset is successful, false if reset is not needed.
+ */
+ boolean resetValueVector(T vector);
Review Comment:
Nothing ever returns false and the value is never used. I have changed this
to return void.
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010632791
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroStructProducer.java:
##
@@ -0,0 +1,73 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.complex.StructVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer which produces nested record type values to avro encoder. Read the
data from {@link
+ * org.apache.arrow.vector.complex.StructVector}.
+ */
+public class AvroStructProducer extends BaseAvroProducer {
+
+ private final Producer[] delegates;
+
+ /** Instantiate a AvroStructProducer. */
+ public AvroStructProducer(StructVector vector, Producer[] delegates) {
+super(vector);
+this.delegates = delegates;
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+
+for (Producer delegate : delegates) {
+ delegate.produce(encoder);
+}
+
+currentIndex++;
+ }
+
+ @Override
+ public void skipNull() {
+for (Producer delegate : delegates) {
+ delegate.skipNull();
+}
+super.skipNull();
+ }
+
+ @Override
+ public void setPosition(int index) {
+for (Producer delegate : delegates) {
+ delegate.setPosition(index);
+}
+super.setPosition(index);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean resetValueVector(StructVector vector) {
+for (int i = 0; i < delegates.length; i++) {
+ Producer delegate = (Producer) delegates[i];
+ delegate.resetValueVector(vector.getChildrenFromFields().get(i));
Review Comment:
Per above, nothing ever returns false and the value is never used, so I
removed the return value.
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638: URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010646441 ## adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java: ## @@ -0,0 +1,729 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; +import org.apache.arrow.adapter.avro.producers.AvroBigIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroBooleanProducer; +import org.apache.arrow.adapter.avro.producers.AvroBytesProducer; +import org.apache.arrow.adapter.avro.producers.AvroDenseUnionProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeBinaryProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeListProducer; +import org.apache.arrow.adapter.avro.producers.AvroFloat2Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat4Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat8Producer; +import org.apache.arrow.adapter.avro.producers.AvroIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroListProducer; +import org.apache.arrow.adapter.avro.producers.AvroMapProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullableProducer; +import org.apache.arrow.adapter.avro.producers.AvroSmallIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroStringProducer; +import org.apache.arrow.adapter.avro.producers.AvroStructProducer; +import org.apache.arrow.adapter.avro.producers.AvroTinyIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroUint1Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint2Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint4Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint8Producer; +import org.apache.arrow.adapter.avro.producers.AvroUnionProducer; +import org.apache.arrow.adapter.avro.producers.BaseAvroProducer; +import org.apache.arrow.adapter.avro.producers.CompositeAvroProducer; +import org.apache.arrow.adapter.avro.producers.Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateDayProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimal256Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimalProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecTzProducer; +import org.apache.arrow.util.Preconditions; +import org.apache.arrow.vector.BigIntVector; +import org.apache.arrow.vector.BitVector; +import org.apache.arrow.vector.DateDayVector; +import org.apache.arrow.vector.DateMilliVector; +import org.apache.arrow.vector.Decimal256Vector; +import org.apache.arrow.vector.DecimalVector; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.FixedSizeBinaryVector; +import org.apache.arrow.vector.Float2Vector; +import org.apache.arrow.vector.Float4Vector; +import org.apache.arrow.vector.Float8Vector; +import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.NullVector; +import org.apache.arrow.vector.SmallIntVector; +import org.apache.arrow.vector.TimeMicroVector; +import
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638: URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010645566 ## adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java: ## @@ -0,0 +1,729 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; +import org.apache.arrow.adapter.avro.producers.AvroBigIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroBooleanProducer; +import org.apache.arrow.adapter.avro.producers.AvroBytesProducer; +import org.apache.arrow.adapter.avro.producers.AvroDenseUnionProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeBinaryProducer; +import org.apache.arrow.adapter.avro.producers.AvroFixedSizeListProducer; +import org.apache.arrow.adapter.avro.producers.AvroFloat2Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat4Producer; +import org.apache.arrow.adapter.avro.producers.AvroFloat8Producer; +import org.apache.arrow.adapter.avro.producers.AvroIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroListProducer; +import org.apache.arrow.adapter.avro.producers.AvroMapProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullProducer; +import org.apache.arrow.adapter.avro.producers.AvroNullableProducer; +import org.apache.arrow.adapter.avro.producers.AvroSmallIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroStringProducer; +import org.apache.arrow.adapter.avro.producers.AvroStructProducer; +import org.apache.arrow.adapter.avro.producers.AvroTinyIntProducer; +import org.apache.arrow.adapter.avro.producers.AvroUint1Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint2Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint4Producer; +import org.apache.arrow.adapter.avro.producers.AvroUint8Producer; +import org.apache.arrow.adapter.avro.producers.AvroUnionProducer; +import org.apache.arrow.adapter.avro.producers.BaseAvroProducer; +import org.apache.arrow.adapter.avro.producers.CompositeAvroProducer; +import org.apache.arrow.adapter.avro.producers.Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateDayProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDateMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimal256Producer; +import org.apache.arrow.adapter.avro.producers.logical.AvroDecimalProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimeSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMilliTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampNanoTzProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecProducer; +import org.apache.arrow.adapter.avro.producers.logical.AvroTimestampSecTzProducer; +import org.apache.arrow.util.Preconditions; +import org.apache.arrow.vector.BigIntVector; +import org.apache.arrow.vector.BitVector; +import org.apache.arrow.vector.DateDayVector; +import org.apache.arrow.vector.DateMilliVector; +import org.apache.arrow.vector.Decimal256Vector; +import org.apache.arrow.vector.DecimalVector; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.FixedSizeBinaryVector; +import org.apache.arrow.vector.Float2Vector; +import org.apache.arrow.vector.Float4Vector; +import org.apache.arrow.vector.Float8Vector; +import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.NullVector; +import org.apache.arrow.vector.SmallIntVector; +import org.apache.arrow.vector.TimeMicroVector; +import
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010644452
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroUint4Producer.java:
##
@@ -0,0 +1,40 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.UInt4Vector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces long values from a {@link UInt4Vector}, writes data
to an avro encoder.
+ */
+public class AvroUint4Producer extends BaseAvroProducer {
+
+ /** Instantiate an AvroUint4Producer. */
+ public AvroUint4Producer(UInt4Vector vector) {
+super(vector);
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+int unsigned = vector.getDataBuffer().getInt(currentIndex * (long)
UInt4Vector.TYPE_WIDTH);
+long signed = unsigned & 0xL;
Review Comment:
Thanks, updated the code to use that method.
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroUint2Producer.java:
##
@@ -0,0 +1,38 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.UInt2Vector;
+import org.apache.avro.io.Encoder;
+
+/** Producer that produces int values from a {@link UInt2Vector}, writes data
to an avro encoder. */
+public class AvroUint2Producer extends BaseAvroProducer {
+
+ /** Instantiate an AvroUint2Producer. */
+ public AvroUint2Producer(UInt2Vector vector) {
+super(vector);
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+short unsigned = vector.getDataBuffer().getShort(currentIndex * (long)
UInt2Vector.TYPE_WIDTH);
+int signed = unsigned & 0x;
Review Comment:
Thanks, updated the code to use that method.
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r2010642572
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/logical/AvroTimeMilliProducer.java:
##
@@ -0,0 +1,34 @@
+/*
+ * 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.logical;
+
+import org.apache.arrow.adapter.avro.producers.AvroIntProducer;
+import org.apache.arrow.vector.TimeMilliVector;
+
+/**
+ * Producer that produces time (milliseconds) values from a {@link
TimeMilliVector}, writes data to
+ * an Avro encoder.
+ */
+public class AvroTimeMilliProducer extends AvroIntProducer {
+
+ // Time in milliseconds stored as integer, matches Avro time-millis type
Review Comment:
I think time for seconds / millis are four byte width?
[TimeMilliVector](https://github.com/apache/arrow-java/blob/48a20ba91605ebb44df845671782acd8f869bd4b/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java#L39).
So shouldn't be a range issue for this one.
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2702107186 Thanks @lidavidm for all the comments - really helpful :-) I'll push an update in a few days to address these and also add the tests, will probably be after the weekend. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1980767717
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroStructProducer.java:
##
@@ -0,0 +1,73 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.complex.StructVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer which produces nested record type values to avro encoder. Read the
data from {@link
+ * org.apache.arrow.vector.complex.StructVector}.
+ */
+public class AvroStructProducer extends BaseAvroProducer {
+
+ private final Producer[] delegates;
+
+ /** Instantiate a AvroStructProducer. */
+ public AvroStructProducer(StructVector vector, Producer[] delegates) {
+super(vector);
+this.delegates = delegates;
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+
+for (Producer delegate : delegates) {
+ delegate.produce(encoder);
+}
+
+currentIndex++;
+ }
+
+ @Override
+ public void skipNull() {
+for (Producer delegate : delegates) {
+ delegate.skipNull();
+}
+super.skipNull();
+ }
+
+ @Override
+ public void setPosition(int index) {
+for (Producer delegate : delegates) {
+ delegate.setPosition(index);
+}
+super.setPosition(index);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean resetValueVector(StructVector vector) {
+for (int i = 0; i < delegates.length; i++) {
+ Producer delegate = (Producer) delegates[i];
+ delegate.resetValueVector(vector.getChildrenFromFields().get(i));
Review Comment:
Should the return value here be accounted for?
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java:
##
@@ -0,0 +1,729 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.arrow.adapter.avro.producers.AvroBigIntProducer;
+import org.apache.arrow.adapter.avro.producers.AvroBooleanProducer;
+import org.apache.arrow.adapter.avro.producers.AvroBytesProducer;
+import org.apache.arrow.adapter.avro.producers.AvroDenseUnionProducer;
+import org.apache.arrow.adapter.avro.producers.AvroFixedSizeBinaryProducer;
+import org.apache.arrow.adapter.avro.producers.AvroFixedSizeListProducer;
+import org.apache.arrow.adapter.avro.producers.AvroFloat2Producer;
+import org.apache.arrow.adapter.avro.producers.AvroFloat4Producer;
+import org.apache.arrow.adapter.avro.producers.AvroFloat8Producer;
+import org.apache.arrow.adapter.avro.producers.AvroIntProducer;
+import org.apache.arrow.adapter.avro.producers.AvroListProducer;
+import org.apache.arrow.adapter.avro.producers.AvroMapProducer;
+import org.apache.arrow.adapter.avro.producers.AvroNullProducer;
+import org.apache.arrow.adapter.avro.producers.AvroNullableProducer;
+import org.apache.arrow.adapter.avro.producers.AvroSmallIntProducer;
+import org.apache.arrow.adapter.avro.producers.AvroStringProducer;
+import org.apache.arrow.adapter.avro.producers.AvroStructProducer;
+import org.apache.arrow.adapter.avro.producers.AvroTinyIntProducer;
+import org.apache.arrow.adapter.avro.producers.AvroUint1Producer;
+import org.apache.arrow.adapter.avro.producers.AvroUint2Producer;
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2699709876 Sorry, I've gotten caught up in my main job - I'll try to circle back here soon -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1976673041
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java:
##
@@ -0,0 +1,194 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.arrow.adapter.avro.producers.AvroArraysProducer;
+import org.apache.arrow.adapter.avro.producers.AvroBooleanProducer;
+import org.apache.arrow.adapter.avro.producers.AvroBytesProducer;
+import org.apache.arrow.adapter.avro.producers.AvroDoubleProducer;
+import org.apache.arrow.adapter.avro.producers.AvroFixedProducer;
+import org.apache.arrow.adapter.avro.producers.AvroFloatProducer;
+import org.apache.arrow.adapter.avro.producers.AvroIntProducer;
+import org.apache.arrow.adapter.avro.producers.AvroLongProducer;
+import org.apache.arrow.adapter.avro.producers.AvroMapProducer;
+import org.apache.arrow.adapter.avro.producers.AvroNullProducer;
+import org.apache.arrow.adapter.avro.producers.AvroNullableProducer;
+import org.apache.arrow.adapter.avro.producers.AvroStringProducer;
+import org.apache.arrow.adapter.avro.producers.AvroStructProducer;
+import org.apache.arrow.adapter.avro.producers.AvroUnionsProducer;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.adapter.avro.producers.CompositeAvroProducer;
+import org.apache.arrow.adapter.avro.producers.Producer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroDateProducer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroDecimalProducer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMicroProducer;
+import org.apache.arrow.adapter.avro.producers.logical.AvroTimeMillisProducer;
+import
org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMicroProducer;
+import
org.apache.arrow.adapter.avro.producers.logical.AvroTimestampMillisProducer;
+import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.vector.BigIntVector;
+import org.apache.arrow.vector.BitVector;
+import org.apache.arrow.vector.DateDayVector;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.FixedSizeBinaryVector;
+import org.apache.arrow.vector.Float4Vector;
+import org.apache.arrow.vector.Float8Vector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.NullVector;
+import org.apache.arrow.vector.TimeMicroVector;
+import org.apache.arrow.vector.TimeMilliVector;
+import org.apache.arrow.vector.TimeStampMicroVector;
+import org.apache.arrow.vector.TimeStampMilliVector;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.arrow.vector.complex.MapVector;
+import org.apache.arrow.vector.complex.StructVector;
+import org.apache.arrow.vector.complex.UnionVector;
+import org.apache.arrow.vector.types.Types;
+
+public class ArrowToAvroUtils {
+
+ /**
+ * Create a composite Avro producer for a set of field vectors (typically
the root set of a VSR).
+ *
+ * @param vectors The vectors that will be used to produce Avro data
+ * @return The resulting composite Avro producer
+ */
+ public static CompositeAvroProducer
createCompositeProducer(List vectors) {
+
+List> producers = new
ArrayList<>(vectors.size());
+
+for (FieldVector vector : vectors) {
+ BaseAvroProducer producer =
createProducer(vector);
+ producers.add(producer);
+}
+
+return new CompositeAvroProducer(producers);
+ }
+
+ private static BaseAvroProducer createProducer(FieldVector vector) {
+boolean nullable = vector.getField().isNullable();
+return createProducer(vector, nullable);
+ }
+
+ private static BaseAvroProducer createProducer(FieldVector vector,
boolean nullable) {
+
+Preconditions.checkNotNull(vector, "Arrow vector object can't be null");
+
+final Types.MinorType minorType = vector.getMinorType();
+
+// Avro understands nullable types as a union of type | null
+// Most nullable fields in a VSR will not be
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1976672861
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/AvroNullableProducer.java:
##
@@ -0,0 +1,77 @@
+/*
+ * 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 java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer wrapper which producers nullable types to an avro encoder. Write
the data to the
+ * underlying {@link FieldVector}.
+ */
+public class AvroNullableProducer extends
BaseAvroProducer {
+
+ private final Producer delegate;
+
+ /** Instantiate a AvroNullableProducer. */
+ public AvroNullableProducer(Producer delegate) {
+super(delegate.getVector());
+this.delegate = delegate;
+ }
+
+ @Override
+ public void produce(Encoder encoder) throws IOException {
+if (vector.isNull(currentIndex)) {
+ encoder.writeInt(1);
Review Comment:
I tried doing that, it broke the consumers and the data would not do round
trip. In Avro this is considered as the difference between "nullable" and
"optional", with "optional" being the semantics you are suggesting. I have kept
it as nullable for now. I do think we will need to follow up with a PR on the
consumers, particularly to address null handling. Nullable types get mangled in
the schema round trip at the moment!
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1976672431
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/logical/AvroDecimalProducer.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.adapter.avro.producers.logical;
+
+import java.io.IOException;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces decimal values from a {@link DecimalVector}, writes
data to an Avro
+ * encoder.
+ */
+public abstract class AvroDecimalProducer extends
BaseAvroProducer {
+
+ /** Instantiate an AvroDecimalProducer. */
+ protected AvroDecimalProducer(DecimalVector vector) {
+super(vector);
+ }
+
+ /** Producer for decimal logical type with original bytes type. */
+ public static class BytesDecimalProducer extends AvroDecimalProducer {
+
+private final byte[] reuseBytes;
+
+/** Instantiate a BytesDecimalConsumer. */
+public BytesDecimalProducer(DecimalVector vector) {
+ super(vector);
+ Preconditions.checkArgument(
+ vector.getTypeWidth() <= 16, "Decimal bytes length should <= 16.");
+ reuseBytes = new byte[vector.getTypeWidth()];
Review Comment:
Apologies, have removed this, I was mirroring consumers which need to handle
both bytes and fixed inputs, but for producers we can always used fixed and the
type width is always known.
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1976672068
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/Producer.java:
##
@@ -0,0 +1,62 @@
+/*
+ * 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;
+import org.apache.avro.io.Encoder;
+
+import java.io.IOException;
+
+/**
+ * Interface that is used to produce values to avro encoder.
+ *
+ * @param The vector within producer or its delegate, used for partially
produce purpose.
+ */
+public interface Producer extends AutoCloseable {
+
+ /**
+ * Produce a specific type value from the vector and write it to avro
encoder.
+ *
+ * @param encoder avro encoder to write data
+ * @throws IOException on error
+ */
+ void produce(Encoder encoder) throws IOException;
+
+ /** Skip null value in the vector by setting reader position + 1. */
+ void skipNull();
+
+ /** Set the position to read value from vector. */
+ void setPosition(int index);
Review Comment:
Per my [comment
below](https://github.com/apache/arrow-java/pull/638#issuecomment-2692815888),
this proved more tricky than I first thought. In light of that, are you happy
to stick with int for now?
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1976671839
##
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 vector type.
+ */
+public abstract class BaseAvroProducer implements
Producer {
+
+ 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;
+ }
+
+ @Override
+ public void close() throws Exception {
+vector.close();
+ }
+
+ @Override
+ public boolean resetValueVector(T vector) {
+this.vector = vector;
+this.currentIndex = 0;
+return true;
+ }
Review Comment:
Done, close() and AutoClosable are gone :-)
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2692815888 Hello. I have pushed a second iteration for review. Major updates are: * Added schema generation, to convert Arrow List to Avro Schema (record schema). I added doc comments with the type mapping. Schema is built of ArrowType while physical producers use MinorType, that bugged me at first but on reflection probably seems correct? * Updated the producers with a more complete set of types, including all widths of float / int types and logical types for all the date / time types (but not duration as of yet). Would appreciate a set of eyes on the timezone mapping for TZ aware timestamps! Per my reading of the Avro spec this is correct but worth double checking. I have tried to make it so most Arrow types will map to an Avro type if there is a suitable target. The basic approach is: * If a direct equivalent exists, use that * Next, choose an equivalent with no loss of precision (e.g. small int -> int) * Next, choose an equivalent with loss of precision but no loss of range (e.g. time nano -> time micros) * Finally, choose an equivalent with the best match and error on overflow (e.g. unsigned long -> long) I'm not sure about the last one, would it be better just to say we can't convert those types and throw an error up front? Large types (for text, binary, list) are not supported yet, there will be some extra thought needed on getting very large buffers between the two APIs. Interval / duration also not done yet, Arrow Interval resembles Avro Duration but is not an exact match and Arrow duration doesn't really have an equivalent that I could see. View types also not included as of now. I tried to move over to using long as the current row index, however a lot of the high-level APIs on the vector types use ints. For working directly with primitive types I was able to go to the underlying buffer (there were reasons to do that anyway in a few cases), but for the complex types that gets trickier because the type of the child vectors is not known. Is it ok to keep the interface using an int for current index for now? Most of the primitive producers are updated anyway, so the work to move over later would not be too much. I've run out of time for today. Next I plan to do the tests - like the consumers, will be exhaustive across types, combinations of nullability etc with some edge cases. Then the last thing I'd like to come back to on this PR is enums / dict encoding, just in case that has any impact on the structure of things would be good to know while it's still easy to change things. I have addressed some of the comments but not all, I will work through the rest but wanted to share this to check I'm still going in the right direction! -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1976671881
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/CompositeAvroProducer.java:
##
@@ -0,0 +1,69 @@
+/*
+ * 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 java.io.IOException;
+import java.util.List;
+
+import org.apache.arrow.util.AutoCloseables;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.avro.io.Encoder;
+
+/** Composite producer which holds all producers. It manages the produce and
cleanup process. */
+public class CompositeAvroProducer implements AutoCloseable {
+
+ private final List> producers;
+
+ public CompositeAvroProducer(List>
producers) {
+this.producers = producers;
+ }
+
+ public List> getProducers() {
+return producers;
+ }
+
+ /** Produce encoder data. */
+ public void produce(Encoder encoder) throws IOException {
+for (Producer producer : producers) {
+ producer.produce(encoder);
+}
+ }
+
+ /** Reset vector of consumers with the given {@link VectorSchemaRoot}. */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void resetProducerVectors(VectorSchemaRoot root) {
+// This method assumes that the VSR matches the constructed set of
producers
+int index = 0;
+for (Producer producer : producers) {
+ if (producer.resetValueVector(root.getFieldVectors().get(index))) {
+index++;
+ }
+}
+ }
+
+ @Override
+ public void close() {
+// clean up
+try {
+ AutoCloseables.close(producers);
+} catch (Exception e) {
+ throw new RuntimeException("Error occurs in close.", e);
Review Comment:
Per above, close and AutoCloable are gone
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
wgtmac commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1974765389
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/logical/AvroDecimalProducer.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.adapter.avro.producers.logical;
+
+import java.io.IOException;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces decimal values from a {@link DecimalVector}, writes
data to an Avro
+ * encoder.
+ */
+public abstract class AvroDecimalProducer extends
BaseAvroProducer {
+
+ /** Instantiate an AvroDecimalProducer. */
+ protected AvroDecimalProducer(DecimalVector vector) {
+super(vector);
+ }
+
+ /** Producer for decimal logical type with original bytes type. */
+ public static class BytesDecimalProducer extends AvroDecimalProducer {
+
+private final byte[] reuseBytes;
+
+/** Instantiate a BytesDecimalConsumer. */
+public BytesDecimalProducer(DecimalVector vector) {
+ super(vector);
+ Preconditions.checkArgument(
+ vector.getTypeWidth() <= 16, "Decimal bytes length should <= 16.");
+ reuseBytes = new byte[vector.getTypeWidth()];
Review Comment:
Well, I think I have mixed up the requirement from Iceberg which says
`Stored as fixed using the minimum number of bytes for the given precision.`
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1974724340
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/logical/AvroDecimalProducer.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.adapter.avro.producers.logical;
+
+import java.io.IOException;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces decimal values from a {@link DecimalVector}, writes
data to an Avro
+ * encoder.
+ */
+public abstract class AvroDecimalProducer extends
BaseAvroProducer {
+
+ /** Instantiate an AvroDecimalProducer. */
+ protected AvroDecimalProducer(DecimalVector vector) {
+super(vector);
+ }
+
+ /** Producer for decimal logical type with original bytes type. */
+ public static class BytesDecimalProducer extends AvroDecimalProducer {
+
+private final byte[] reuseBytes;
+
+/** Instantiate a BytesDecimalConsumer. */
+public BytesDecimalProducer(DecimalVector vector) {
+ super(vector);
+ Preconditions.checkArgument(
+ vector.getTypeWidth() <= 16, "Decimal bytes length should <= 16.");
+ reuseBytes = new byte[vector.getTypeWidth()];
Review Comment:
Decimal is fixed width byte (either 16 or 32)
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
wgtmac commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1974675294
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/logical/AvroDecimalProducer.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.adapter.avro.producers.logical;
+
+import java.io.IOException;
+import org.apache.arrow.adapter.avro.producers.BaseAvroProducer;
+import org.apache.arrow.util.Preconditions;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.avro.io.Encoder;
+
+/**
+ * Producer that produces decimal values from a {@link DecimalVector}, writes
data to an Avro
+ * encoder.
+ */
+public abstract class AvroDecimalProducer extends
BaseAvroProducer {
+
+ /** Instantiate an AvroDecimalProducer. */
+ protected AvroDecimalProducer(DecimalVector vector) {
+super(vector);
+ }
+
+ /** Producer for decimal logical type with original bytes type. */
+ public static class BytesDecimalProducer extends AvroDecimalProducer {
+
+private final byte[] reuseBytes;
+
+/** Instantiate a BytesDecimalConsumer. */
+public BytesDecimalProducer(DecimalVector vector) {
+ super(vector);
+ Preconditions.checkArgument(
+ vector.getTypeWidth() <= 16, "Decimal bytes length should <= 16.");
+ reuseBytes = new byte[vector.getTypeWidth()];
Review Comment:
Is this correct? I don't think the type width is constant for each value. It
might be similar to what you did in `AvroBytesProducer`.
##
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 vector type.
+ */
+public abstract class BaseAvroProducer implements
Producer {
+
+ 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:
Is there any restriction to the new `index`? Do we expect `index` <
`currentIndex`?
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/ArrowToAvroUtils.java:
##
@@ -0,0 +1,194 @@
+/*
+ * 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;
+
+import
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1972643290
##
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 vector type.
+ */
+public abstract class BaseAvroProducer implements
Producer {
+
+ 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;
+ }
+
+ @Override
+ public void close() throws Exception {
+vector.close();
+ }
+
+ @Override
+ public boolean resetValueVector(T vector) {
+this.vector = vector;
+this.currentIndex = 0;
+return true;
+ }
Review Comment:
Yeah, let's drop `close()` and `AutoClosable`!
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1972643154
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/Producer.java:
##
@@ -0,0 +1,62 @@
+/*
+ * 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;
+import org.apache.avro.io.Encoder;
+
+import java.io.IOException;
+
+/**
+ * Interface that is used to produce values to avro encoder.
+ *
+ * @param The vector within producer or its delegate, used for partially
produce purpose.
+ */
+public interface Producer extends AutoCloseable {
+
+ /**
+ * Produce a specific type value from the vector and write it to avro
encoder.
+ *
+ * @param encoder avro encoder to write data
+ * @throws IOException on error
+ */
+ void produce(Encoder encoder) throws IOException;
+
+ /** Skip null value in the vector by setting reader position + 1. */
+ void skipNull();
+
+ /** Set the position to read value from vector. */
+ void setPosition(int index);
Review Comment:
That sounds good to me.
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638: URL: https://github.com/apache/arrow-java/pull/638#discussion_r1971812587 ## adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/Producer.java: ## Review Comment: I'm following the naming pattern from the consumers, the top level interface there is just `Consumer`. I've matched the type names for all the individual type producers as well. -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2685419869 Thanks so much for all the comments! I've put questions in line, will wait for your answers on how to address those points. In the meantime I will add the schema generator and producers for the narrow primitive types, as well as some top level doc comments describing the translation. I'll make a start on the test coverage as well -- 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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1971822027
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/CompositeAvroProducer.java:
##
@@ -0,0 +1,69 @@
+/*
+ * 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 java.io.IOException;
+import java.util.List;
+
+import org.apache.arrow.util.AutoCloseables;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.avro.io.Encoder;
+
+/** Composite producer which holds all producers. It manages the produce and
cleanup process. */
+public class CompositeAvroProducer implements AutoCloseable {
+
+ private final List> producers;
+
+ public CompositeAvroProducer(List>
producers) {
+this.producers = producers;
+ }
+
+ public List> getProducers() {
+return producers;
+ }
+
+ /** Produce encoder data. */
+ public void produce(Encoder encoder) throws IOException {
+for (Producer producer : producers) {
+ producer.produce(encoder);
+}
+ }
+
+ /** Reset vector of consumers with the given {@link VectorSchemaRoot}. */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void resetProducerVectors(VectorSchemaRoot root) {
+// This method assumes that the VSR matches the constructed set of
producers
+int index = 0;
+for (Producer producer : producers) {
+ if (producer.resetValueVector(root.getFieldVectors().get(index))) {
+index++;
+ }
+}
+ }
+
+ @Override
+ public void close() {
+// clean up
+try {
+ AutoCloseables.close(producers);
+} catch (Exception e) {
+ throw new RuntimeException("Error occurs in close.", e);
Review Comment:
Per above, if producers are not owning / closing the vectors this issue goes
away. Otherwise yes this would make sense. Let me know, which you'd like me to
do.
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1971819669
##
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 vector type.
+ */
+public abstract class BaseAvroProducer implements
Producer {
+
+ 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;
+ }
+
+ @Override
+ public void close() throws Exception {
+vector.close();
+ }
+
+ @Override
+ public boolean resetValueVector(T vector) {
+this.vector = vector;
+this.currentIndex = 0;
+return true;
+ }
Review Comment:
I think I agree with you that producers should not own / close the vectors.
In which case, this becomes a non-issue! Are you happy for me to update on
those lines? The producers will still own a reference, but we could get rid of
all the close() methods and remove AutoClosable from the base interface. Would
you like me to do that?
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
martin-traverse commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1971815360
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/Producer.java:
##
@@ -0,0 +1,62 @@
+/*
+ * 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;
+import org.apache.avro.io.Encoder;
+
+import java.io.IOException;
+
+/**
+ * Interface that is used to produce values to avro encoder.
+ *
+ * @param The vector within producer or its delegate, used for partially
produce purpose.
+ */
+public interface Producer extends AutoCloseable {
+
+ /**
+ * Produce a specific type value from the vector and write it to avro
encoder.
+ *
+ * @param encoder avro encoder to write data
+ * @throws IOException on error
+ */
+ void produce(Encoder encoder) throws IOException;
+
+ /** Skip null value in the vector by setting reader position + 1. */
+ void skipNull();
+
+ /** Set the position to read value from vector. */
+ void setPosition(int index);
Review Comment:
Ok, that makes sense. We should really update the consumers to match. If you
like, I could make both int and long available as overloads, and keep a long
internally. That way we can update the consumer interface to match, without
breaking the API. Would you like me to do that?
--
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]
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
lidavidm commented on code in PR #638:
URL: https://github.com/apache/arrow-java/pull/638#discussion_r1970974511
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/Producer.java:
##
Review Comment:
nit: AvroProducer since everything else is named like that?
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/CompositeAvroProducer.java:
##
@@ -0,0 +1,69 @@
+/*
+ * 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 java.io.IOException;
+import java.util.List;
+
+import org.apache.arrow.util.AutoCloseables;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.avro.io.Encoder;
+
+/** Composite producer which holds all producers. It manages the produce and
cleanup process. */
+public class CompositeAvroProducer implements AutoCloseable {
+
+ private final List> producers;
+
+ public CompositeAvroProducer(List>
producers) {
+this.producers = producers;
+ }
+
+ public List> getProducers() {
+return producers;
+ }
+
+ /** Produce encoder data. */
+ public void produce(Encoder encoder) throws IOException {
+for (Producer producer : producers) {
+ producer.produce(encoder);
+}
+ }
+
+ /** Reset vector of consumers with the given {@link VectorSchemaRoot}. */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void resetProducerVectors(VectorSchemaRoot root) {
+// This method assumes that the VSR matches the constructed set of
producers
+int index = 0;
+for (Producer producer : producers) {
+ if (producer.resetValueVector(root.getFieldVectors().get(index))) {
+index++;
+ }
+}
+ }
+
+ @Override
+ public void close() {
+// clean up
+try {
+ AutoCloseables.close(producers);
+} catch (Exception e) {
+ throw new RuntimeException("Error occurs in close.", e);
Review Comment:
Normally `close` is declared to throw `Exception` anyways - do we need to
rewrap this in RuntimeException?
Otherwise use `AutoCloseables.closeNoChecked`
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/Producer.java:
##
@@ -0,0 +1,62 @@
+/*
+ * 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;
+import org.apache.avro.io.Encoder;
+
+import java.io.IOException;
+
+/**
+ * Interface that is used to produce values to avro encoder.
+ *
+ * @param The vector within producer or its delegate, used for partially
produce purpose.
+ */
+public interface Producer extends AutoCloseable {
+
+ /**
+ * Produce a specific type value from the vector and write it to avro
encoder.
+ *
+ * @param encoder avro encoder to write data
+ * @throws IOException on error
+ */
+ void produce(Encoder encoder) throws IOException;
+
+ /** Skip null value in the vector by setting reader position + 1. */
+ void skipNull();
+
+ /** Set the position to read value from vector. */
+ void setPosition(int index);
Review Comment:
I think we've been trying to be future-proof and use `long` for indices now
(since eventually once we support the new memory APIs we'll be able to address
more than 2GiB of memory at once)
##
adapter/avro/src/main/java/org/apache/arrow/adapter/avro/producers/BaseAvroProducer.java:
##
@@ -0,0
Re: [PR] GH-615: Produce Avro core data types out of Arrow VSR [arrow-java]
github-actions[bot] commented on PR #638: URL: https://github.com/apache/arrow-java/pull/638#issuecomment-2683793488 Thank you for opening a pull request! Please label the PR with one or more of: - bug-fix - chore - dependencies - documentation - enhancement Also, add the 'breaking-change' label if appropriate. See [CONTRIBUTING.md](https://github.com/apache/arrow-java/blob/main/CONTRIBUTING.md) for details. -- 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]
