Skip to main content
Question

Access fieldname and values in sdc.records in jython evaluator processor


I’m trying to access each value inside a record using field name. But getting an error which says record has no attribute value.

What is the correct approach to access and modify values in each record in a loop?

PIPELINE-

ERROR - 

CODE - 

for record in sdc.records:
    try:
        sdc.output.write(record.value["name"])
    except Exception as e:
        sdc.error.write(record, str(e))

DATA SOURCE - dev raw data source 

{
    "id":1,
    "name": "anjay",
    "company_name":"persistent"
    }
    {
    "id":2,
    "name": "Binjay",
    "company_name":"persistnt"
    }
    {
    "id":3,
    "name": "Cinjay",
    "company_name":"infosys"
    }
    {
    "id":4,
    "name": "Dinjay",
    "company_name":"infsys"
    }
    {
    "id":5,
    "name": "Einnjay",
    "company_name":"cisco"
    }
    {
        "id":6,
        "name": "Finjay",
        "company_name":"sisco"
    }

3 replies

Sanjeev
StreamSets Employee
Forum|alt.badge.img
  • StreamSets Employee
  • 53 replies
  • August 7, 2023

@nachiket_pethe please see the example code below which change the case to uppercase for each ‘name’ field

for record in sdc.records:
  try:
    record.value['name'] = record.value['name'].upper()
    # Write record to processor output
    sdc.output.write(record)

  except Exception as e:
    # Send record to error
    sdc.error.write(record, str(e))

 


Thanks for the reply @Sanjeev.

I tried to run the exact same code but got the same error.

 


Bikram
Headliner
Forum|alt.badge.img+1
  • Headliner
  • 486 replies
  • August 7, 2023

@nachiket_pethe 

There shouldn’t be any issues in the code suggested by sanjeev but try too import the attached pipeline and check if it helps.


Reply