33
33
import org .apache .arrow .vector .complex .writer .BaseWriter .StructWriter ;
34
34
import org .apache .arrow .vector .complex .writer .FieldWriter ;
35
35
import org .apache .arrow .vector .holders .DecimalHolder ;
36
+ import org .apache .arrow .vector .holders .DurationHolder ;
36
37
import org .apache .arrow .vector .types .Types ;
37
38
import org .apache .arrow .vector .types .pojo .ArrowType ;
38
39
import org .apache .arrow .vector .types .pojo .FieldType ;
@@ -831,7 +832,6 @@ public void testCopyMapVectorWithMapValue() {
831
832
832
833
from .setValueCount (COUNT );
833
834
834
- // copy values
835
835
FieldReader in = from .getReader ();
836
836
FieldWriter out = to .getWriter ();
837
837
for (int i = 0 ; i < COUNT ; i ++) {
@@ -841,7 +841,138 @@ public void testCopyMapVectorWithMapValue() {
841
841
}
842
842
to .setValueCount (COUNT );
843
843
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
+
845
976
assertTrue (VectorEqualsVisitor .vectorEquals (from , to ));
846
977
}
847
978
}
0 commit comments