You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by "Sunderlin, Mark" <ma...@teamaol.com> on 2012/02/02 18:18:44 UTC

How to check if all key/value pairs in two maps are equal?

I am trying to see of two hive maps have the same data in them.  I am not looking to see if any single key-value pair in the maps match, I am looking to see if

a)    There is a one to one match between the keys in map1 and the keys in map2

b)   The matching keys  have the same value in both maps

This doesn't work, but it shows what I want to do:

case
            when map1 = map2
                        then 'maps match'
                        else 'maps do not match'
end match_result




---
Mark E. Sunderlin
Solutions Architect   |AOL Core Data Technologies
P: 703-256-6935       | C: 540-327-6222 | AIM: MESunderlin
22000 AOL Way,  Dulles, VA  20166
[aol-comp-logo]


Re: How to check if all key/value pairs in two maps are equal?

Posted by Mark Grover <mg...@oanda.com>.
Hi Mark,
How about writing your own UDF that does the comparison you want?
UDFs can accept complex arguments (e.g. Maps) just like they do primitive ones.

If you want to go the string route, you could write a UDF that converts a map to JSON string (I have written something similar, I haven't gotten around to submitting it)

Alternatively, you could use the transform syntax to serialize a map into string. You might have to do some string sanitization afterwards:-)
Something along the lines of (untested):
  FROM table
  INSERT OVERWRITE TABLE new_table
  SELECT TRANSFORM(input_map)
  USING '/bin/cat'
  AS (output_map string);

----- Original Message -----
From: "Mark Sunderlin" <ma...@teamaol.com>
To: user@hive.apache.org
Sent: Friday, February 3, 2012 9:19:52 AM
Subject: RE: How to check if all key/value pairs in two maps are equal?




No, can’t cast a map into a string …. * sigh *



---

Mark E. Sunderlin

Solutions Architect |AOL Core Data Technologies

P: 703-256-6935 | C: 540-327-6222 | AIM: MESunderlin

22000 AOL Way | Dulles, VA | 20166




From: Aniket Mokashi [mailto:aniket486@gmail.com]
Sent: Thursday, February 02, 2012 1:36 PM
To: user@hive.apache.org
Subject: Re: How to check if all key/value pairs in two maps are equal?



Can you cast it into string and compare?


On Thu, Feb 2, 2012 at 9:18 AM, Sunderlin, Mark < mark.sunderlin@teamaol.com > wrote:



I am trying to see of two hive maps have the same data in them. I am not looking to see if any single key-value pair in the maps match, I am looking to see if

a) There is a one to one match between the keys in map1 and the keys in map2

b) The matching keys have the same value in both maps



This doesn’t work, but it shows what I want to do:



case

when map1 = map2

then ‘maps match'

else 'maps do not match'

end match_result









---

Mark E. Sunderlin

Solutions Architect |AOL Core Data Technologies

P: 703-256-6935 | C: 540-327-6222 | AIM: MESunderlin

22000 AOL Way, Dulles, VA 20166

aol-comp-logo










--
"...:::Aniket:::... Quetzalco@tl"

RE: How to check if all key/value pairs in two maps are equal?

Posted by "Sunderlin, Mark" <ma...@teamaol.com>.
No, can't cast a map into a string .... *sigh*

---
Mark E. Sunderlin
Solutions Architect |AOLCore Data Technologies
P: 703-256-6935 | C: 540-327-6222 | AIM: MESunderlin
22000 AOL Way | Dulles, VA | 20166

From: Aniket Mokashi [mailto:aniket486@gmail.com]
Sent: Thursday, February 02, 2012 1:36 PM
To: user@hive.apache.org
Subject: Re: How to check if all key/value pairs in two maps are equal?

Can you cast it into string and compare?
On Thu, Feb 2, 2012 at 9:18 AM, Sunderlin, Mark <ma...@teamaol.com>> wrote:
I am trying to see of two hive maps have the same data in them.  I am not looking to see if any single key-value pair in the maps match, I am looking to see if

a)    There is a one to one match between the keys in map1 and the keys in map2

b)   The matching keys  have the same value in both maps

This doesn't work, but it shows what I want to do:

case
            when map1 = map2
                        then 'maps match'
                        else 'maps do not match'
end match_result




---
Mark E. Sunderlin
Solutions Architect   |AOL Core Data Technologies
P: 703-256-6935<tel:703-256-6935>       | C: 540-327-6222<tel:540-327-6222> | AIM: MESunderlin
22000 AOL Way,  Dulles, VA  20166
[aol-comp-logo]




--
"...:::Aniket:::... Quetzalco@tl"

Re: How to check if all key/value pairs in two maps are equal?

Posted by Aniket Mokashi <an...@gmail.com>.
Can you cast it into string and compare?

On Thu, Feb 2, 2012 at 9:18 AM, Sunderlin, Mark
<ma...@teamaol.com>wrote:

>  I am trying to see of two hive maps have the same data in them.  I am
> not looking to see if any single key-value pair in the maps match, I am
> looking to see if ****
>
> **a)    **There is a one to one match between the keys in map1 and the
> keys in map2 ****
>
> **b)   **The matching keys  have the same value in both maps****
>
> ** **
>
> This doesn’t work, but it shows what I want to do:****
>
> ** **
>
> case****
>
>             when map1 = map2****
>
>                         then ‘maps match'****
>
>                         else 'maps do not match'****
>
> end match_result****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ---****
>
> *Mark E. Sunderlin***
>
> *Solutions Architect   **|AOL **Core Data Technologies*
>
> P: 703-256-6935       *|* C: 540-327-6222 *|* AIM: MESunderlin****
>
> 22000 AOL Way,  Dulles, VA  20166****
>
> [image: aol-comp-logo]****
>
> ** **
>



-- 
"...:::Aniket:::... Quetzalco@tl"