Class CompleteDataType

java.lang.Object
com.streambase.sb.CompleteDataType
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CompleteDataType.CaptureType, CompleteDataType.FunctionType, CompleteDataType.ListType, CompleteDataType.TupleType

public abstract class CompleteDataType extends Object implements Serializable
Wraps DataType with ancillary information about the type (where appropriate) that's needed to actually use the DataType. E.g., to be "complete",
  • DataType.TUPLE needs a description of the tuple's schema (expressed as a Schema),and
  • DataType.LIST needs a description of the type of list's elements (itself expressed as a CompleteDataType).
  • DataType.FUNCTION needs a description of the function's arguments (as a Schema) and its return type (as a CompleteDataType)

Note: Serializations of instances of this class that are created (e.g., by using ObjectOutputStream) in one version of StreamBase in general will not be deserializable in any other version of StreamBase.

Since:
6.3
See Also:
  • Field Details

    • type

      protected final DataType type
      Wrapped data type
    • SCORE_FAIL

      public static final long SCORE_FAIL
      Coercion score fail
      See Also:
    • SCORE_PASS

      public static final long SCORE_PASS
      Coercion score pass
      See Also:
    • TYPE_TO_TYPE_SCORE

      public static final long TYPE_TO_TYPE_SCORE
      Type to type coercion value
      See Also:
    • NULL_TO_TYPE_SCORE

      public static final long NULL_TO_TYPE_SCORE
      Null to type coercion value
      See Also:
    • WILDCARD_SCORE

      public static final long WILDCARD_SCORE
      Wild card coercion value
      See Also:
  • Constructor Details

    • CompleteDataType

      protected CompleteDataType(DataType type)
      Constructor
      Parameters:
      type - Data type
  • Method Details

    • getDataType

      public DataType getDataType()
      Return the data type of the complete type
      Returns:
      the DataType
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • toHumanString

      public String toHumanString()
      Return a String describing the type suitable for error messages.

      Assumes no schemas are named.

      Returns:
      a suitable string
      Since:
      6.3
    • canAssignFrom

      public final boolean canAssignFrom(CompleteDataType other)
      Check if a value of this type can be assigned a value of the other type. That is, is this type a supertype of that type.
      Parameters:
      other - the other type
      Returns:
      type assignment compatibility
    • canAssignFromImpl

      protected boolean canAssignFromImpl(CompleteDataType other)
      Method for subclasses to override if they have a broader concept of type.
      Parameters:
      other - the other type
      Returns:
      type assignment compatibility
    • rateCoercion

      public long rateCoercion(CompleteDataType type)
      calculate the coercion score to get coerce this → type - by default returns SCORE_PASS or SCORE_FAIL based on equals
      Parameters:
      type - the CType to converse to
      Returns:
      the score, use COp.java as a reference for score constants
    • toHumanString

      public abstract String toHumanString(SchemaUtil.SchemaProvider schemaProvider)
      Return a String describing the type suitable for error messages.
      Parameters:
      schemaProvider - A schema provider to identify named schemas
      Returns:
      param a suitable string
      Since:
      6.3
    • equalBaseTypes

      protected boolean equalBaseTypes(CompleteDataType other)
      Compare wrapped types
      Parameters:
      other - Compare with this type
      Returns:
      true if equal
    • getName

      public String getName()
      Get the name of this complete type
      Returns:
      the name of this CompleteDataType
    • getSchema

      public Schema getSchema()
      For tuple types, return the tuple's schema. For other types null is returned.
      Returns:
      the tuple types's schema
    • getArgumentSchema

      public Schema getArgumentSchema()
      For function types, return the argument schema. For other types null is returned.
      Returns:
      the function type's argument schema
    • getElementType

      public CompleteDataType getElementType()
      For list collection types, return the complete type of the list's elements. For other types null is returned.
      Returns:
      the list type's element type
    • getCaptureName

      public String getCaptureName()
      For capture types, return the capture type name. For other types, null is returned
      Returns:
      the capture name
    • getReturnType

      public CompleteDataType getReturnType()
      For function types, return the return type of the function. For other types, return null.
      Returns:
      the function type's return type
    • rateCoercion

      public static long rateCoercion(CompleteDataType from, CompleteDataType to)
      Rate coercion
      Parameters:
      from - From type
      to - To type
      Returns:
      Coercion value
    • forBool

      @Deprecated public static CompleteDataType forBool()
      Deprecated.
      Return the complete type for a bool.
      Returns:
      a boolean complete data type
      Since:
      6.3
    • forBoolean

      public static CompleteDataType forBoolean()
      Return the complete type for a bool.
      Returns:
      a boolean complete data type
      Since:
      6.3
    • forBlob

      public static CompleteDataType forBlob()
      Return the complete type for a blob.
      Returns:
      a blob complete data type.
      Since:
      6.3
    • forDouble

      public static CompleteDataType forDouble()
      Return the complete type for a double.
      Returns:
      a double complete data type
      Since:
      6.3
    • forInt

      public static CompleteDataType forInt()
      Return the complete type for an int.
      Returns:
      a int complete data type
      Since:
      6.3
    • forLong

      public static CompleteDataType forLong()
      Return the complete type for a long.
      Returns:
      a long complete data type
      Since:
      6.3
    • forString

      public static CompleteDataType forString()
      Return the complete type for a string.
      Returns:
      a string complete data type
      Since:
      6.3
    • forTimestamp

      public static CompleteDataType forTimestamp()
      Return the complete type for a timestamp.
      Returns:
      a timestamp complete data type
      Since:
      6.3
    • forTuple

      public static CompleteDataType forTuple(Schema schema)
      Return a tuple complete data type with the specified schema.
      Parameters:
      schema - the tuple's schema. This parameter may not be null.
      Returns:
      a tuple complete data type
      Since:
      6.3
    • forList

      public static CompleteDataType forList(CompleteDataType elementType)
      Return a list complete data type with the specified element type
      Parameters:
      elementType - the list's element type
      Returns:
      a list complete data type
      Since:
      6.3
    • forDoubleList

      public static CompleteDataType forDoubleList()
      Returns:
      the equivalence of calling forList(forDouble())
    • forIntList

      public static CompleteDataType forIntList()
      Returns:
      the equivalence of calling forList(forInt())
    • forLongList

      public static CompleteDataType forLongList()
      Returns:
      the equivalence of calling forList(forLong())
    • forStringList

      public static CompleteDataType forStringList()
      Returns:
      the equivalence of calling forList(forString())
    • forBoolList

      public static CompleteDataType forBoolList()
      Returns:
      the equivalence of calling forList(forBool())
    • forBlobList

      public static CompleteDataType forBlobList()
      Returns:
      the equivalence of calling forList(forBlob())
    • forTimestampList

      public static CompleteDataType forTimestampList()
      Returns:
      the equivalence of calling forList(forTimestamp())
    • forCapture

      public static CompleteDataType forCapture(String typeName)
      Return a capture complete data type with the specified type parameter name. The type parameter name, to be meaningful in the context of a module, must match a type parameter name that is bound by one of the input streams of the module. (All type parameters at the top level are considered to be bound to an empty set of fields)
      Parameters:
      typeName - the type parameter name to use
      Returns:
      a CaptureType with the given type parameter name
      Since:
      7.2
    • findSuperType

      public static CompleteDataType findSuperType(CompleteDataType t1, CompleteDataType t2)
      Find a type that t1 and t2 can both promote to safely
      Parameters:
      t1 - an input type or null
      t2 - an input type or null
      Returns:
      a type such that both t1.promoteTo() and t2.promoteTo() is safe or null if no such type is available or either argument is null
    • forFunction

      public static CompleteDataType.FunctionType forFunction(Schema argumentSchema, CompleteDataType returnType)
      Return a function's CompleteDataType with the given argument schema and return type
      Parameters:
      argumentSchema - the function's arguments. To represent no arguments, pass an empty schema, not null.
      returnType - the function's return type
      Returns:
      a function's CompleteDataType
      Since:
      7.4