3333import org .apache .arrow .vector .complex .writer .BaseWriter .StructWriter ;
3434import org .apache .arrow .vector .complex .writer .FieldWriter ;
3535import org .apache .arrow .vector .holders .DecimalHolder ;
36+ import org .apache .arrow .vector .holders .DurationHolder ;
3637import org .apache .arrow .vector .types .Types ;
3738import org .apache .arrow .vector .types .pojo .ArrowType ;
3839import org .apache .arrow .vector .types .pojo .FieldType ;
@@ -831,7 +832,6 @@ public void testCopyMapVectorWithMapValue() {
831832
832833 from .setValueCount (COUNT );
833834
834- // copy values
835835 FieldReader in = from .getReader ();
836836 FieldWriter out = to .getWriter ();
837837 for (int i = 0 ; i < COUNT ; i ++) {
@@ -841,7 +841,138 @@ public void testCopyMapVectorWithMapValue() {
841841 }
842842 to .setValueCount (COUNT );
843843
844- // validate equals
844+ assertTrue (VectorEqualsVisitor .vectorEquals (from , to ));
845+ }
846+ }
847+
848+ @ Test
849+ public void testCopyDurationVector () {
850+ try (ListVector from = ListVector .empty ("v" , allocator );
851+ ListVector to = ListVector .empty ("v" , allocator )) {
852+
853+ UnionListWriter listWriter = from .getWriter ();
854+ listWriter .allocate ();
855+
856+ DurationHolder durationHolder = new DurationHolder ();
857+ for (int i = 0 ; i < COUNT ; i ++) {
858+ listWriter .setPosition (i );
859+ listWriter .startList ();
860+ durationHolder .value = 123456789L ;
861+ listWriter .duration ().write (durationHolder );
862+ listWriter .endList ();
863+ }
864+ from .setValueCount (COUNT );
865+
866+ FieldReader in = from .getReader ();
867+ FieldWriter out = to .getWriter ();
868+ for (int i = 0 ; i < COUNT ; i ++) {
869+ in .setPosition (i );
870+ out .setPosition (i );
871+ ComplexCopier .copy (in , out );
872+ }
873+
874+ to .setValueCount (COUNT );
875+
876+ assertTrue (VectorEqualsVisitor .vectorEquals (from , to ));
877+ }
878+ }
879+
880+ @ Test
881+ public void testCopyListVectorWithDuration () {
882+ try (ListVector from = ListVector .empty ("v" , allocator );
883+ ListVector to = ListVector .empty ("v" , allocator )) {
884+
885+ UnionListWriter listWriter = from .getWriter ();
886+ listWriter .allocate ();
887+
888+ DurationHolder durationHolder = new DurationHolder ();
889+ for (int i = 0 ; i < COUNT ; i ++) {
890+ listWriter .setPosition (i );
891+ listWriter .startList ();
892+ durationHolder .value = 123456789L ;
893+ listWriter .duration ().write (durationHolder );
894+ listWriter .endList ();
895+ }
896+ from .setValueCount (COUNT );
897+
898+ FieldReader in = from .getReader ();
899+ FieldWriter out = to .getWriter ();
900+ for (int i = 0 ; i < COUNT ; i ++) {
901+ in .setPosition (i );
902+ out .setPosition (i );
903+ ComplexCopier .copy (in , out );
904+ }
905+
906+ to .setValueCount (COUNT );
907+
908+ assertTrue (VectorEqualsVisitor .vectorEquals (from , to ));
909+ }
910+ }
911+
912+ @ Test
913+ public void testCopyMapVectorWithDurationValue () {
914+ try (MapVector from = MapVector .empty ("v" , allocator , false );
915+ MapVector to = MapVector .empty ("v" , allocator , false )) {
916+
917+ UnionMapWriter mapWriter = from .getWriter ();
918+ mapWriter .allocate ();
919+
920+ DurationHolder durationHolder = new DurationHolder ();
921+ for (int i = 0 ; i < COUNT ; i ++) {
922+ mapWriter .setPosition (i );
923+ mapWriter .startMap ();
924+ mapWriter .startEntry ();
925+ mapWriter .key ().integer ().writeInt (i );
926+ durationHolder .value = 123456789L ;
927+ mapWriter .value ().duration ().write (durationHolder );
928+ mapWriter .endEntry ();
929+ mapWriter .endMap ();
930+ }
931+ from .setValueCount (COUNT );
932+
933+ FieldReader in = from .getReader ();
934+ FieldWriter out = to .getWriter ();
935+ for (int i = 0 ; i < COUNT ; i ++) {
936+ in .setPosition (i );
937+ out .setPosition (i );
938+ ComplexCopier .copy (in , out );
939+ }
940+
941+ to .setValueCount (COUNT );
942+
943+ assertTrue (VectorEqualsVisitor .vectorEquals (from , to ));
944+ }
945+ }
946+
947+ @ Test
948+ public void testCopyStructVectorWithDurationValue () {
949+ try (StructVector from = StructVector .empty ("v" , allocator );
950+ StructVector to = StructVector .empty ("v" , allocator )) {
951+
952+ from .allocateNew ();
953+
954+ NullableStructWriter structWriter = from .getWriter ();
955+ DurationHolder durationHolder = new DurationHolder ();
956+
957+ for (int i = 0 ; i < COUNT ; i ++) {
958+ structWriter .setPosition (i );
959+ structWriter .start ();
960+ durationHolder .value = 123456789L ;
961+ structWriter .duration ("durationField" ).write (durationHolder );
962+ structWriter .end ();
963+ }
964+
965+ from .setValueCount (COUNT );
966+
967+ FieldReader in = from .getReader ();
968+ FieldWriter out = to .getWriter ();
969+ for (int i = 0 ; i < COUNT ; i ++) {
970+ in .setPosition (i );
971+ out .setPosition (i );
972+ ComplexCopier .copy (in , out );
973+ }
974+ to .setValueCount (COUNT );
975+
845976 assertTrue (VectorEqualsVisitor .vectorEquals (from , to ));
846977 }
847978 }
0 commit comments