All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.parquet.proto.ProtoParquetReader Maven / Gradle / Ivy

There is a newer version: 1.15.0
Show newest version
/*
 * 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.parquet.proto;

import static org.apache.parquet.proto.ProtoConstants.CONFIG_IGNORE_UNKNOWN_FIELDS;

import com.google.protobuf.MessageOrBuilder;
import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.parquet.filter.UnboundRecordFilter;
import org.apache.parquet.hadoop.ParquetReader;
import org.apache.parquet.hadoop.api.ReadSupport;
import org.apache.parquet.io.InputFile;

/**
 * Read Protobuf records from a Parquet file.
 */
public class ProtoParquetReader extends ParquetReader {

  public static  ParquetReader.Builder builder(Path file) {
    return new ProtoParquetReader.Builder(file);
  }

  public static  ParquetReader.Builder builder(Path file, boolean ignoreUnknownFields) {
    return new ProtoParquetReader.Builder(file).setIgnoreUnknownFields(ignoreUnknownFields);
  }

  public static  ParquetReader.Builder builder(InputFile file) {
    return new ProtoParquetReader.Builder(file);
  }

  public static  ParquetReader.Builder builder(InputFile file, boolean ignoreUnknownFields) {
    return new ProtoParquetReader.Builder(file).setIgnoreUnknownFields(ignoreUnknownFields);
  }

  /**
   * @param file a file path
   * @throws IOException if there is an error while reading
   * @deprecated use {@link #builder(Path)}
   */
  @Deprecated
  @SuppressWarnings("unchecked")
  public ProtoParquetReader(Path file) throws IOException {
    super(file, new ProtoReadSupport());
  }

  /**
   * @param file         a file path
   * @param recordFilter an unbound record filter
   * @throws IOException if there is an error while reading
   * @deprecated use {@link #builder(Path)}
   */
  @Deprecated
  @SuppressWarnings("unchecked")
  public ProtoParquetReader(Path file, UnboundRecordFilter recordFilter) throws IOException {
    super(file, new ProtoReadSupport(), recordFilter);
  }

  private static class Builder extends ParquetReader.Builder {

    protected Builder(InputFile file) {
      super(file);
    }

    protected Builder setIgnoreUnknownFields(boolean ignoreUnknownFields) {
      if (ignoreUnknownFields) {
        this.set(CONFIG_IGNORE_UNKNOWN_FIELDS, "TRUE");
      }
      return this;
    }

    protected Builder(Path path) {
      super(path);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    protected ReadSupport getReadSupport() {
      return new ProtoReadSupport();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy