]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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 | <#list vv.types as type> | |
20 | <#list type.minor as minor> | |
21 | <#list ["Nullable"] as mode> | |
22 | <#assign name = minor.class?cap_first /> | |
23 | <#assign eName = name /> | |
24 | <#assign javaType = (minor.javaType!type.javaType) /> | |
25 | <#assign fields = minor.fields!type.fields /> | |
26 | <#assign friendlyType = (minor.friendlyType!minor.boxedType!type.boxedType) /> | |
27 | ||
28 | <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/${eName}WriterImpl.java" /> | |
29 | <#include "/@includes/license.ftl" /> | |
30 | ||
31 | package org.apache.arrow.vector.complex.impl; | |
32 | ||
33 | <#include "/@includes/vv_imports.ftl" /> | |
34 | ||
35 | /* | |
36 | * This class is generated using FreeMarker on the ${.template_name} template. | |
37 | */ | |
38 | @SuppressWarnings("unused") | |
39 | public class ${eName}WriterImpl extends AbstractFieldWriter { | |
40 | ||
41 | final ${name}Vector vector; | |
42 | ||
43 | public ${eName}WriterImpl(${name}Vector vector) { | |
44 | this.vector = vector; | |
45 | } | |
46 | ||
47 | @Override | |
48 | public Field getField() { | |
49 | return vector.getField(); | |
50 | } | |
51 | ||
52 | @Override | |
53 | public int getValueCapacity() { | |
54 | return vector.getValueCapacity(); | |
55 | } | |
56 | ||
57 | @Override | |
58 | public void allocate() { | |
59 | vector.allocateNew(); | |
60 | } | |
61 | ||
62 | @Override | |
63 | public void close() { | |
64 | vector.close(); | |
65 | } | |
66 | ||
67 | @Override | |
68 | public void clear() { | |
69 | vector.clear(); | |
70 | } | |
71 | ||
72 | @Override | |
73 | protected int idx() { | |
74 | return super.idx(); | |
75 | } | |
76 | ||
77 | <#if mode == "Repeated"> | |
78 | ||
79 | public void write(${minor.class?cap_first}Holder h) { | |
80 | mutator.addSafe(idx(), h); | |
81 | vector.setValueCount(idx()+1); | |
82 | } | |
83 | ||
84 | public void write(${minor.class?cap_first}Holder h) { | |
85 | mutator.addSafe(idx(), h); | |
86 | vector.setValueCount(idx()+1); | |
87 | } | |
88 | ||
89 | public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) { | |
90 | mutator.addSafe(idx(), <#list fields as field>${field.name}<#if field_has_next>, </#if></#list>); | |
91 | vector.setValueCount(idx()+1); | |
92 | } | |
93 | ||
94 | public void setPosition(int idx) { | |
95 | super.setPosition(idx); | |
96 | mutator.startNewValue(idx); | |
97 | } | |
98 | ||
99 | ||
100 | <#else> | |
101 | ||
102 | <#if !minor.class?starts_with("Decimal")> | |
103 | public void write(${minor.class}Holder h) { | |
104 | vector.setSafe(idx(), h); | |
105 | vector.setValueCount(idx()+1); | |
106 | } | |
107 | ||
108 | public void write(Nullable${minor.class}Holder h) { | |
109 | vector.setSafe(idx(), h); | |
110 | vector.setValueCount(idx()+1); | |
111 | } | |
112 | ||
113 | public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) { | |
114 | vector.setSafe(idx(), 1<#list fields as field><#if field.include!true >, ${field.name}</#if></#list>); | |
115 | vector.setValueCount(idx()+1); | |
116 | } | |
117 | </#if> | |
118 | ||
119 | <#if minor.class == "VarChar"> | |
120 | public void write${minor.class}(${friendlyType} value) { | |
121 | vector.setSafe(idx(), value); | |
122 | vector.setValueCount(idx()+1); | |
123 | } | |
124 | </#if> | |
125 | ||
126 | <#if minor.class?starts_with("Decimal")> | |
127 | ||
128 | public void write(${minor.class}Holder h){ | |
129 | DecimalUtility.checkPrecisionAndScale(h.precision, h.scale, vector.getPrecision(), vector.getScale()); | |
130 | vector.setSafe(idx(), h); | |
131 | vector.setValueCount(idx() + 1); | |
132 | } | |
133 | ||
134 | public void write(Nullable${minor.class}Holder h){ | |
135 | if (h.isSet == 1) { | |
136 | DecimalUtility.checkPrecisionAndScale(h.precision, h.scale, vector.getPrecision(), vector.getScale()); | |
137 | } | |
138 | vector.setSafe(idx(), h); | |
139 | vector.setValueCount(idx() + 1); | |
140 | } | |
141 | ||
142 | public void write${minor.class}(long start, ArrowBuf buffer){ | |
143 | vector.setSafe(idx(), 1, start, buffer); | |
144 | vector.setValueCount(idx() + 1); | |
145 | } | |
146 | ||
147 | public void write${minor.class}(long start, ArrowBuf buffer, ArrowType arrowType){ | |
148 | DecimalUtility.checkPrecisionAndScale(((ArrowType.Decimal) arrowType).getPrecision(), | |
149 | ((ArrowType.Decimal) arrowType).getScale(), vector.getPrecision(), vector.getScale()); | |
150 | vector.setSafe(idx(), 1, start, buffer); | |
151 | vector.setValueCount(idx() + 1); | |
152 | } | |
153 | ||
154 | public void write${minor.class}(BigDecimal value){ | |
155 | // vector.setSafe already does precision and scale checking | |
156 | vector.setSafe(idx(), value); | |
157 | vector.setValueCount(idx() + 1); | |
158 | } | |
159 | ||
160 | public void writeBigEndianBytesTo${minor.class}(byte[] value, ArrowType arrowType){ | |
161 | DecimalUtility.checkPrecisionAndScale(((ArrowType.Decimal) arrowType).getPrecision(), | |
162 | ((ArrowType.Decimal) arrowType).getScale(), vector.getPrecision(), vector.getScale()); | |
163 | vector.setBigEndianSafe(idx(), value); | |
164 | vector.setValueCount(idx() + 1); | |
165 | } | |
166 | ||
167 | public void writeBigEndianBytesTo${minor.class}(byte[] value){ | |
168 | vector.setBigEndianSafe(idx(), value); | |
169 | vector.setValueCount(idx() + 1); | |
170 | } | |
171 | </#if> | |
172 | ||
173 | ||
174 | public void writeNull() { | |
175 | vector.setNull(idx()); | |
176 | vector.setValueCount(idx()+1); | |
177 | } | |
178 | </#if> | |
179 | } | |
180 | ||
181 | <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/writer/${eName}Writer.java" /> | |
182 | <#include "/@includes/license.ftl" /> | |
183 | ||
184 | package org.apache.arrow.vector.complex.writer; | |
185 | ||
186 | <#include "/@includes/vv_imports.ftl" /> | |
187 | /* | |
188 | * This class is generated using FreeMarker on the ${.template_name} template. | |
189 | */ | |
190 | @SuppressWarnings("unused") | |
191 | public interface ${eName}Writer extends BaseWriter { | |
192 | public void write(${minor.class}Holder h); | |
193 | ||
194 | <#if minor.class?starts_with("Decimal")>@Deprecated</#if> | |
195 | public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>); | |
196 | <#if minor.class?starts_with("Decimal")> | |
197 | ||
198 | public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>, ArrowType arrowType); | |
199 | ||
200 | public void write${minor.class}(${friendlyType} value); | |
201 | ||
202 | public void writeBigEndianBytesTo${minor.class}(byte[] value, ArrowType arrowType); | |
203 | ||
204 | @Deprecated | |
205 | public void writeBigEndianBytesTo${minor.class}(byte[] value); | |
206 | </#if> | |
207 | } | |
208 | ||
209 | </#list> | |
210 | </#list> | |
211 | </#list> |