Support Questions

Find answers, ask questions, and share your expertise
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

How to add String value in nifi Custom Processor code??



I have created custom processor same like ExecuteSQL.
after executing query all data get in resultset .
I have to add one external string value .
String queryID="123456" -it may be static or dynamic.
Where I have to add that value in resultSet or flowfile?? and how to add that value??
using convert AvroToJson I have take that queryID using EvaluateJsonPath processor and use further operation.
the code is same like below,

Can someone point me at an example to get me going


fileToProcess = session.write(fileToProcess, new OutputStreamCallback() {
public void process(final OutputStream out) throws IOException {
try {
logger.debug("Executing query {}", new Object[]{selectQuery});
final ResultSet resultSet = st.executeQuery(selectQuery);
final JdbcCommon.AvroConversionOptions options = JdbcCommon.AvroConversionOptions.builder()
nrOfRows.set(JdbcCommon.convertToAvroStream(resultSet, out, options, null));
} catch (final SQLException e) {
throw new ProcessException(e);

long duration = stopWatch.getElapsed(TimeUnit.MILLISECONDS);

// set attribute how many rows were selected
fileToProcess = session.putAttribute(fileToProcess, RESULT_ROW_COUNT, String.valueOf(nrOfRows.get()));
fileToProcess = session.putAttribute(fileToProcess, RESULT_QUERY_DURATION, String.valueOf(duration));
fileToProcess = session.putAttribute(fileToProcess, CoreAttributes.MIME_TYPE.key(), JdbcCommon.MIME_TYPE_AVRO_BINARY);"{} contains {} Avro records; transferring to 'success'",
new Object[]{fileToProcess, nrOfRows.get()});
session.getProvenanceReporter().modifyContent(fileToProcess, "Retrieved " + nrOfRows.get() + " rows", duration);
session.transfer(fileToProcess, REL_SUCCESS);


Wouldn't it make sense to add this as an attribute? See the calls to session.putAttribute() in the code above.

View solution in original post


Wouldn't it make sense to add this as an attribute? See the calls to session.putAttribute() in the code above.


after executing query i get resultset. now i want add some value into resultset like query id , query start time , query end time in resultset, so i can get in nifi flow.

Expert Contributor

With nifi 1.3 you have the record based processors. So you can forward the output of executesql or your custom processor to QueryRecord. Set it up to read Avro. Now add a query like so select col_a,col_b..'${query_id}','${query_time}','${query_end_time}' from flowfile'. this will add the data you need to the query resultset.


Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.