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

io.substrait.relation.files.FileOrFiles Maven / Gradle / Ivy

Go to download

Create a well-defined, cross-language specification for data compute operations

There is a newer version: 0.46.1
Show newest version
package io.substrait.relation.files;

import io.substrait.proto.ReadRel;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
public interface FileOrFiles {

  Optional pathType();

  enum PathType {
    URI_PATH,
    URI_PATH_GLOB,
    URI_FILE,
    URI_FOLDER
  }

  Optional getPath();

  long getPartitionIndex();

  long getStart();

  long getLength();

  Optional getFileFormat();

  default ReadRel.LocalFiles.FileOrFiles toProto() {
    ReadRel.LocalFiles.FileOrFiles.Builder builder = ReadRel.LocalFiles.FileOrFiles.newBuilder();

    getFileFormat()
        .ifPresent(
            fileFormat -> {
              if (fileFormat instanceof FileFormat.ParquetReadOptions options) {
                builder.setParquet(
                    ReadRel.LocalFiles.FileOrFiles.ParquetReadOptions.newBuilder().build());
              } else if (fileFormat instanceof FileFormat.ArrowReadOptions options) {
                builder.setArrow(
                    ReadRel.LocalFiles.FileOrFiles.ArrowReadOptions.newBuilder().build());
              } else if (fileFormat instanceof FileFormat.OrcReadOptions options) {
                builder.setOrc(ReadRel.LocalFiles.FileOrFiles.OrcReadOptions.newBuilder().build());
              } else if (fileFormat instanceof FileFormat.DwrfReadOptions options) {
                builder.setDwrf(
                    ReadRel.LocalFiles.FileOrFiles.DwrfReadOptions.newBuilder().build());
              } else if (fileFormat instanceof FileFormat.Extension options) {
                builder.setExtension(options.getExtension());
              } else {
                throw new UnsupportedOperationException(
                    "Unable to convert file format of " + fileFormat.getClass());
              }
            });

    pathType()
        .ifPresent(
            pathType ->
                getPath()
                    .ifPresent(
                        path -> {
                          switch (pathType) {
                            case URI_PATH -> builder.setUriPath(path);
                            case URI_PATH_GLOB -> builder.setUriPathGlob(path);
                            case URI_FILE -> builder.setUriFile(path);
                            case URI_FOLDER -> builder.setUriFolder(path);
                          }
                        }));

    return builder
        .setPartitionIndex(getPartitionIndex())
        .setStart(getStart())
        .setLength(getLength())
        .build();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy