public abstract class BulletRecordConverter extends Object implements Serializable
BulletDSLConfig
. If a BulletRecordSchema
is provided, and type-checking is
enabled, the converter will check that values match their types in the schema and throw if they do not. If a schema is
not provided, the level of type-checking is left to the implementation.Modifier and Type | Field and Description |
---|---|
protected BulletDSLConfig |
config |
protected BulletRecordSchema |
schema |
protected boolean |
shouldTypeCheck |
Constructor and Description |
---|
BulletRecordConverter(com.yahoo.bullet.common.BulletConfig bulletConfig)
Constructor that takes a configuration containing the settings relevant for this converter.
|
Modifier and Type | Method and Description |
---|---|
protected BulletRecordConverter |
build()
Helper function used to initialize BulletRecordConverter from BulletDSLConfig.
|
com.yahoo.bullet.record.BulletRecord |
convert(Object object)
Converts an object to a BulletRecord using the configuration-defined implementation of BulletRecord.
|
com.yahoo.bullet.record.BulletRecord |
convert(Object object,
com.yahoo.bullet.record.BulletRecord record)
Converts an object to a BulletRecord using the given record.
|
protected void |
flattenMap(Map<String,Serializable> mapRecord,
com.yahoo.bullet.record.BulletRecord record)
Takes the fields of a map and inserts them into a BulletRecord.
|
static BulletRecordConverter |
from(BulletDSLConfig config)
Creates a BulletRecordConverter instance using the specified class.
|
protected abstract Object |
get(Object object,
String base)
Gets the specified top-level field from the object.
|
protected Object |
getField(Object object,
String field)
Gets the specified inner field from the object.
|
protected com.yahoo.bullet.typesystem.TypedObject |
getTypedObject(String name,
com.yahoo.bullet.typesystem.Type type,
Serializable value)
Converts the field value with the given name and expected type into a
TypedObject . |
protected void |
setField(BulletRecordField field,
Object value,
com.yahoo.bullet.record.BulletRecord record)
Sets the field in a
BulletRecord . |
protected BulletDSLConfig config
protected BulletRecordSchema schema
protected boolean shouldTypeCheck
public BulletRecordConverter(com.yahoo.bullet.common.BulletConfig bulletConfig)
bulletConfig
- The BulletConfig
to use.protected BulletRecordConverter build() throws BulletDSLException
BulletRecordProvider
, and optionally the BulletRecordSchema
, used by the converter.BulletDSLException
- if there is an error creating the converter.public com.yahoo.bullet.record.BulletRecord convert(Object object) throws BulletDSLException
object
- The object to be converted.BulletDSLException
- if there is an error converting the object to a BulletRecord.public com.yahoo.bullet.record.BulletRecord convert(Object object, com.yahoo.bullet.record.BulletRecord record) throws BulletDSLException
object
- The object to be converted.record
- The record to insert fields into.BulletDSLException
- if there is an error converting the object to a BulletRecord.protected void setField(BulletRecordField field, Object value, com.yahoo.bullet.record.BulletRecord record)
BulletRecord
.field
- The field to set.value
- The value to set the field to.record
- The record to set the field in.protected void flattenMap(Map<String,Serializable> mapRecord, com.yahoo.bullet.record.BulletRecord record)
mapRecord
- The map to take fields from.record
- The BulletRecord to insert fields into.protected abstract Object get(Object object, String base)
object
- The object to get from.base
- The top-level field to get.protected Object getField(Object object, String field)
object
- The object to get from.field
- The inner field to get.protected com.yahoo.bullet.typesystem.TypedObject getTypedObject(String name, com.yahoo.bullet.typesystem.Type type, Serializable value)
TypedObject
. If type checking is
enabled, it will check to make sure that the expected type matches the final type in the TypedObject
.
This method is only used for non-record fields.name
- The name of the field.type
- The expected type of the field.value
- The Serializable
value of the field.TypedObject
wrapping the value.public static BulletRecordConverter from(BulletDSLConfig config)
config
- The configuration containing the BulletRecordConverter class name and other relevant settings.Copyright © 2021. All rights reserved.