Interface Schema

  • All Known Implementing Classes:
    ConnectSchema, SchemaBuilder

    public interface Schema

    Definition of an abstract data type. Data types can be primitive types (integer types, floating point types, boolean, strings, and bytes) or complex types (typed arrays, maps with one key schema and value schema, and structs that have a fixed set of field names each with an associated value schema). Any type can be specified as optional, allowing it to be omitted (resulting in null values when it is missing) and can specify a default value.

    All schemas may have some associated metadata: a name, version, and documentation. These are all considered part of the schema itself and included when comparing schemas. Besides adding important metadata, these fields enable the specification of logical types that specify additional constraints and semantics (e.g. UNIX timestamps are just an int64, but the user needs the know about the additional semantics to interpret it properly).

    Schemas can be created directly, but in most cases using SchemaBuilder will be simpler.

    • Field Detail

      • INT8_SCHEMA

        static final Schema INT8_SCHEMA
      • INT16_SCHEMA

        static final Schema INT16_SCHEMA
      • INT32_SCHEMA

        static final Schema INT32_SCHEMA
      • INT64_SCHEMA

        static final Schema INT64_SCHEMA
      • FLOAT32_SCHEMA

        static final Schema FLOAT32_SCHEMA
      • FLOAT64_SCHEMA

        static final Schema FLOAT64_SCHEMA
      • BOOLEAN_SCHEMA

        static final Schema BOOLEAN_SCHEMA
      • STRING_SCHEMA

        static final Schema STRING_SCHEMA
      • BYTES_SCHEMA

        static final Schema BYTES_SCHEMA
      • OPTIONAL_INT8_SCHEMA

        static final Schema OPTIONAL_INT8_SCHEMA
      • OPTIONAL_INT16_SCHEMA

        static final Schema OPTIONAL_INT16_SCHEMA
      • OPTIONAL_INT32_SCHEMA

        static final Schema OPTIONAL_INT32_SCHEMA
      • OPTIONAL_INT64_SCHEMA

        static final Schema OPTIONAL_INT64_SCHEMA
      • OPTIONAL_FLOAT32_SCHEMA

        static final Schema OPTIONAL_FLOAT32_SCHEMA
      • OPTIONAL_FLOAT64_SCHEMA

        static final Schema OPTIONAL_FLOAT64_SCHEMA
      • OPTIONAL_BOOLEAN_SCHEMA

        static final Schema OPTIONAL_BOOLEAN_SCHEMA
      • OPTIONAL_STRING_SCHEMA

        static final Schema OPTIONAL_STRING_SCHEMA
      • OPTIONAL_BYTES_SCHEMA

        static final Schema OPTIONAL_BYTES_SCHEMA
    • Method Detail

      • type

        Schema.Type type()
        Returns:
        the type of this schema
      • isOptional

        boolean isOptional()
        Returns:
        true if this field is optional, false otherwise
      • defaultValue

        Object defaultValue()
        Returns:
        the default value for this schema
      • name

        String name()
        Returns:
        the name of this schema
      • version

        Integer version()
        Get the optional version of the schema. If a version is included, newer versions *must* be larger than older ones.
        Returns:
        the version of this schema
      • doc

        String doc()
        Returns:
        the documentation for this schema
      • parameters

        Map<String,​String> parameters()
        Get a map of schema parameters.
        Returns:
        Map containing parameters for this schema, or null if there are no parameters
      • keySchema

        Schema keySchema()
        Get the key schema for this map schema. Throws a DataException if this schema is not a map.
        Returns:
        the key schema
      • valueSchema

        Schema valueSchema()
        Get the value schema for this map or array schema. Throws a DataException if this schema is not a map or array.
        Returns:
        the value schema
      • fields

        List<Field> fields()
        Get the list of fields for this Schema. Throws a DataException if this schema is not a struct.
        Returns:
        the list of fields for this Schema
      • field

        Field field​(String fieldName)
        Get a field for this Schema by name. Throws a DataException if this schema is not a struct.
        Parameters:
        fieldName - the name of the field to look up
        Returns:
        the Field object for the specified field, or null if there is no field with the given name