Streamsets Jython evaluator

1k Views Asked by At

I need a code on how to check all field of a record if it contains a certain string and write a header attribute if it has that character. Please see code below:

for record in records:
  if record.value == "":
    record.attributes["DATA"] = "BAD"
    sdc.output.write(record)
  else:
    record.attributes["DATA"] = "GOOD"
    sdc.output.write(record)

If anyone know another way to do this that would be great!!! record.values['/*'] doesnt work for me to get all the column.

2

There are 2 best solutions below

0
On

For anyone facing the same problem, this might help!

for record in records:
  for key in record.value:
    if record.value[key] == "":
      record.attributes["DATA"] = key
   sdc.output.write(record)
0
On

Here's another rather compact way of writing it.

for (key,val) in record.value.iteritems():
   if val == "some_string_value":
     record.attributes["DATA"] = "some_header_value"

sdc.output.write(record)

Cheers, Dash