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 org.apache.arrow.vector.types.pojo.ArrowType.Null; 19 import org.apache.arrow.vector.types.pojo.Field; 20 21 <@pp.dropOutputFile /> 22 <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/NullReader.java" /> 23 24 25 <#include "/@includes/license.ftl" /> 26 27 package org.apache.arrow.vector.complex.impl; 28 29 <#include "/@includes/vv_imports.ftl" /> 30 31 /** 32 * Source code generated using FreeMarker template ${.template_name} 33 */ 34 @SuppressWarnings("unused") 35 public class NullReader extends AbstractBaseReader implements FieldReader{ 36 37 public static final NullReader INSTANCE = new NullReader(); 38 public static final NullReader EMPTY_LIST_INSTANCE = new NullReader(MinorType.NULL); 39 public static final NullReader EMPTY_STRUCT_INSTANCE = new NullReader(MinorType.STRUCT); 40 private MinorType type; 41 NullReader()42 private NullReader(){ 43 super(); 44 type = MinorType.NULL; 45 } 46 NullReader(MinorType type)47 private NullReader(MinorType type){ 48 super(); 49 this.type = type; 50 } 51 52 @Override getMinorType()53 public MinorType getMinorType() { 54 return type; 55 } 56 57 @Override getField()58 public Field getField() { 59 return new Field("", FieldType.nullable(new Null()), null); 60 } 61 copyAsValue(StructWriter writer)62 public void copyAsValue(StructWriter writer) {} 63 copyAsValue(ListWriter writer)64 public void copyAsValue(ListWriter writer) {} 65 copyAsValue(UnionWriter writer)66 public void copyAsValue(UnionWriter writer) {} 67 68 <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> 69 public void read(${name}Holder holder){ 70 throw new UnsupportedOperationException("NullReader cannot write into non-nullable holder"); 71 } 72 73 public void read(Nullable${name}Holder holder){ 74 holder.isSet = 0; 75 } 76 read(int arrayIndex, ${name}Holder holder)77 public void read(int arrayIndex, ${name}Holder holder){ 78 throw new ArrayIndexOutOfBoundsException(); 79 } 80 81 public void copyAsValue(${minor.class}Writer writer){} copyAsField(String name, ${minor.class}Writer writer)82 public void copyAsField(String name, ${minor.class}Writer writer){} 83 read(int arrayIndex, Nullable${name}Holder holder)84 public void read(int arrayIndex, Nullable${name}Holder holder){ 85 throw new ArrayIndexOutOfBoundsException(); 86 } 87 </#list></#list> 88 size()89 public int size(){ 90 return 0; 91 } 92 isSet()93 public boolean isSet(){ 94 return false; 95 } 96 next()97 public boolean next(){ 98 return false; 99 } 100 struct()101 public RepeatedStructReader struct(){ 102 return this; 103 } 104 list()105 public RepeatedListReader list(){ 106 return this; 107 } 108 struct(String name)109 public StructReader struct(String name){ 110 return this; 111 } 112 list(String name)113 public ListReader list(String name){ 114 return this; 115 } 116 reader(String name)117 public FieldReader reader(String name){ 118 return this; 119 } 120 reader()121 public FieldReader reader(){ 122 return this; 123 } 124 fail(String name)125 private void fail(String name){ 126 throw new IllegalArgumentException(String.format("You tried to read a %s type when you are using a ValueReader of type %s.", name, this.getClass().getSimpleName())); 127 } 128 129 <#list ["Object", "BigDecimal", "Short", "Integer", "Long", "Boolean", 130 "LocalDateTime", "Duration", "Period", "Double", "Float", 131 "Character", "Text", "String", "Byte", "byte[]", "PeriodDuration"] as friendlyType> 132 <#assign safeType=friendlyType /> 133 <#if safeType=="byte[]"><#assign safeType="ByteArray" /></#if> 134 135 public ${friendlyType} read${safeType}(int arrayIndex){ 136 return null; 137 } 138 139 public ${friendlyType} read${safeType}(){ 140 return null; 141 } 142 </#list> 143 144 } 145 146 147 148