hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Grover <mgro...@oanda.com>
Subject Re: How to check if all key/value pairs in two maps are equal?
Date Fri, 03 Feb 2012 16:43:22 GMT
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" <mark.sunderlin@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"

Mime
View raw message