3333
3434import java .util .Objects ;
3535
36+ /**
37+ * Arrow types
38+ **/
3639public abstract class ArrowType {
3740
3841 public abstract byte getTypeType ();
3942 public abstract int getType (FlatBufferBuilder builder );
4043 public abstract <T > T accept (ArrowTypeVisitor <T > visitor );
4144
45+ /**
46+ * to visit the ArrowTypes
47+ * <code>
48+ * type.accept(new ArrowTypeVisitor<Type>() {
49+ * ...
50+ * });
51+ * </code>
52+ */
4253 public static interface ArrowTypeVisitor <T > {
4354 <#list arrowTypes .types as type >
4455 T visit ($ {type .name } type );
@@ -55,9 +66,7 @@ public static class ${name} extends ArrowType {
5566 </#if >
5667
5768 <#list fields as field >
58- <#assign fieldName = field .name >
59- <#assign fieldType = field .type >
60- $ {fieldType } $ {fieldName };
69+ $ {field .type } $ {field .name };
6170 </#list >
6271
6372 <#if type .fields ?size != 0 >
@@ -79,6 +88,9 @@ public int getType(FlatBufferBuilder builder) {
7988 <#if field .type == "String" >
8089 int $ {field .name } = builder .createString (this .$ {field .name });
8190 </#if >
91+ <#if field .type == "int[]" >
92+ int $ {field .name } = org .apache .arrow .flatbuf .$ {type .name }.create$ {field .name ?cap_first }Vector (builder , this .$ {field .name });
93+ </#if >
8294 </#list >
8395 org .apache .arrow .flatbuf .$ {type .name }.start$ {type .name }(builder );
8496 <#list type .fields as field >
@@ -96,7 +108,7 @@ public int getType(FlatBufferBuilder builder) {
96108 public String toString () {
97109 return "${name}{"
98110 <#list fields as field >
99- + ", " + $ {field .name }
111+ + <# if field . type == "int[]" > java . util . Arrays . toString ( $ {field .name })<# else > $ { field . name }</# if ><# if field_has_next > + ", " </# if >
100112 </#list >
101113 + "}" ;
102114 }
@@ -115,8 +127,7 @@ public boolean equals(Object obj) {
115127 return true ;
116128 <#else >
117129 $ {type .name } that = ($ {type .name }) obj ;
118- return
119- <#list type .fields as field >Objects .equals (this .$ {field .name }, that .$ {field .name }) <#if field_has_next >&&<#else >;</#if >
130+ return <#list type .fields as field >Objects .deepEquals (this .$ {field .name }, that .$ {field .name }) <#if field_has_next >&&<#else >;</#if >
120131 </#list >
121132 </#if >
122133 }
@@ -134,9 +145,20 @@ public static org.apache.arrow.vector.types.pojo.ArrowType getTypeForField(org.a
134145 <#assign name = type .name >
135146 <#assign nameLower = type .name ?lower_case >
136147 <#assign fields = type .fields >
137- case Type .$ {type .name }:
148+ case Type .$ {type .name }: {
138149 org .apache .arrow .flatbuf .$ {type .name } $ {nameLower }Type = (org .apache .arrow .flatbuf .$ {type .name }) field .type (new org .apache .arrow .flatbuf .$ {type .name }());
139- return new $ {type .name }(<#list type .fields as field >$ {nameLower }Type .$ {field .name }()<#if field_has_next >, </#if ></#list >);
150+ <#list type .fields as field >
151+ <#if field .type == "int[]">
152+ $ {field .type } $ {field .name } = new int[$ {nameLower }Type .$ {field .name }Length ()];
153+ for (int i = 0 ; i < $ {field .name }.length ; ++i ) {
154+ $ {field .name }[i ] = $ {nameLower }Type .$ {field .name }(i );
155+ }
156+ <#else >
157+ $ {field .type } $ {field .name } = $ {nameLower }Type .$ {field .name }();
158+ </#if >
159+ </#list >
160+ return new $ {type .name }(<#list type .fields as field >$ {field .name }<#if field_has_next >, </#if ></#list >);
161+ }
140162 </#list >
141163 default :
142164 throw new UnsupportedOperationException ("Unsupported type : " + field .typeType ());
0 commit comments