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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 <@pp.dropOutputFile
/>
19 <@pp.changeOutputFile name
="/org/apache/arrow/vector/complex/impl/AbstractPromotableFieldWriter.java" />
22 <#include
"/@includes/license.ftl" />
24 package org
.apache
.arrow
.vector
.complex
.impl
;
26 <#include
"/@includes/vv_imports.ftl" />
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.
32 * This class is generated using freemarker and the ${.template_name} template.
35 @SuppressWarnings("unused")
36 abstract class AbstractPromotableFieldWriter
extends AbstractFieldWriter
{
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
42 protected FieldWriter
getWriter(MinorType type
) {
43 return getWriter(type
, null);
46 abstract protected FieldWriter
getWriter(MinorType type
, ArrowType arrowType
);
49 * @return the current FieldWriter
51 abstract protected FieldWriter
getWriter();
55 getWriter(MinorType
.STRUCT
).start();
60 getWriter(MinorType
.STRUCT
).end();
61 setPosition(idx() + 1);
65 public void startList() {
66 getWriter(MinorType
.LIST
).startList();
70 public void endList() {
71 getWriter(MinorType
.LIST
).endList();
72 setPosition(idx() + 1);
76 public void startMap() {
77 getWriter(MinorType
.MAP
).startMap();
81 public void endMap() {
82 getWriter(MinorType
.MAP
).endMap();
83 setPosition(idx() + 1);
87 public void startEntry() {
88 getWriter(MinorType
.MAP
).startEntry();
92 public MapWriter
key() {
93 return getWriter(MinorType
.MAP
).key();
97 public MapWriter
value() {
98 return getWriter(MinorType
.MAP
).value();
102 public void endEntry() {
103 getWriter(MinorType
.MAP
).endEntry();
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">
110 public void write($
{name
}Holder holder
) {
111 getWriter(MinorType
.$
{name?upper_case
}).write(holder
);
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
>);
118 <#elseif minor
.class == "Decimal">
120 public void write(DecimalHolder holder
) {
121 getWriter(MinorType
.DECIMAL
).write(holder
);
124 public void writeDecimal(int start
, ArrowBuf buffer
, ArrowType arrowType
) {
125 getWriter(MinorType
.DECIMAL
).writeDecimal(start
, buffer
, arrowType
);
128 public void writeDecimal(int start
, ArrowBuf buffer
) {
129 getWriter(MinorType
.DECIMAL
).writeDecimal(start
, buffer
);
132 public void writeBigEndianBytesToDecimal(byte[] value
, ArrowType arrowType
) {
133 getWriter(MinorType
.DECIMAL
).writeBigEndianBytesToDecimal(value
, arrowType
);
136 public void writeBigEndianBytesToDecimal(byte[] value
) {
137 getWriter(MinorType
.DECIMAL
).writeBigEndianBytesToDecimal(value
);
139 <#elseif minor
.class == "Decimal256">
141 public void write(Decimal256Holder holder
) {
142 getWriter(MinorType
.DECIMAL256
).write(holder
);
145 public void writeDecimal256(long start
, ArrowBuf buffer
, ArrowType arrowType
) {
146 getWriter(MinorType
.DECIMAL256
).writeDecimal256(start
, buffer
, arrowType
);
149 public void writeDecimal256(long start
, ArrowBuf buffer
) {
150 getWriter(MinorType
.DECIMAL256
).writeDecimal256(start
, buffer
);
152 public void writeBigEndianBytesToDecimal256(byte[] value
, ArrowType arrowType
) {
153 getWriter(MinorType
.DECIMAL256
).writeBigEndianBytesToDecimal256(value
, arrowType
);
156 public void writeBigEndianBytesToDecimal256(byte[] value
) {
157 getWriter(MinorType
.DECIMAL256
).writeBigEndianBytesToDecimal256(value
);
164 public void writeNull() {
168 public StructWriter
struct() {
169 return getWriter(MinorType
.LIST
).struct();
173 public ListWriter
list() {
174 return getWriter(MinorType
.LIST
).list();
178 public MapWriter
map() {
179 return getWriter(MinorType
.LIST
).map();
183 public MapWriter
map(boolean keysSorted
) {
184 return getWriter(MinorType
.MAP
, new ArrowType
.Map(keysSorted
));
188 public StructWriter
struct(String name
) {
189 return getWriter(MinorType
.STRUCT
).struct(name
);
193 public ListWriter
list(String name
) {
194 return getWriter(MinorType
.STRUCT
).list(name
);
198 public MapWriter
map(String name
) {
199 return getWriter(MinorType
.STRUCT
).map(name
);
203 public MapWriter
map(String name
, boolean keysSorted
) {
204 return getWriter(MinorType
.STRUCT
).map(name
, keysSorted
);
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
/>
212 <#
if minor
.typeParams??
>
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
>);
220 public $
{capName
}Writer $
{lowerName
}(String name
) {
221 return getWriter(MinorType
.STRUCT
).$
{lowerName
}(name
);
225 public $
{capName
}Writer $
{lowerName
}() {
226 return getWriter(MinorType
.LIST
).$
{lowerName
}();
231 public void copyReader(FieldReader reader
) {
232 getWriter().copyReader(reader
);
235 public void copyReaderToField(String name
, FieldReader reader
) {
236 getWriter().copyReaderToField(name
, reader
);