You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The KeyValue Feature allows to read, process and write data as key-value pairs, which don't have an fixed schema like tuples.

To use the feature you have to install it and use the "KeyValueObject" or "NestedKeyValueObject" data handler. The applicable operators will be automatically chosen. Until now selection and projection are supported. Also there are operators to transform key-value objects to tuples and the other way round. The feature also includes wrapper for handling of JSON and BSON data.

Operators

The following new or modificated operators are provided in keyvalue feature.

KeyValueToTuple

Transforms key-value object to tuples. All data fields which are not defined in schema will be lost.

#DEFINE SCHEMA [['timestamp.unixtimestamp', 'List(Integer)'],['timestamp.iso', 'String'],['track.name', 'String'],['uncorrectedTrack.name', 'String']]
tuple = KEYVALUETOTUPLE({schema=${SCHEMA}, KEEPINPUT = 'false', TYPE = 'type'}, receiverJSON)

TupleToKeyValue

Transforms tuples to key-value objects based on tuples schema.

tupleToKeyValue = TUPLETOKEYVALUE(receiverTuple)

Select

selectJSON = SELECT({predicate='track.artist.name = "Evanescence"'}, receiverJSON)
selectJSONList = SELECT({predicate='timestamp.unixtimestamp[0] = 1162304033'}, receiverJSON)

Project

For the key-value projection the "paths" attribute has to be used. The "attributes" attribute only works for relational tuples.

 projectJSON = PROJECT({paths = [['timestamp.unixtimestamp', 'List(Integer)'],['timestamp.iso', 'String']]}, receiverJSON)

Wrapper

The feature adds protocol handler for the common key-value data formats JSON and BSON (binary JSON).

JSON

Read JSON file

 json = ACCESS({
    source='json', 
    wrapper='GenericPull',
    transport='File',
    protocol='JSON',
    dataHandler='KeyValueObject',
    options=[['filename','${WORKSPACEPROJECT}\scrobbles-2006-10_linebreak.json']]
})

Write JSON file

SENDERjson = SENDER({
    transport='File',
    wrapper='GenericPush',
    protocol='JSON',
    dataHandler='KeyValueObject',
    SINK="SENDERjson",
    options=[['filename','${WORKSPACEPROJECT}\output\test2']]
}, json)

Transfer data with JSON

JSON protocol handler can not only be used to read and write files, but also to transfer data from one odysseus instance to another. The example shows the use of TCP as transport protocol, but RabbitMQ can be used the same way.

 SENDERjson = SENDER({
    transport='TCPServer',
    wrapper='GenericPush',
    protocol='JSON',
    dataHandler='KeyValueObject',
    SINK="SENDERjson",
    options=[
        ['port', '8080'],
        ['HOST','localhost'],
    ]}, json)
receiverJSON = RECEIVE({
    transport='TCPClient',
    source= 'ReceiverJSON',
    protocol='JSON',
    dataHandler='KeyValueObject',
    options=[['port', '8080']]         
})

BSON

BSON can be used in exactly the same way as JSON - just replace the protocol handler.

More information about BSON can be found at http://bsonspec.org/.

  • No labels