Class AbstractColumnMetadata

java.lang.Object
org.apache.drill.exec.record.metadata.AbstractPropertied
org.apache.drill.exec.record.metadata.AbstractColumnMetadata
All Implemented Interfaces:
ColumnMetadata, Propertied
Direct Known Subclasses:
AbstractMapColumnMetadata, DynamicColumn, PrimitiveColumnMetadata, RepeatedListColumnMetadata, VariantColumnMetadata

public abstract class AbstractColumnMetadata extends AbstractPropertied implements ColumnMetadata
Abstract definition of column metadata. Allows applications to create specialized forms of a column metadata object by extending from this abstract class.

Note that, by design, primitive columns do not have a link to their tuple parent, or their index within that parent. This allows the same metadata to be shared between two views of a tuple, perhaps physical and projected views. This restriction does not apply to map columns, since maps (and the row itself) will, by definition, differ between the two views.

  • Field Details

  • Constructor Details

  • Method Details

    • createColumnMetadata

      public static AbstractColumnMetadata createColumnMetadata(String name, String type, TypeProtos.DataMode mode, Map<String,String> properties) throws IOException
      Throws:
      IOException
    • bind

      public void bind(TupleMetadata parentTuple)
      Specified by:
      bind in interface ColumnMetadata
    • name

      public String name()
      Specified by:
      name in interface ColumnMetadata
    • type

      public TypeProtos.MinorType type()
      Specified by:
      type in interface ColumnMetadata
    • majorType

      public TypeProtos.MajorType majorType()
      Specified by:
      majorType in interface ColumnMetadata
    • mode

      public TypeProtos.DataMode mode()
      Specified by:
      mode in interface ColumnMetadata
    • isNullable

      public boolean isNullable()
      Specified by:
      isNullable in interface ColumnMetadata
    • isArray

      public boolean isArray()
      Specified by:
      isArray in interface ColumnMetadata
    • dimensions

      public int dimensions()
      Specified by:
      dimensions in interface ColumnMetadata
    • isMap

      public boolean isMap()
      Specified by:
      isMap in interface ColumnMetadata
    • isVariant

      public boolean isVariant()
      Specified by:
      isVariant in interface ColumnMetadata
    • isMultiList

      public boolean isMultiList()
      Description copied from interface: ColumnMetadata
      Determine if the schema represents a column with a LIST type with UNION elements. (Lists can be of a single type (with nullable elements) or can be of unions.)
      Specified by:
      isMultiList in interface ColumnMetadata
      Returns:
      true if the column is of type LIST of UNIONs
    • isDict

      public boolean isDict()
      Specified by:
      isDict in interface ColumnMetadata
    • isScalar

      public boolean isScalar()
      Specified by:
      isScalar in interface ColumnMetadata
    • isDynamic

      public boolean isDynamic()
      Description copied from interface: ColumnMetadata
      Reports if the column is dynamic. A dynamic column is one with a "type to be named later." It is valid for describing a dynamic schema, but not for creating vectors; to create a vector the column must be resolved to a concrete type. The context should make it clear if any columns can be dynamic.
      Specified by:
      isDynamic in interface ColumnMetadata
      Returns:
      true if the column does not yet have a concrete type, false if the column type is concrete
    • tupleSchema

      public TupleMetadata tupleSchema()
      Description copied from interface: ColumnMetadata
      Schema for TUPLE columns.
      Specified by:
      tupleSchema in interface ColumnMetadata
      Returns:
      the tuple schema
    • variantSchema

      public VariantMetadata variantSchema()
      Description copied from interface: ColumnMetadata
      Schema for VARIANT columns.
      Specified by:
      variantSchema in interface ColumnMetadata
      Returns:
      the variant schema
    • childSchema

      public ColumnMetadata childSchema()
      Description copied from interface: ColumnMetadata
      Schema of inner dimension for MULTI_ARRAY columns. If an array is 3D, the outer column represents all 3 dimensions. outer.childSchema() gives another MULTI_ARRAY for the inner 2D array. outer.childSchema().childSchema() gives a column of some other type (but repeated) for the 1D array.

      Sorry for the mess, but it is how the code works and we are not in a position to revisit data type fundamentals.

      Specified by:
      childSchema in interface ColumnMetadata
      Returns:
      the description of the (n-1) st dimension.
    • isVariableWidth

      public boolean isVariableWidth()
      Specified by:
      isVariableWidth in interface ColumnMetadata
    • isEquivalent

      public boolean isEquivalent(ColumnMetadata o)
      Description copied from interface: ColumnMetadata
      Report whether one column is equivalent to another. Columns are equivalent if they have the same name, type and structure (ignoring internal structure such as properties.)
      Specified by:
      isEquivalent in interface ColumnMetadata
    • equalsWithProperties

      public boolean equalsWithProperties(AbstractColumnMetadata other)
    • expectedWidth

      public int expectedWidth()
      Description copied from interface: ColumnMetadata
      Get the expected width for a column. This is the actual width for fixed- width columns, the specified width (defaulting to 50) for variable-width columns.
      Specified by:
      expectedWidth in interface ColumnMetadata
      Returns:
      the expected column width of the each data value. Does not include "overhead" space such as for the null-value vector or offset vector
    • setExpectedWidth

      public void setExpectedWidth(int width)
      Description copied from interface: ColumnMetadata
      For variable-width columns, specify the expected column width to be used when allocating a new vector. Does nothing for fixed-width columns.
      Specified by:
      setExpectedWidth in interface ColumnMetadata
      Parameters:
      width - the expected column width
    • precision

      public int precision()
      Returns precision for current column. For the case when precision is not set or column type does not support precision, negative value will be returned.
      Specified by:
      precision in interface ColumnMetadata
      Returns:
      precision for current column
    • scale

      public int scale()
      Returns scale for current column. For the case when scale is not set or column type does not support scale, negative value will be returned.
      Specified by:
      scale in interface ColumnMetadata
      Returns:
      scale for current column
    • setExpectedElementCount

      public void setExpectedElementCount(int childCount)
      Description copied from interface: ColumnMetadata
      For an array column, specify the expected average array cardinality. Ignored for non-array columns. Used when allocating new vectors.
      Specified by:
      setExpectedElementCount in interface ColumnMetadata
      Parameters:
      childCount - the expected average array cardinality. Defaults to 1 for non-array columns, 10 for array columns
    • expectedElementCount

      public int expectedElementCount()
      Description copied from interface: ColumnMetadata
      Returns the expected array cardinality for array columns, or 1 for non-array columns.
      Specified by:
      expectedElementCount in interface ColumnMetadata
      Returns:
      the expected value cardinality per value (per-row for top-level columns, per array element for arrays within lists)
    • setFormat

      public void setFormat(String value)
      Specified by:
      setFormat in interface ColumnMetadata
    • format

      public String format()
      Specified by:
      format in interface ColumnMetadata
    • dateTimeFormatter

      public DateTimeFormatter dateTimeFormatter()
      Description copied from interface: ColumnMetadata
      Returns the formatter to use for date/time values. Only valid for date/time columns.
      Specified by:
      dateTimeFormatter in interface ColumnMetadata
      Returns:
    • setDefaultValue

      public void setDefaultValue(String value)
      Description copied from interface: ColumnMetadata
      Sets the default value property using the string-encoded form of the value. The default value is used for filling a vector when no real data is available.
      Specified by:
      setDefaultValue in interface ColumnMetadata
      Parameters:
      value - the default value in String representation
    • defaultValue

      public String defaultValue()
      Description copied from interface: ColumnMetadata
      Returns the default value for this column in String literal representation.
      Specified by:
      defaultValue in interface ColumnMetadata
      Returns:
      the default value in String literal representation, or null if no default value has been set
    • decodeDefaultValue

      public Object decodeDefaultValue()
      Description copied from interface: ColumnMetadata
      Returns the default value decoded into object form. This is the same as:
      decodeValue(defaultValue());
       
      Specified by:
      decodeDefaultValue in interface ColumnMetadata
      Returns:
      the default value decode as an object that can be passed to the ColumnWriter#setObject() method.
    • valueFromString

      public Object valueFromString(String value)
      Specified by:
      valueFromString in interface ColumnMetadata
    • valueToString

      public String valueToString(Object value)
      Specified by:
      valueToString in interface ColumnMetadata
    • properties

      public Map<String,String> properties()
      Specified by:
      properties in interface Propertied
      Overrides:
      properties in class AbstractPropertied
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • appendContents

      protected void appendContents(StringBuilder buf)
    • typeString

      public abstract String typeString()
      Description copied from interface: ColumnMetadata
      Converts type metadata into string representation accepted by the table schema parser.
      Specified by:
      typeString in interface ColumnMetadata
      Returns:
      type metadata string representation
    • columnString

      public String columnString()
      Description copied from interface: ColumnMetadata
      Converts column metadata into string representation accepted by the table schema parser.
      Specified by:
      columnString in interface ColumnMetadata
      Returns:
      column metadata string representation
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class AbstractPropertied
    • equalsWithProperties

      public boolean equalsWithProperties(Object o)
    • escapeSpecialSymbols

      protected String escapeSpecialSymbols(String value)
      If given value contains backticks (`) or backslashes (\), escapes them.
      Parameters:
      value - string value
      Returns:
      updated value