public class TypeUtil extends Object
Modifier and Type | Method and Description |
---|---|
static RecordTokenType |
addSourceInfoFields(RecordTokenType type)
Constructs the output type used when tagging with source information fields.
|
static Field |
annotate(Field field,
String propertyName,
String propertyValue)
Returns a new field object with the same type and name as the original, but
with the given property set to the given value.
|
static RecordTokenType |
annotate(RecordTokenType type,
String propertyName,
String propertyValue)
Returns a new RecordTokenType with the given annotation applied to all
of its fields.
|
static RecordTokenType |
deriveSchema(ScalarTyped... columns)
Builds a default record schema using the types of the specified
columnar objects.
|
static TokenType |
fromJSON(String json)
Parses a JSON description of a
TokenType . |
static List<String> |
getDomainValuesAsStrings(FieldDomain domain)
Returns the values of the domain as strings
|
static <T extends ScalarTyped & Named> |
getRecordType(T... fields)
Computes the record type which a composite of the specified fields would have.
|
static ScalarTokenType[] |
getTypes(RecordTokenType type)
Returns the types of the fields of this record type.
|
static boolean |
hasDomainValues(RecordTokenType type)
Returns whether all of the fields in the given type have domain values.
|
static boolean |
hasDomainValues(RecordTokenType type,
String field)
Returns whether the given field has domain values defined.
|
static RecordTokenType |
homogeneousRecord(int size,
ScalarTokenType fieldType,
String fieldBase)
Constructs a record type descriptor in which all fields have the same
type.
|
static RecordTokenType |
matchFieldNames(RecordTokenType source,
RecordTokenType match)
Utility for renaming the fields of a given record type to match that of
another.
|
static RecordTokenType |
merge(RecordTokenType... types)
Merges the specified record types into a new one, handling name collisions
by renaming.
|
static FieldDomain |
mergeDomain(FieldDomain domain1,
FieldDomain domain2)
Merges two domains.
|
static DataRepresentation |
mergeRepresentations(TokenType... types)
Returns the overall representation to be used when combining types.
|
static RecordTokenType |
mergeTypes(TokenType... types)
Merges the specified types into a single record type, handling name collisions
by renaming.
|
static RecordTokenType |
mutating(RecordTokenType type,
Collection<String> modifiedFields)
Computes the resulting type assuming that the specified fields
may be mutated.
|
static Field |
nonUnique(Field field)
Returns a new field object with the same type and name as the original, but with the
primaryKey flag set to false |
static RecordTokenType |
nonUnique(RecordTokenType type)
Returns a RecordTokenType, equivalent to the original, but with all
primaryKey
flags set to false |
static RecordTokenType |
overlay(RecordTokenType... types)
Merges the specified record types into a new record type, handling name collisions
with a last-one-wins mechanism.
|
static Field |
primaryKey(Field field,
boolean primaryKey)
Returns a new field object with the same type and name as the original, but with the
primaryKey flag set to the given value. |
static RecordTokenType |
remove(RecordTokenType source,
List<String> removed)
Creates a new record type containing all fields from the source type except
those matching one of the specified field names.
|
static RecordTokenType |
remove(RecordTokenType source,
String... removed)
Creates a new record type containing all fields from the source type except
those matching one of the specified field names.
|
static RecordTokenType |
rename(RecordTokenType source,
Map<String,String> sourceToTargetNameMap)
Utility for renaming fields in the source type using the given source
and target field names.
|
static RecordTokenType |
rename(RecordTokenType source,
String[] sourceNames,
String[] targetNames)
Utility for renaming fields in the source type using the given source
and target field names.
|
static RecordTokenType |
reorderAndRename(RecordTokenType source,
String[] sourceNames,
String[] targetNames)
Utility for the renaming/reordering of a given record type.
|
static RecordTokenType |
retain(RecordTokenType source,
List<String> retained)
Creates a new record type containing only fields from the source type which
match one of the specified field names.
|
static RecordTokenType |
retain(RecordTokenType source,
String... retained)
Creates a new record type containing only fields from the source type which
match one of the specified field names.
|
static RecordTokenType |
select(RecordTokenType source,
List<String> selected)
Creates a new record type containing only fields from the source type which
match one of the specified field names.
|
static RecordTokenType |
select(RecordTokenType source,
String... selected)
Creates a new record type containing only fields from the source type which
match one of the specified field names.
|
static RecordTokenType |
strictOverlay(boolean dropUnique,
RecordTokenType... types)
Merges the specified record types into a new record type, allowing name collisions
only if
isAssignableFrom() is true for the types. |
static String |
toJSON(TokenType type)
Generates the JSON description of the specified type.
|
static RecordTokenType |
toType(DataRepresentation representation,
Namespace<ScalarTokenType> namespace)
Converts from a list of fields to a record token type.
|
static RecordTokenType |
validateFieldSelection(String propertyName,
RecordTokenType source,
String... selected)
Validates a set of field names against the source type, computing the
resulting type.
|
static void |
validateRequiredFields(String propertyName,
RecordTokenType source,
RecordTokenType required)
Validates a set of Fields against the source type ensuring the required field names are present and of the same type.
|
static ScalarTokenType |
valueOf(String type)
Gets the named scalar type.
|
static RecordTokenType |
widestNamedType(RecordTokenType... types)
Calculates the record type for which
isAssignableFrom()
is true for all of the specified types matched by name. |
static RecordTokenType |
widestType(RecordTokenType... types)
Calculates the record type for which
isAssignableFrom()
is true for all of the specified types. |
static ScalarTokenType |
widestType(ScalarTokenType... types)
Determines the widest of the specified types.
|
static RecordTokenType |
withDomainValues(RecordTokenType type,
String fieldName,
Set<String> discovered)
Returns a new RecordTokenType with domain values set to the discovered values.
|
static RecordTokenType |
wrap(List<? extends ScalarTokenType> types)
Creates a new record type with the specified field types.
|
static RecordTokenType |
wrap(String prefix,
List<? extends ScalarTokenType> types)
Creates a new record schema with the specified field types.
|
static RecordTokenType |
wrap(String name,
ScalarTokenType type)
Creates a new record type with a single named field of the given type.
|
public static <T extends ScalarTyped & Named> RecordTokenType getRecordType(T... fields)
fields
- the objects representing the fields of the compositepublic static final RecordTokenType validateFieldSelection(String propertyName, RecordTokenType source, String... selected)
propertyName
- the property name to use in the validation failure exceptionsource
- the record type to checkselected
- the field names to validate, in the desired ordering
for the new typecom.pervasive.datarush.graphs.physical.InvalidPropertyValueException
- if one or more of the specified fields do not
exist in the source typepublic static final void validateRequiredFields(String propertyName, RecordTokenType source, RecordTokenType required)
propertyName
- the property name to use in the validation failure exceptionsource
- the record type to checkrequired
- the fields to validatecom.pervasive.datarush.graphs.physical.InvalidPropertyValueException
- if one or more of the specified fields do not
exist in the source typepublic static final RecordTokenType select(RecordTokenType source, String... selected)
The specified fields must be valid names in the source type.
source
- the record type to filterselected
- the field names to keep in the new type, in the desired ordering
for the new typeInvalidFieldException
- if one or more of the specified fields do not
exist in the source typepublic static final RecordTokenType toType(DataRepresentation representation, Namespace<ScalarTokenType> namespace)
representation
- the representationnamespace
- the list of fieldspublic static final RecordTokenType select(RecordTokenType source, List<String> selected)
The specified fields must be valid names in the source type.
source
- the record type to filterselected
- the field names to keep in the new type, in the desired ordering
for the new typeInvalidFieldException
- if one or more of the specified fields do not
exist in the source typepublic static final RecordTokenType retain(RecordTokenType source, String... retained)
The specified fields do not need to be valid names in the source type.
source
- the record type to filterretained
- the field names to keep in the new typepublic static final RecordTokenType retain(RecordTokenType source, List<String> retained)
The specified fields do not need to be valid names in the source type.
source
- the record type to filterretained
- the field names to keep in the new typepublic static final RecordTokenType remove(RecordTokenType source, String... removed)
The specified fields do not need to be valid names in the source type.
source
- the record type to filterremoved
- the field names to remove from the new typepublic static final RecordTokenType remove(RecordTokenType source, List<String> removed)
The specified fields do not need to be valid names in the source type.
source
- the record type to filterremoved
- the field names to remove from the new typepublic static final RecordTokenType reorderAndRename(RecordTokenType source, String[] sourceNames, String[] targetNames)
sourceNames
. Those fields are then renamed to the
corresponding ordinal counterpart in targetNames
.source
- source record typesourceNames
- list of fields in source
ordered to the
desired outputtargetNames
- list of names the corresponding ordinal source field
name will be changed topublic static final RecordTokenType rename(RecordTokenType source, Map<String,String> sourceToTargetNameMap)
source
- source token typesourceToTargetNameMap
- mapping from old names to new namespublic static final RecordTokenType rename(RecordTokenType source, String[] sourceNames, String[] targetNames)
source
- source token typesourceNames
- list of field names in the sourcetargetNames
- list of names to substitute for the source namespublic static RecordTokenType wrap(String name, ScalarTokenType type)
name
- the name for the fieldtype
- the type of the field datapublic static RecordTokenType wrap(String prefix, List<? extends ScalarTokenType> types)
prefix + i
,
where i
is the field's 0-based position in the input list.prefix
- the field name prefixtypes
- the types of field datapublic static RecordTokenType wrap(List<? extends ScalarTokenType> types)
"field" + i
,
where i
is the flow's 0-based position in the input list.types
- the types of field datapublic static DataRepresentation mergeRepresentations(TokenType... types)
types
- List of typespublic static RecordTokenType merge(RecordTokenType... types)
The following conditions will hold with respect to the ordering of fields in the result:
For a destructive merge which overwrites fields in collision, use
overlay(RecordTokenType...)
instead.
types
- the record types to mergepublic static RecordTokenType overlay(RecordTokenType... types)
The following conditions will hold with respect to the ordering of fields in the result:
For a non-destructive merge which doesn't replace collisions, use
merge(RecordTokenType...)
instead.
types
- the record types to mergepublic static RecordTokenType strictOverlay(boolean dropUnique, RecordTokenType... types) throws InvalidFieldException
isAssignableFrom()
is true for the types. Otherwise null
will be returned.
The following conditions will hold with respect to the ordering of fields in the result:
For a non-destructive merge which doesn't replace collisions, use
merge(RecordTokenType...)
instead.
dropUnique
- if true will not include fields not present in all recordstypes
- the record types to mergeInvalidFieldException
public static RecordTokenType mergeTypes(TokenType... types)
The result is equivalent to calling merge(RecordTokenType...)
,
passing each record type straight through and replacing all scalar flows in
the input with wrap("input"+i, type)
. Refer to merge(RecordTokenType...)
for specific details on the merged result.
types
- the types to mergepublic static final RecordTokenType matchFieldNames(RecordTokenType source, RecordTokenType match)
source
but the field names of match
.source
- source record typematch
- record type whose field names should be matchedpublic static RecordTokenType homogeneousRecord(int size, ScalarTokenType fieldType, String fieldBase)
fieldBase + index
where
index
is the field's index in the record type.size
- Number of desired fieldsfieldType
- Scalar type of all fieldsfieldBase
- Base field namepublic static TokenType fromJSON(String json)
TokenType
.
This method acts as an inverse to the method {toJSON(TokenType)
method on token types; for any type, it will always be
the case that:
type.equals(TypeUtil.fromJSON(TypeUtil.toJSON(type))
json
- the JSON format of a type.public static String toJSON(TokenType type)
type
- the type for which to generate a descriptionpublic static ScalarTokenType widestType(ScalarTokenType... types)
T
for which T.isAssignableFrom()
is true for all of the types.types
- the scalar types to analyzenull
.TokenType.isAssignableFrom(TokenType)
public static ScalarTokenType[] getTypes(RecordTokenType type)
type
- the record typepublic static ScalarTokenType valueOf(String type)
type
- the type to getpublic static RecordTokenType widestType(RecordTokenType... types)
isAssignableFrom()
is true for all of the specified types. Such a type can only
be found if all record types contain the same number of fields
and a widest scalar type can be found for each field.types
- the record types to analyzenull
.TokenType.isAssignableFrom(TokenType)
,
widestType(ScalarTokenType...)
public static RecordTokenType widestNamedType(RecordTokenType... types)
isAssignableFrom()
is true for all of the specified types matched by name. Such a
type can only be found if all record types contain the same number
of named fields and a widest scalar type can be found for each named field.types
- the record types to analyzenull
.TokenType.isAssignableFrom(TokenType)
,
widestType(ScalarTokenType...)
public static Field annotate(Field field, String propertyName, String propertyValue)
field
- The field to annotatepropertyName
- The name of the annotationpropertyValue
- The value of the annotationpublic static Field primaryKey(Field field, boolean primaryKey)
primaryKey
flag set to the given value.field
- The original fieldprimaryKey
- The value for the primaryKey flagpublic static Field nonUnique(Field field)
primaryKey
flag set to falsefield
- The original fieldpublic static RecordTokenType nonUnique(RecordTokenType type)
primaryKey
flags set to false
type
- the original typepublic static RecordTokenType annotate(RecordTokenType type, String propertyName, String propertyValue)
type
- The type to annotatepropertyName
- The name of the annotationpropertyValue
- The value of the annotationpublic static RecordTokenType deriveSchema(ScalarTyped... columns)
columns
- objects describing the columns. These objects implicitly
provide the column data type.public static RecordTokenType addSourceInfoFields(RecordTokenType type)
type
- the original source type to be extended with source informationpublic static RecordTokenType mutating(RecordTokenType type, Collection<String> modifiedFields)
This methods assumes that both the underlying schema and the relative ordering of records in the flow is unchanged.
the
- the original typemodifiedFields
- the fields that may be modifiedpublic static List<String> getDomainValuesAsStrings(FieldDomain domain)
domain
- the domainpublic static boolean hasDomainValues(RecordTokenType type, String field)
type
- the typefield
- the name of the fieldInvalidFieldException
- if the field is not definedpublic static boolean hasDomainValues(RecordTokenType type)
type
- the typeInvalidFieldException
- if the field is not definedpublic static RecordTokenType withDomainValues(RecordTokenType type, String fieldName, Set<String> discovered)
type
- the original typefieldName
- the field to updatediscovered
- the discovered valuespublic static FieldDomain mergeDomain(FieldDomain domain1, FieldDomain domain2)
lowerBound
equal to the min of the two lower bounds or
unspecified lower bound if either is unspecifiedupperBound
equal to the max of the two upper bounds or
unspecified upper bound if either is unspecifiedvalues
equal to the union of the two sets of values
or unspecified if either is unspecifieddomain1
- the first domaindomain2
- the second domainIllegalArgumentException
- if there is no common base class between the types of the two domainsCopyright © 2016 Actian Corporation. All rights reserved.