Ask Your Question
2

Incorrect example of usage of Data Collector Records in JavaScript Evaluator

asked 2019-12-12 03:14:38 -0600

Gill Bates gravatar image

There is such an example in "Accessing Record Details" section:

from com.streamsets.pipeline.api import Field
...
record.sdcRecord.set('/new', Field.create(Field.Type.STRING, 'new-value'))
record.sdcRecord.get('/old').setAttribute('attr', 'attr-value')
...

But it doesn't work, it seems like it's copy-pasted from the analogous Groovy example from documentation for the Groovy processor.

Can someone kindly post a working example of usage of Data Collector Records in JavaScript Processor?

edit retag flag offensive close merge delete

Comments

good catch - it'd be nice to use Java APIs in JS Eval but don't think that is possible

meash-nrel gravatar imagemeash-nrel ( 2019-12-12 15:01:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-12-12 15:36:58 -0600

metadaddy gravatar image

updated 2019-12-12 15:42:06 -0600

I'll open a doc bug for this... In the meantime, here is the correct code for JavaScript:

var Field = Java.type('com.streamsets.pipeline.api.Field');
...
records[i].sdcRecord.set('/new', Field.create(Field.Type.STRING, 'new-value'))
records[i].sdcRecord.get('/old').setAttribute('attr', 'attr-value')
...

Note that, as mentioned in the doc, you'll need to set Record Type to 'Data Collector Records' in the Advanced tab:

image description

Working in preview:

image description

edit flag offensive delete link more

Comments

Awesome! Thank you very much!

Gill Bates gravatar imageGill Bates ( 2019-12-12 15:43:21 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-12-12 03:14:38 -0600

Seen: 81 times

Last updated: Dec 12 '19