|
| 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 | +import io.netty.buffer.ArrowBuf; |
| 19 | +import org.apache.arrow.vector.complex.writer.DecimalWriter; |
| 20 | +import org.apache.arrow.vector.holders.DecimalHolder; |
| 21 | + |
| 22 | +import java.lang.UnsupportedOperationException; |
| 23 | +import java.math.BigDecimal; |
| 24 | + |
| 25 | +<@pp.dropOutputFile /> |
| 26 | +<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/UnionFixedSizeListWriter.java" /> |
| 27 | + |
| 28 | + |
| 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 and the ${.template_name} template. |
| 37 | + */ |
| 38 | + |
| 39 | +@SuppressWarnings("unused") |
| 40 | +public class UnionFixedSizeListWriter extends AbstractFieldWriter { |
| 41 | + |
| 42 | + protected FixedSizeListVector vector; |
| 43 | + protected PromotableWriter writer; |
| 44 | + private boolean inStruct = false; |
| 45 | + private String structName; |
| 46 | + private int lastIndex = 0; |
| 47 | + private final int listSize; |
| 48 | + |
| 49 | + public UnionFixedSizeListWriter(FixedSizeListVector vector) { |
| 50 | + this(vector, NullableStructWriterFactory.getNullableStructWriterFactoryInstance()); |
| 51 | + } |
| 52 | + |
| 53 | + public UnionFixedSizeListWriter(FixedSizeListVector vector, NullableStructWriterFactory nullableStructWriterFactory) { |
| 54 | + this.vector = vector; |
| 55 | + this.writer = new PromotableWriter(vector.getDataVector(), vector, nullableStructWriterFactory); |
| 56 | + this.listSize = vector.getListSize(); |
| 57 | + } |
| 58 | + |
| 59 | + public UnionFixedSizeListWriter(FixedSizeListVector vector, AbstractFieldWriter parent) { |
| 60 | + this(vector); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public void allocate() { |
| 65 | + vector.allocateNew(); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public void clear() { |
| 70 | + vector.clear(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public Field getField() { |
| 75 | + return null; |
| 76 | + } |
| 77 | + |
| 78 | + public void setValueCount(int count) { |
| 79 | + vector.setValueCount(count); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public int getValueCapacity() { |
| 84 | + return vector.getValueCapacity(); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void close() throws Exception { |
| 89 | + |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public void setPosition(int index) { |
| 94 | + super.setPosition(index); |
| 95 | + } |
| 96 | + <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> |
| 97 | + <#assign fields = minor.fields!type.fields /> |
| 98 | + <#assign uncappedName = name?uncap_first/> |
| 99 | + <#if uncappedName == "int" ><#assign uncappedName = "integer" /></#if> |
| 100 | + <#if !minor.typeParams?? > |
| 101 | +
|
| 102 | + @Override |
| 103 | + public ${name}Writer ${uncappedName}() { |
| 104 | + return this; |
| 105 | + } |
| 106 | +
|
| 107 | + @Override |
| 108 | + public ${name}Writer ${uncappedName}(String name) { |
| 109 | + structName = name; |
| 110 | + return writer.${uncappedName}(name); |
| 111 | + } |
| 112 | + </#if> |
| 113 | + </#list></#list> |
| 114 | +
|
| 115 | + @Override |
| 116 | + public DecimalWriter decimal() { |
| 117 | + return this; |
| 118 | + } |
| 119 | +
|
| 120 | + @Override |
| 121 | + public DecimalWriter decimal(String name, int scale, int precision) { |
| 122 | + return writer.decimal(name, scale, precision); |
| 123 | + } |
| 124 | +
|
| 125 | + @Override |
| 126 | + public DecimalWriter decimal(String name) { |
| 127 | + return writer.decimal(name); |
| 128 | + } |
| 129 | +
|
| 130 | + @Override |
| 131 | + public StructWriter struct() { |
| 132 | + inStruct = true; |
| 133 | + return this; |
| 134 | + } |
| 135 | +
|
| 136 | + @Override |
| 137 | + public ListWriter list() { |
| 138 | + return writer; |
| 139 | + } |
| 140 | +
|
| 141 | + @Override |
| 142 | + public ListWriter list(String name) { |
| 143 | + ListWriter listWriter = writer.list(name); |
| 144 | + return listWriter; |
| 145 | + } |
| 146 | +
|
| 147 | + @Override |
| 148 | + public StructWriter struct(String name) { |
| 149 | + StructWriter structWriter = writer.struct(name); |
| 150 | + return structWriter; |
| 151 | + } |
| 152 | +
|
| 153 | + @Override |
| 154 | + public void startList() { |
| 155 | + int start = vector.startNewValue(idx()); |
| 156 | + writer.setPosition(start); |
| 157 | + } |
| 158 | +
|
| 159 | + @Override |
| 160 | + public void endList() { |
| 161 | + setPosition(idx() + 1); |
| 162 | + } |
| 163 | +
|
| 164 | + @Override |
| 165 | + public void start() { |
| 166 | + writer.start(); |
| 167 | + } |
| 168 | +
|
| 169 | + @Override |
| 170 | + public void end() { |
| 171 | + writer.end(); |
| 172 | + inStruct = false; |
| 173 | + } |
| 174 | +
|
| 175 | + @Override |
| 176 | + public void write(DecimalHolder holder) { |
| 177 | + writer.write(holder); |
| 178 | + writer.setPosition(writer.idx() + 1); |
| 179 | + } |
| 180 | +
|
| 181 | + public void writeDecimal(int start, ArrowBuf buffer) { |
| 182 | + writer.writeDecimal(start, buffer); |
| 183 | + writer.setPosition(writer.idx() + 1); |
| 184 | + } |
| 185 | +
|
| 186 | + public void writeDecimal(BigDecimal value) { |
| 187 | + writer.writeDecimal(value); |
| 188 | + writer.setPosition(writer.idx() + 1); |
| 189 | + } |
| 190 | +
|
| 191 | + <#list vv.types as type> |
| 192 | + <#list type.minor as minor> |
| 193 | + <#assign name = minor.class?cap_first /> |
| 194 | + <#assign fields = minor.fields!type.fields /> |
| 195 | + <#assign uncappedName = name?uncap_first/> |
| 196 | + <#if !minor.typeParams?? > |
| 197 | + @Override |
| 198 | + public void write${name}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) { |
| 199 | + if (writer.idx() >= (idx() + 1) * listSize) { |
| 200 | + throw new IllegalStateException(String.format("values at index %s is greater than listSize %s", idx(), listSize)); |
| 201 | + } |
| 202 | + writer.write${name}(<#list fields as field>${field.name}<#if field_has_next>, </#if></#list>); |
| 203 | + writer.setPosition(writer.idx() + 1); |
| 204 | + } |
| 205 | +
|
| 206 | + public void write(${name}Holder holder) { |
| 207 | + if (writer.idx() >= (idx() + 1) * listSize) { |
| 208 | + throw new IllegalStateException(String.format("values at index %s is greater than listSize %s", idx(), listSize)); |
| 209 | + } |
| 210 | + writer.write${name}(<#list fields as field>holder.${field.name}<#if field_has_next>, </#if></#list>); |
| 211 | + writer.setPosition(writer.idx() + 1); |
| 212 | + } |
| 213 | + |
| 214 | + </#if> |
| 215 | + </#list> |
| 216 | + </#list> |
| 217 | +} |
0 commit comments