org.apache.iceberg.orc.OrcValueReaders Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iceberg-orc Show documentation
Show all versions of iceberg-orc Show documentation
A table format for huge analytic datasets
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.iceberg.orc;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Types;
import org.apache.orc.storage.ql.exec.vector.BytesColumnVector;
import org.apache.orc.storage.ql.exec.vector.ColumnVector;
import org.apache.orc.storage.ql.exec.vector.DoubleColumnVector;
import org.apache.orc.storage.ql.exec.vector.LongColumnVector;
import org.apache.orc.storage.ql.exec.vector.StructColumnVector;
public class OrcValueReaders {
private OrcValueReaders() {
}
public static OrcValueReader booleans() {
return BooleanReader.INSTANCE;
}
public static OrcValueReader ints() {
return IntegerReader.INSTANCE;
}
public static OrcValueReader longs() {
return LongReader.INSTANCE;
}
public static OrcValueReader floats() {
return FloatReader.INSTANCE;
}
public static OrcValueReader doubles() {
return DoubleReader.INSTANCE;
}
public static OrcValueReader bytes() {
return BytesReader.INSTANCE;
}
private static class BooleanReader implements OrcValueReader {
static final BooleanReader INSTANCE = new BooleanReader();
private BooleanReader() {
}
@Override
public Boolean nonNullRead(ColumnVector vector, int row) {
return ((LongColumnVector) vector).vector[row] != 0;
}
}
private static class IntegerReader implements OrcValueReader {
static final IntegerReader INSTANCE = new IntegerReader();
private IntegerReader() {
}
@Override
public Integer nonNullRead(ColumnVector vector, int row) {
return (int) ((LongColumnVector) vector).vector[row];
}
}
private static class LongReader implements OrcValueReader {
static final LongReader INSTANCE = new LongReader();
private LongReader() {
}
@Override
public Long nonNullRead(ColumnVector vector, int row) {
return ((LongColumnVector) vector).vector[row];
}
}
private static class FloatReader implements OrcValueReader {
private static final FloatReader INSTANCE = new FloatReader();
private FloatReader() {
}
@Override
public Float nonNullRead(ColumnVector vector, int row) {
return (float) ((DoubleColumnVector) vector).vector[row];
}
}
private static class DoubleReader implements OrcValueReader {
private static final DoubleReader INSTANCE = new DoubleReader();
private DoubleReader() {
}
@Override
public Double nonNullRead(ColumnVector vector, int row) {
return ((DoubleColumnVector) vector).vector[row];
}
}
private static class BytesReader implements OrcValueReader {
private static final BytesReader INSTANCE = new BytesReader();
private BytesReader() {
}
@Override
public byte[] nonNullRead(ColumnVector vector, int row) {
BytesColumnVector bytesVector = (BytesColumnVector) vector;
return Arrays.copyOfRange(
bytesVector.vector[row], bytesVector.start[row], bytesVector.start[row] + bytesVector.length[row]);
}
}
public abstract static class StructReader implements OrcValueReader {
private final OrcValueReader>[] readers;
private final int[] positions;
private final Object[] constants;
protected StructReader(List> readers) {
this.readers = readers.toArray(new OrcValueReader[0]);
this.positions = new int[0];
this.constants = new Object[0];
}
protected StructReader(List> readers, Types.StructType struct, Map idToConstant) {
this.readers = readers.toArray(new OrcValueReader[0]);
List fields = struct.fields();
List positionList = Lists.newArrayListWithCapacity(fields.size());
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy