0

I have an userStream having username,ipaddress,timestamp

I want to store this details in UserDetailsTable (In memory table) and need to do an upsert. How could I able to update the row if username and ipaddress are same and insert otherwise as a new row.

For example:

Ist userStream is "Rockey","192.15.12.11","10-10-2015 10.32"
2nd userStream is "Jose","192.15.12.21","10-10-2015 10.33"
3rd userStream is "Rockey","192.15.12.11","10-10-2015 10.34"

Result of UserDetailsTable is below

"Jose","192.15.12.21","10-10-2015 10.33"   (New row)
"Rockey","192.15.12.11","10-10-2015 10.34" (Update the existing row)
Community
  • 1
  • 1

1 Answers1

0

You can use following method.

from userStream
select username, ipaddress ,timestamp
update UserDetailsTable
on UserDetailsTable.username == username

Please not that stream attributes and event tables attributes needs to be same. Hope this helps.

Thanks.

dnWick
  • 393
  • 3
  • 14
  • I think update is okay, but how we can achieve insert too (see the full question) – java specialist May 12 '15 at 03:27
  • for that you can write another query like below. from userStream[not(UserDetailsTable.name == userStream.name in UserDetailsTable)] select userStream.username , userStream.ipaddress, userStream.timestamp insert into UserDetailsTable; – dnWick May 12 '15 at 05:10
  • but it is not working with following query from userStream[not(UserDetailsTable.name == userStream.name and UserDetailsTable.ipaddress == userStream.ipaddress in UserDetailsTable)] select userStream.username , userStream.ipaddress, userStream.timestamp insert into UserDetailsTable; – java specialist May 12 '15 at 15:58
  • Please explain why this answer got -1 here. We cannot have both the conditions in one query like if else. You need to write two consecutive queries to achieve the above. – dnWick May 12 '15 at 16:01
  • I dont marked -1 here, as you have tried to answer my question – java specialist May 12 '15 at 16:04
  • i didn't meant you. I asked the person who down voted it. :) Hope this two queries help you. – dnWick May 12 '15 at 16:14
  • I have tried your answer and it is working fine, but problem is that when using two condtion like below, it is not working, any idea about this [not(UserDetailsTable.name == userStream.name and UserDetailsTable.ipaddress == userStream.ipaddress in UserDetailsTable)] – java specialist May 12 '15 at 16:20
  • sorry i missed your earlier comment. Can you try this way, [not(UserDetailsTable.name == userStream.name in UserDetailsTable) AND not(UserDetailsTable.ipaddress == userStream.ipaddress in UserDetailsTable)]. – dnWick May 12 '15 at 16:57