2

I am new to geode .
I am adding like below:

gfsh>put --key=('id':'11') --value=('firstname':'Amaresh','lastname':'Dhal') --region=region
Result      : true
Key Class   : java.lang.String
Key         : ('id':'11')
Value Class : java.lang.String
Old Value   : <NULL>   

when I query like this:

gfsh>query --query="select * from /region"

Result     : true
startCount : 0
endCount   : 20
Rows       : 9

Result
-----------------------------------------
('firstname':'A2','lastname':'D2')
HI
Amaresh
Amaresh
('firstname':'A1','lastname':'D1')
World
World
('firstname':'Amaresh','lastname':'Dhal')
Hello

NEXT_STEP_NAME : END

When I am trying to query like below I am not getting the value:

gfsh>query --query="select * from /region r where r.id='11'"

Result     : true
startCount : 0
endCount   : 20
Rows       : 0


NEXT_STEP_NAME : END

Ofcourse I can use get command...But i want to use where condition..Where I am doing wrong..It gives no output

Thanks

Amaresh
  • 3,231
  • 7
  • 37
  • 60

3 Answers3

2

In Geode the key is not "just another column". In fact, the basic query syntax implicitly queries only the fields of the value. However, you can include the key in your query using this syntax:

select value.lastname, value.firstname from /region.entries where key.id=11

Also, it is fairly common practice to include the id field in your value class even though it is not strictly required.

Randy May
  • 348
  • 1
  • 8
  • @Randy..It doesnt give me the result – Amaresh Dec 01 '15 at 05:30
  • 1
    I see what is happening. The query syntax is right but there is a problem with the "put" and in fact the gemfire documentation on gfsh makes the same mistake . When I tried the same thing, I noticed that the result from the put says that the key class is java.lang.String. So its literally storing the string "('id':'11')". The gfsh command line isn't a great way to work with complex data types. I think if you do a "put" through the API, or even the REST interface, the query will work. – Randy May Dec 02 '15 at 19:08
1

What Randy said is exactly right, the 'key" is not another column. The exact format of the query should be

gfsh>query --query="select * from /Address.entries where key=2"

What you are looking for here is getting all the "entries" on the region "Address" and then querying the key.

To check which one you want to query you can fire this query

   gfsh>query --query="select * from /Address.entries"
1

You can always use the get command to fetch the data pertaining to a specific key.

get --key=<KEY_NAME> --region=<REGION_NAME>

Example:

get --key=1 --region=Address

Reference: https://gemfire.docs.pivotal.io/910/geode/tools_modules/gfsh/command-pages/get.html

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83