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
public abstract class CompleteDataType extends Object implements Serializable
WrapsDataType
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompleteDataType.CaptureType
Capture typestatic class
CompleteDataType.FunctionType
Function typestatic class
CompleteDataType.ListType
List typestatic class
CompleteDataType.TupleType
Tuple type
-
Field Summary
Fields Modifier and Type Field Description static long
NULL_TO_TYPE_SCORE
Null to type coercion valuestatic long
SCORE_FAIL
Coercion score failstatic long
SCORE_PASS
Coercion score passprotected DataType
type
Wrapped data typestatic long
TYPE_TO_TYPE_SCORE
Type to type coercion valuestatic long
WILDCARD_SCORE
Wild card coercion value
-
Constructor Summary
Constructors Modifier Constructor Description protected
CompleteDataType(DataType type)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
canAssignFrom(CompleteDataType other)
Check if a value of this type can be assigned a value of the other type.protected boolean
canAssignFromImpl(CompleteDataType other)
Method for subclasses to override if they have a broader concept of type.protected boolean
equalBaseTypes(CompleteDataType other)
Compare wrapped typesstatic CompleteDataType
findSuperType(CompleteDataType t1, CompleteDataType t2)
Find a type that t1 and t2 can both promote to safelystatic CompleteDataType
forBlob()
Return the complete type for a blob.static CompleteDataType
forBlobList()
static CompleteDataType
forBool()
Deprecated.UseforBoolean()
static CompleteDataType
forBoolean()
Return the complete type for a bool.static CompleteDataType
forBoolList()
static CompleteDataType
forCapture(String typeName)
Return a capture complete data type with the specified type parameter name.static CompleteDataType
forDouble()
Return the complete type for a double.static CompleteDataType
forDoubleList()
static CompleteDataType.FunctionType
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
forIntList()
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
forLongList()
static CompleteDataType
forString()
Return the complete type for a string.static CompleteDataType
forStringList()
static CompleteDataType
forTimestamp()
Return the complete type for a timestamp.static CompleteDataType
forTimestampList()
static CompleteDataType
forTuple(Schema schema)
Return a tuple complete data type with the specified schema.Schema
getArgumentSchema()
For function types, return the argument schema.String
getCaptureName()
For capture types, return the capture type name.DataType
getDataType()
Return the data type of the complete typeCompleteDataType
getElementType()
For list collection types, return the complete type of the list's elements.String
getName()
Get the name of this complete typeCompleteDataType
getReturnType()
For function types, return the return type of the function.Schema
getSchema()
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 coercionString
toHumanString()
Return 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.String
toString()
-
-
-
Field Detail
-
type
protected final DataType type
Wrapped data type
-
SCORE_FAIL
public static final long SCORE_FAIL
Coercion score fail- See Also:
- Constant Field Values
-
SCORE_PASS
public static final long SCORE_PASS
Coercion score pass- See Also:
- Constant Field Values
-
TYPE_TO_TYPE_SCORE
public static final long TYPE_TO_TYPE_SCORE
Type to type coercion value- See Also:
- Constant Field Values
-
NULL_TO_TYPE_SCORE
public static final long NULL_TO_TYPE_SCORE
Null to type coercion value- See Also:
- Constant Field Values
-
WILDCARD_SCORE
public static final long WILDCARD_SCORE
Wild card coercion value- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CompleteDataType
protected CompleteDataType(DataType type)
Constructor- Parameters:
type
- Data type
-
-
Method Detail
-
getDataType
public DataType getDataType()
Return the data type of the complete type- Returns:
- the DataType
-
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 typeto
- To type- Returns:
- Coercion value
-
forBool
@Deprecated public static CompleteDataType forBool()
Deprecated.UseforBoolean()
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 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
-
-