24847

replacing values in pig latin

Question:

I have a dataset in form:

id1, id2, id3

Either of id1,id2 or id3 (or all three.. or any two) can be missing in a record.

Now if id1 is missing I want to replace it with 1

id2 by 3 id3 by 7

How do I do this. Thanks

Answer1:

Use the bincond operator to test if the value is null and then replace it with the desired value. From Programming Pig, <a href="http://ofps.oreilly.com/titles/9781449302641/intro_pig_latin.html" rel="nofollow">Chapter 5</a>:

2 == 2 ? 1 : 4 --returns 1 2 == 3 ? 1 : 4 --returns 4 null == 2 ? 1 : 4 -- returns null 2 == 2 ? 1 : 'fred' -- type error, both values must be of the same type

In your example,

id2 IS NULL ? 3 : id2

Recommend

  • Given longitude and latitude of two areas, how to find the distance between them in meters. How to q
  • How to reshape data wide to long [duplicate]
  • Oracle XMLTABLE left outer join doesn't return results when XPath doesn't exist
  • How to highlight/color multiple rows on selection?
  • Javascript onpaste event of everytext box value should be split and paste in corresponding textbox
  • How do I encode key-value pairs using Perl's XML::Simple module?
  • Use Python to manipulate txt file presentation of key-value grouping
  • Best way to create Combination of records (Order does not matter, no repetition allowed) in mySQL ta
  • Whats the best way of sending a lot of parameters between pages?
  • python id3 tag unicode
  • JQuery: how to name click functions?
  • MongoDB Count() vs. Aggregation
  • width returns 0 for IE and Chrome
  • DataFrame transformation in Spark, Java
  • multidimensional array
  • Produce a precision weighted average among rows with repeated observations
  • How to return DataSet (xsd) in WCF
  • SAXReader not re-ecape characters
  • RxJava debounce by arbitrary value
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • Marklogic : Query response time is very high
  • Why querying a date BC is changed to AD in Java?
  • Record samples being played with OpenAL
  • Checking free space on FTP server
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • JSON with duplicate key names losing information when parsed
  • How to model a transition system with SPIN
  • Jquery - Jquery Wysiwyg return html as a string
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • Python: how to group similar lists together in a list of lists?
  • json Serialization in asp
  • Proper way to use connect-multiparty with express.js?
  • How to set the response of a form post action to a iframe source?
  • Why joiner is not used after Sequence generator or Update statergy
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • File not found error Google Drive API
  • Is it possible to post an object from jquery to bottle.py?
  • Django query for large number of relationships