]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / vector / src / main / codegen / templates / AbstractPromotableFieldWriter.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 <@pp.dropOutputFile />
19 <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/AbstractPromotableFieldWriter.java" />
20
21
22 <#include "/@includes/license.ftl" />
23
24 package org.apache.arrow.vector.complex.impl;
25
26 <#include "/@includes/vv_imports.ftl" />
27
28 /*
29 * A FieldWriter which delegates calls to another FieldWriter. The delegate FieldWriter can be promoted to a new type
30 * when necessary. Classes that extend this class are responsible for handling promotion.
31 *
32 * This class is generated using freemarker and the ${.template_name} template.
33 *
34 */
35 @SuppressWarnings("unused")
36 abstract class AbstractPromotableFieldWriter extends AbstractFieldWriter {
37 /**
38 * Retrieve the FieldWriter, promoting if it is not a FieldWriter of the specified type
39 * @param type the type of the values we want to write
40 * @return the corresponding field writer
41 */
42 protected FieldWriter getWriter(MinorType type) {
43 return getWriter(type, null);
44 }
45
46 abstract protected FieldWriter getWriter(MinorType type, ArrowType arrowType);
47
48 /**
49 * @return the current FieldWriter
50 */
51 abstract protected FieldWriter getWriter();
52
53 @Override
54 public void start() {
55 getWriter(MinorType.STRUCT).start();
56 }
57
58 @Override
59 public void end() {
60 getWriter(MinorType.STRUCT).end();
61 setPosition(idx() + 1);
62 }
63
64 @Override
65 public void startList() {
66 getWriter(MinorType.LIST).startList();
67 }
68
69 @Override
70 public void endList() {
71 getWriter(MinorType.LIST).endList();
72 setPosition(idx() + 1);
73 }
74
75 @Override
76 public void startMap() {
77 getWriter(MinorType.MAP).startMap();
78 }
79
80 @Override
81 public void endMap() {
82 getWriter(MinorType.MAP).endMap();
83 setPosition(idx() + 1);
84 }
85
86 @Override
87 public void startEntry() {
88 getWriter(MinorType.MAP).startEntry();
89 }
90
91 @Override
92 public MapWriter key() {
93 return getWriter(MinorType.MAP).key();
94 }
95
96 @Override
97 public MapWriter value() {
98 return getWriter(MinorType.MAP).value();
99 }
100
101 @Override
102 public void endEntry() {
103 getWriter(MinorType.MAP).endEntry();
104 }
105
106 <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
107 <#assign fields = minor.fields!type.fields />
108 <#if minor.class != "Decimal" && minor.class != "Decimal256">
109 @Override
110 public void write(${name}Holder holder) {
111 getWriter(MinorType.${name?upper_case}).write(holder);
112 }
113
114 public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
115 getWriter(MinorType.${name?upper_case}).write${minor.class}(<#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
116 }
117
118 <#elseif minor.class == "Decimal">
119 @Override
120 public void write(DecimalHolder holder) {
121 getWriter(MinorType.DECIMAL).write(holder);
122 }
123
124 public void writeDecimal(int start, ArrowBuf buffer, ArrowType arrowType) {
125 getWriter(MinorType.DECIMAL).writeDecimal(start, buffer, arrowType);
126 }
127
128 public void writeDecimal(int start, ArrowBuf buffer) {
129 getWriter(MinorType.DECIMAL).writeDecimal(start, buffer);
130 }
131
132 public void writeBigEndianBytesToDecimal(byte[] value, ArrowType arrowType) {
133 getWriter(MinorType.DECIMAL).writeBigEndianBytesToDecimal(value, arrowType);
134 }
135
136 public void writeBigEndianBytesToDecimal(byte[] value) {
137 getWriter(MinorType.DECIMAL).writeBigEndianBytesToDecimal(value);
138 }
139 <#elseif minor.class == "Decimal256">
140 @Override
141 public void write(Decimal256Holder holder) {
142 getWriter(MinorType.DECIMAL256).write(holder);
143 }
144
145 public void writeDecimal256(long start, ArrowBuf buffer, ArrowType arrowType) {
146 getWriter(MinorType.DECIMAL256).writeDecimal256(start, buffer, arrowType);
147 }
148
149 public void writeDecimal256(long start, ArrowBuf buffer) {
150 getWriter(MinorType.DECIMAL256).writeDecimal256(start, buffer);
151 }
152 public void writeBigEndianBytesToDecimal256(byte[] value, ArrowType arrowType) {
153 getWriter(MinorType.DECIMAL256).writeBigEndianBytesToDecimal256(value, arrowType);
154 }
155
156 public void writeBigEndianBytesToDecimal256(byte[] value) {
157 getWriter(MinorType.DECIMAL256).writeBigEndianBytesToDecimal256(value);
158 }
159
160
161 </#if>
162
163 </#list></#list>
164 public void writeNull() {
165 }
166
167 @Override
168 public StructWriter struct() {
169 return getWriter(MinorType.LIST).struct();
170 }
171
172 @Override
173 public ListWriter list() {
174 return getWriter(MinorType.LIST).list();
175 }
176
177 @Override
178 public MapWriter map() {
179 return getWriter(MinorType.LIST).map();
180 }
181
182 @Override
183 public MapWriter map(boolean keysSorted) {
184 return getWriter(MinorType.MAP, new ArrowType.Map(keysSorted));
185 }
186
187 @Override
188 public StructWriter struct(String name) {
189 return getWriter(MinorType.STRUCT).struct(name);
190 }
191
192 @Override
193 public ListWriter list(String name) {
194 return getWriter(MinorType.STRUCT).list(name);
195 }
196
197 @Override
198 public MapWriter map(String name) {
199 return getWriter(MinorType.STRUCT).map(name);
200 }
201
202 @Override
203 public MapWriter map(String name, boolean keysSorted) {
204 return getWriter(MinorType.STRUCT).map(name, keysSorted);
205 }
206 <#list vv.types as type><#list type.minor as minor>
207 <#assign lowerName = minor.class?uncap_first />
208 <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
209 <#assign upperName = minor.class?upper_case />
210 <#assign capName = minor.class?cap_first />
211
212 <#if minor.typeParams?? >
213 @Override
214 public ${capName}Writer ${lowerName}(String name<#list minor.typeParams as typeParam>, ${typeParam.type} ${typeParam.name}</#list>) {
215 return getWriter(MinorType.STRUCT).${lowerName}(name<#list minor.typeParams as typeParam>, ${typeParam.name}</#list>);
216 }
217
218 </#if>
219 @Override
220 public ${capName}Writer ${lowerName}(String name) {
221 return getWriter(MinorType.STRUCT).${lowerName}(name);
222 }
223
224 @Override
225 public ${capName}Writer ${lowerName}() {
226 return getWriter(MinorType.LIST).${lowerName}();
227 }
228
229 </#list></#list>
230
231 public void copyReader(FieldReader reader) {
232 getWriter().copyReader(reader);
233 }
234
235 public void copyReaderToField(String name, FieldReader reader) {
236 getWriter().copyReaderToField(name, reader);
237 }
238 }