You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by rakesh kothari <rk...@hotmail.com> on 2010/09/28 21:45:05 UTC

Accessing Nested Json

Hi,

Is there a good way to access nested properties that are multilevel deep from Json objects loaded in Pig ?

For example, if my json is like:

{"keyA":{"pA":"vA"}} and I need to access "pA". 

Thanks,
-Rakesh
 		 	   		  

Re: Accessing Nested Json

Posted by hc busy <hc...@gmail.com>.
hooray!

On Wed, Sep 29, 2010 at 4:24 PM, Alan Gates <ga...@yahoo-inc.com> wrote:

>
> On Sep 29, 2010, at 3:46 PM, hc busy wrote:
>
>  I thought map can only take bytearray as value type?
>>
>
> No, it can take any type as a value.  There are just a number of places
> where Pig assumes it is a byte array and then does the wrong thing (like if
> you try to order by it).  If the user just dereferences the object as if it
> were a tuple or a map then Pig should implicitly cast it and do the right
> thing.
>
> As a side note, we plan to fix the bad byte array assumptions issues in Pig
> 0.9.  See in particular https://issues.apache.org/jira/browse/PIG-1281,
> https://issues.apache.org/jira/browse/PIG-1065, and
> https://issues.apache.org/jira/browse/PIG-999.
>
> Alan.
>
>
>
>> On Wed, Sep 29, 2010 at 1:53 PM, Alan Gates <ga...@yahoo-inc.com> wrote:
>>
>>  Are you loading them as tuples or maps?  If you're loading them as tuples
>>> than you should be able to say x.keyA.pA (which should return "vA").  If
>>> you're loading them as maps than it would be x#'keyA'#'pA'
>>>
>>> Alan.
>>>
>>>
>>> On Sep 28, 2010, at 12:45 PM, rakesh kothari wrote:
>>>
>>>
>>>  Hi,
>>>>
>>>> Is there a good way to access nested properties that are multilevel deep
>>>> from Json objects loaded in Pig ?
>>>>
>>>> For example, if my json is like:
>>>>
>>>> {"keyA":{"pA":"vA"}} and I need to access "pA".
>>>>
>>>> Thanks,
>>>> -Rakesh
>>>>
>>>>
>>>>
>>>
>>>
>

Re: Accessing Nested Json

Posted by Alan Gates <ga...@yahoo-inc.com>.
On Sep 29, 2010, at 3:46 PM, hc busy wrote:

> I thought map can only take bytearray as value type?

No, it can take any type as a value.  There are just a number of  
places where Pig assumes it is a byte array and then does the wrong  
thing (like if you try to order by it).  If the user just dereferences  
the object as if it were a tuple or a map then Pig should implicitly  
cast it and do the right thing.

As a side note, we plan to fix the bad byte array assumptions issues  
in Pig 0.9.  See in particular https://issues.apache.org/jira/browse/PIG-1281 
, https://issues.apache.org/jira/browse/PIG-1065, and https://issues.apache.org/jira/browse/PIG-999 
.

Alan.

>
> On Wed, Sep 29, 2010 at 1:53 PM, Alan Gates <ga...@yahoo-inc.com>  
> wrote:
>
>> Are you loading them as tuples or maps?  If you're loading them as  
>> tuples
>> than you should be able to say x.keyA.pA (which should return  
>> "vA").  If
>> you're loading them as maps than it would be x#'keyA'#'pA'
>>
>> Alan.
>>
>>
>> On Sep 28, 2010, at 12:45 PM, rakesh kothari wrote:
>>
>>
>>> Hi,
>>>
>>> Is there a good way to access nested properties that are  
>>> multilevel deep
>>> from Json objects loaded in Pig ?
>>>
>>> For example, if my json is like:
>>>
>>> {"keyA":{"pA":"vA"}} and I need to access "pA".
>>>
>>> Thanks,
>>> -Rakesh
>>>
>>>
>>
>>


Re: Accessing Nested Json

Posted by hc busy <hc...@gmail.com>.
I thought map can only take bytearray as value type?

On Wed, Sep 29, 2010 at 1:53 PM, Alan Gates <ga...@yahoo-inc.com> wrote:

> Are you loading them as tuples or maps?  If you're loading them as tuples
> than you should be able to say x.keyA.pA (which should return "vA").  If
> you're loading them as maps than it would be x#'keyA'#'pA'
>
> Alan.
>
>
> On Sep 28, 2010, at 12:45 PM, rakesh kothari wrote:
>
>
>> Hi,
>>
>> Is there a good way to access nested properties that are multilevel deep
>> from Json objects loaded in Pig ?
>>
>> For example, if my json is like:
>>
>> {"keyA":{"pA":"vA"}} and I need to access "pA".
>>
>> Thanks,
>> -Rakesh
>>
>>
>
>

RE: Accessing Nested Json

Posted by rakesh kothari <rk...@hotmail.com>.
Thanks Alan. That works!

-Rakesh

> From: gates@yahoo-inc.com
> To: pig-user@hadoop.apache.org
> Subject: Re: Accessing Nested Json
> Date: Wed, 29 Sep 2010 13:53:42 -0700
> 
> Are you loading them as tuples or maps?  If you're loading them as  
> tuples than you should be able to say x.keyA.pA (which should return  
> "vA").  If you're loading them as maps than it would be x#'keyA'#'pA'
> 
> Alan.
> 
> On Sep 28, 2010, at 12:45 PM, rakesh kothari wrote:
> 
> >
> > Hi,
> >
> > Is there a good way to access nested properties that are multilevel  
> > deep from Json objects loaded in Pig ?
> >
> > For example, if my json is like:
> >
> > {"keyA":{"pA":"vA"}} and I need to access "pA".
> >
> > Thanks,
> > -Rakesh
> > 		 	   		
> 
 		 	   		  

Re: Accessing Nested Json

Posted by Alan Gates <ga...@yahoo-inc.com>.
Are you loading them as tuples or maps?  If you're loading them as  
tuples than you should be able to say x.keyA.pA (which should return  
"vA").  If you're loading them as maps than it would be x#'keyA'#'pA'

Alan.

On Sep 28, 2010, at 12:45 PM, rakesh kothari wrote:

>
> Hi,
>
> Is there a good way to access nested properties that are multilevel  
> deep from Json objects loaded in Pig ?
>
> For example, if my json is like:
>
> {"keyA":{"pA":"vA"}} and I need to access "pA".
>
> Thanks,
> -Rakesh
>