jbonofre commented on code in PR #1519:
URL: https://github.com/apache/arrow-java/pull/1519#discussion_r4678183110


##########
vector/src/test/java/org/apache/arrow/vector/complex/impl/TestDecimal256WriterPromotion.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.vector.complex.impl;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.complex.ListVector;
+import org.junit.jupiter.api.Test;
+
+public class TestDecimal256WriterPromotion {

Review Comment:
   As @lidavidm noted, please move this test into the existing 
`TestPromotableWriter` class (in the same package) instead of creating a new 
single-test file. `TestPromotableWriter` also sets up `DirtyRootAllocator` in 
`@BeforeEach`/`@AfterEach` for leak/buffer checking.



##########
vector/src/main/codegen/templates/PromotableWriter.java:
##########
@@ -316,6 +316,7 @@ public void setPosition(int index) {
 
   protected boolean requiresArrowType(MinorType type) {
     return type == MinorType.DECIMAL
+        || type == MinorType.DECIMAL256

Review Comment:
   It looks good, verified against `ValueVectorTypes.tdd` that `DECIMAL256` was 
the remaining `typeParams`-bearing minor type missing from `requiresArrowType`, 
and `PromotableViewWriter` inherits this check as well.



##########
vector/src/test/java/org/apache/arrow/vector/complex/impl/TestDecimal256WriterPromotion.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.vector.complex.impl;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.complex.ListVector;
+import org.junit.jupiter.api.Test;
+
+public class TestDecimal256WriterPromotion {
+  @Test
+  public void testDecimal256InPromotedUnion() {
+    BigDecimal narrow = new BigDecimal("123.45");
+    BigDecimal wide = new 
BigDecimal("123456789012345678901234567890123456789.01");
+    try (BufferAllocator allocator = new RootAllocator();
+        ListVector vector = ListVector.empty("decimals", allocator)) {
+      UnionListWriter writer = vector.getWriter();
+      writer.startList();
+      writer.decimal().writeDecimal(narrow);
+      writer.decimal256().writeDecimal256(wide);
+      writer.decimal().writeDecimal(narrow.negate());
+      writer.decimal256().writeDecimal256(wide.negate());
+      writer.endList();
+      vector.setValueCount(1);
+      assertEquals(
+          Arrays.asList(narrow, wide, narrow.negate(), wide.negate()), 
vector.getObject(0));
+      vector.validateFull();
+    }

Review Comment:
   Right now this only exercises `ListVector` (`UnionListVector`) promoting 
from `DECIMAL` -> `DECIMAL256` via `writeDecimal256(BigDecimal)`. Could you 
also cover:
   
   - Writing `Decimal256` when the writer is already in `State.UNION` (e.g. 
`Int` -> `VarChar` -> `Decimal256`) so both `state == State.UNION` and `type != 
this.type` in `PromotableWriter.getWriter` are tested.
   - Direct `StructVector` / `PromotableWriter` promotion to `DECIMAL256` 
(similar to `testPromoteToUnionFromDecimal` in `TestPromotableWriter`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to