Package com.streambase.sb
Class CompleteDataType
java.lang.Object
com.streambase.sb.CompleteDataType
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CompleteDataType.CaptureType
,CompleteDataType.FunctionType
,CompleteDataType.ListType
,CompleteDataType.TupleType
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 aCompleteDataType
)
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Capture typestatic class
Function typestatic class
List typestatic class
Tuple type -
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Null to type coercion valuestatic final long
Coercion score failstatic final long
Coercion score passprotected final DataType
Wrapped data typestatic final long
Type to type coercion valuestatic final long
Wild card coercion value -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
canAssignFrom
(CompleteDataType other) Check if a value of this type can be assigned a value of the other type.protected boolean
Method for subclasses to override if they have a broader concept of type.protected boolean
equalBaseTypes
(CompleteDataType other) Compare wrapped typesstatic CompleteDataType
Find a type that t1 and t2 can both promote to safelystatic CompleteDataType
forBlob()
Return the complete type for a blob.static CompleteDataType
static CompleteDataType
forBool()
Deprecated.static CompleteDataType
Return the complete type for a bool.static CompleteDataType
static CompleteDataType
forCapture
(String typeName) Return a capture complete data type with the specified type parameter name.static CompleteDataType
Return the complete type for a double.static CompleteDataType
forFunction
(Schema argumentSchema, CompleteDataType returnType) Return a function'sCompleteDataType
with the given argument schema and return typestatic CompleteDataType
forInt()
Return the complete type for an int.static CompleteDataType
static CompleteDataType
forList
(CompleteDataType elementType) Return a list complete data type with the specified element typestatic CompleteDataType
forLong()
Return the complete type for a long.static CompleteDataType
static CompleteDataType
Return the complete type for a string.static CompleteDataType
static CompleteDataType
Return the complete type for a timestamp.static CompleteDataType
static CompleteDataType
Return a tuple complete data type with the specified schema.For function types, return the argument schema.For capture types, return the capture type name.Return the data type of the complete typeFor list collection types, return the complete type of the list's elements.getName()
Get the name of this complete typeFor function types, return the return type of the function.For tuple types, return the tuple's schema.long
rateCoercion
(CompleteDataType type) calculate the coercion score to get coerce this → type - by default returns SCORE_PASS or SCORE_FAIL based on equalsstatic long
rateCoercion
(CompleteDataType from, CompleteDataType to) Rate coercionReturn a String describing the type suitable for error messages.abstract String
toHumanString
(SchemaUtil.SchemaProvider schemaProvider) Return a String describing the type suitable for error messages.final String
toString()
-
Field Details
-
type
Wrapped data type -
SCORE_FAIL
public static final long SCORE_FAILCoercion score fail- See Also:
-
SCORE_PASS
public static final long SCORE_PASSCoercion score pass- See Also:
-
TYPE_TO_TYPE_SCORE
public static final long TYPE_TO_TYPE_SCOREType to type coercion value- See Also:
-
NULL_TO_TYPE_SCORE
public static final long NULL_TO_TYPE_SCORENull to type coercion value- See Also:
-
WILDCARD_SCORE
public static final long WILDCARD_SCOREWild card coercion value- See Also:
-
-
Constructor Details
-
CompleteDataType
Constructor- Parameters:
type
- Data type
-
-
Method Details
-
getDataType
Return the data type of the complete type- Returns:
- the DataType
-
toString
-
toHumanString
Return a String describing the type suitable for error messages.Assumes no schemas are named.
- Returns:
- a suitable string
- Since:
- 6.3
-
canAssignFrom
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
Method for subclasses to override if they have a broader concept of type.- Parameters:
other
- the other type- Returns:
- type assignment compatibility
-
rateCoercion
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
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
Compare wrapped types- Parameters:
other
- Compare with this type- Returns:
- true if equal
-
getName
Get the name of this complete type- Returns:
- the name of this CompleteDataType
-
getSchema
For tuple types, return the tuple's schema. For other types null is returned.- Returns:
- the tuple types's schema
-
getArgumentSchema
For function types, return the argument schema. For other types null is returned.- Returns:
- the function type's argument schema
-
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
For capture types, return the capture type name. For other types, null is returned- Returns:
- the capture name
-
getReturnType
For function types, return the return type of the function. For other types, return null.- Returns:
- the function type's return type
-
rateCoercion
Rate coercion- Parameters:
from
- From typeto
- To type- Returns:
- Coercion value
-
forBool
Deprecated.UseforBoolean()
Return the complete type for a bool.- Returns:
- a boolean complete data type
- Since:
- 6.3
-
forBoolean
Return the complete type for a bool.- Returns:
- a boolean complete data type
- Since:
- 6.3
-
forBlob
Return the complete type for a blob.- Returns:
- a blob complete data type.
- Since:
- 6.3
-
forDouble
Return the complete type for a double.- Returns:
- a double complete data type
- Since:
- 6.3
-
forInt
Return the complete type for an int.- Returns:
- a int complete data type
- Since:
- 6.3
-
forLong
Return the complete type for a long.- Returns:
- a long complete data type
- Since:
- 6.3
-
forString
Return the complete type for a string.- Returns:
- a string complete data type
- Since:
- 6.3
-
forTimestamp
Return the complete type for a timestamp.- Returns:
- a timestamp complete data type
- Since:
- 6.3
-
forTuple
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
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
- Returns:
- the equivalence of calling forList(forDouble())
-
forIntList
- Returns:
- the equivalence of calling forList(forInt())
-
forLongList
- Returns:
- the equivalence of calling forList(forLong())
-
forStringList
- Returns:
- the equivalence of calling forList(forString())
-
forBoolList
- Returns:
- the equivalence of calling forList(forBool())
-
forBlobList
- Returns:
- the equivalence of calling forList(forBlob())
-
forTimestampList
- Returns:
- the equivalence of calling forList(forTimestamp())
-
forCapture
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
Find a type that t1 and t2 can both promote to safely- Parameters:
t1
- an input type or nullt2
- 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'sCompleteDataType
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
-
forBoolean()