Interface PqFile


public interface PqFile

Value of a Parquet column annotated with the FILE logical type: a reference to a range of bytes, stored inline in the value or in an external object named by a URI.

The factories build only references the format defines:

Factory Refers to
inline(byte[]) the given bytes
external(String) the whole object at uri
external(String, long) bytes [0, size) of the object at uri
external(String, long, long) bytes [offset, offset + size) of the object at uri

withInline(byte[]), withContentType(String) and withChecksum(String) return a copy with one more field set.

PqFile photo = PqFile.external("s3://bucket/bundle.tar", 4096, 51200)
        .withContentType("image/png");

A FILE value is not resolved: fetching the object at uri() and verifying checksum() are left to the caller.

The values the factories and the reader return are immutable: the factories copy the arrays they are given, and inline() returns a copy on each call. Two such values are equal when their accessors return equal values, the inline bytes compared by content; neither is equal to an instance of another implementation. A value the reader returns can be held after the reader moves on; while it is reachable, the inline bytes of every value in the batch it was read from stay in memory. A writer checks every value it is given against the format's rules, whatever implements it.

  • Method Summary

    Modifier and Type
    Method
    Description
    The integrity token for the referenced bytes, as stored, or null if the reference has none.
    The media type of the referenced bytes, or null if the reference has none.
    static PqFile
    A reference to the whole object at uri.
    static PqFile
    external(String uri, long size)
    A reference to the first size bytes of the object at uri.
    static PqFile
    external(String uri, long offset, long size)
    A reference to size bytes of the object at uri, starting at offset.
    boolean
    Whether the reference stores an offset into the object at uri().
    boolean
    Whether the reference stores the number of bytes referenced.
    byte[]
    A copy of the bytes stored inline, or null if the reference stores none.
    static PqFile
    inline(byte[] bytes)
    A reference to bytes stored in the value itself.
    long
    The position of the first referenced byte in the object at uri(); 0 when the reference stores no offset.
    long
    The number of bytes referenced in the object at uri().
    uri()
    The URI of the referenced object, or null if the reference has none.
    default PqFile
    Returns a copy of this reference with an integrity token for the referenced bytes, of the form <algorithm>:<digest>, such as SHA-256:… or an object store's ETAG:….
    default PqFile
    Returns a copy of this reference with the media type of the referenced bytes.
    default PqFile
    withInline(byte[] bytes)
    Returns a copy of this reference that also stores bytes inline.
  • Method Details

    • inline

      static PqFile inline(byte[] bytes)
      A reference to bytes stored in the value itself.
      Parameters:
      bytes - the referenced bytes, possibly empty
      Throws:
      NullPointerException - if bytes is null
    • external

      static PqFile external(String uri)
      A reference to the whole object at uri.
      Parameters:
      uri - an RFC 3986 URI-reference, absolute or relative, stored as given
      Throws:
      NullPointerException - if uri is null
      IllegalArgumentException - if uri is empty
    • external

      static PqFile external(String uri, long size)
      A reference to the first size bytes of the object at uri.
      Parameters:
      uri - an RFC 3986 URI-reference, absolute or relative, stored as given
      size - the number of bytes referenced, 0 for none
      Throws:
      NullPointerException - if uri is null
      IllegalArgumentException - if uri is empty or size is negative
    • external

      static PqFile external(String uri, long offset, long size)
      A reference to size bytes of the object at uri, starting at offset.
      Parameters:
      uri - an RFC 3986 URI-reference, absolute or relative, stored as given
      offset - the position of the first byte referenced
      size - the number of bytes referenced, 0 for none
      Throws:
      NullPointerException - if uri is null
      IllegalArgumentException - if uri is empty, or offset or size is negative
    • withInline

      default PqFile withInline(byte[] bytes)
      Returns a copy of this reference that also stores bytes inline. Combined with external(String) it records where inline bytes came from; the two are expected to denote the same bytes, which is not checked.
      Throws:
      NullPointerException - if bytes is null
      IllegalStateException - if this reference already stores bytes inline
    • withContentType

      default PqFile withContentType(String mediaType)
      Returns a copy of this reference with the media type of the referenced bytes.
      Parameters:
      mediaType - an RFC 2046 media type, such as image/png
      Throws:
      NullPointerException - if mediaType is null
      IllegalArgumentException - if mediaType is empty
      IllegalStateException - if this reference already has a content type
    • withChecksum

      default PqFile withChecksum(String token)
      Returns a copy of this reference with an integrity token for the referenced bytes, of the form <algorithm>:<digest>, such as SHA-256:… or an object store's ETAG:…. The token is stored as given and not verified against any bytes. The writer refuses a token not of that form, and one whose digest for MD5, CRC32, CRC32C or SHA-256 is not lowercase hex of that algorithm's length.
      Throws:
      NullPointerException - if token is null
      IllegalArgumentException - if token is empty
      IllegalStateException - if this reference already has a checksum
    • uri

      String uri()
      The URI of the referenced object, or null if the reference has none.
    • hasOffset

      boolean hasOffset()
      Whether the reference stores an offset into the object at uri().
    • offset

      long offset()
      The position of the first referenced byte in the object at uri(); 0 when the reference stores no offset.
    • hasSize

      boolean hasSize()
      Whether the reference stores the number of bytes referenced. A reference to a whole object stores none.
    • size

      long size()
      The number of bytes referenced in the object at uri().
      Throws:
      IllegalStateException - if the reference stores no size, which hasSize() answers
    • contentType

      String contentType()
      The media type of the referenced bytes, or null if the reference has none. The format states that a reference without one can be assumed to be application/octet-stream.
    • checksum

      String checksum()
      The integrity token for the referenced bytes, as stored, or null if the reference has none.
    • inline

      byte[] inline()
      A copy of the bytes stored inline, or null if the reference stores none.