nifi-sqllookup-services-bundle icon indicating copy to clipboard operation
nifi-sqllookup-services-bundle copied to clipboard

How to use this service in Lookup attribute?

Open MormonJesus69420 opened this issue 2 years ago • 4 comments

Hi! I would like to use this service in LookupAttribute processor to find an Agent ID based on Agent Name and Agent Version that I get from FlowFile.

I've tried using this service in LookupAttribute but I don't know how to provide those two values to the service through the processor.

In your example you say that this service supports named parameters, for example:

SELECT name FROM foo WHERE sequence = :sequence AND catalog = :catalog

So I've tried putting it in the service with following query:

SELECT agent_id FROM agent WHERE agent_name = :agent_name AND agent_version = :agent_version

I've tried many ways of trying to provide values for these two parameters, but couldn't get it to work with LookupAttribute.
Then I've tried to simplify the SQL query, just to see if I can get it to work and used:

SELECT agent_id FROM agent WHERE agent_name = :agent_name

In LookupAttribute I've defined the property agent _id and given it various values such as "agent_name", "${agent_name}", "agent_name=${agent_name}", "agent_name,${agent_name}", and more, but it didn't work, every time I got following error when I tried running the LookupAttribute processor:

LookupAttribute[id=d9aa39f8-4bc7-1fe5-a4e4-9130dd75dfbf] Processing halted: yielding [1 sec]: org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied for the SQL parameter 'agent': No value registered for key 'agent_name'

I've tried looking through source code to figure out how to fix this, but I have no idea.
Could you help me?

MormonJesus69420 avatar Oct 03 '23 14:10 MormonJesus69420

I can definitely help you out. What version of NiFi are you using?

mrcsparker avatar Oct 03 '23 15:10 mrcsparker

Hi, I am using NiFi 1.22 currently. I had to hack the source code a tiny bit to use the service with LookupAttribute as it requires a StringLookupService, not a LookupService<String>. I done that just by adding implements StringLookupService and it seems to have worked.

MormonJesus69420 avatar Oct 04 '23 05:10 MormonJesus69420

Here's how I have configured the service SQL Query: image Here is the service itself: image And the LookupAttribute processor: image Like I've said before I have tried to set the value of agent_name in various ways, but nothing seems to work. It just throws the same error every time:

LookupAttribute[id=d9aa39f8-4bc7-1fe5-a4e4-9130dd75dfbf] Processing halted: yielding [1 sec]: org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied for the SQL parameter 'agent_name': No value registered for key 'agent_name'

If I hardcode the value in SQL query it works just fine: image image image

MormonJesus69420 avatar Oct 04 '23 05:10 MormonJesus69420

I have also tried following setup to no avail MicrosoftTeams-image MicrosoftTeams-image (1)

MormonJesus69420 avatar Oct 04 '23 14:10 MormonJesus69420