org.apache.iceberg.flink.data.FlinkAvroReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iceberg-flink Show documentation
Show all versions of iceberg-flink 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.flink.data;
import java.util.List;
import java.util.Map;
import org.apache.avro.Schema;
import org.apache.flink.types.Row;
import org.apache.iceberg.avro.ValueReader;
import org.apache.iceberg.avro.ValueReaders;
import org.apache.iceberg.data.avro.DataReader;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.types.Types;
public class FlinkAvroReader extends DataReader {
public FlinkAvroReader(org.apache.iceberg.Schema expectedSchema, Schema readSchema) {
super(expectedSchema, readSchema, ImmutableMap.of());
}
@Override
protected ValueReader> createStructReader(Types.StructType struct,
List> fields,
Map idToConstant) {
return new RowReader(fields, struct, idToConstant);
}
private static class RowReader extends ValueReaders.StructReader {
private final Types.StructType structType;
private RowReader(List> readers, Types.StructType struct, Map idToConstant) {
super(readers, struct, idToConstant);
this.structType = struct;
}
@Override
protected Row reuseOrCreate(Object reuse) {
if (reuse instanceof Row) {
return (Row) reuse;
} else {
return new Row(structType.fields().size());
}
}
@Override
protected Object get(Row row, int pos) {
return row.getField(pos);
}
@Override
protected void set(Row row, int pos, Object value) {
row.setField(pos, value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy