title: Cannot cast bytearray to chararray in pig
body: <p>I have a data as follows:</p>
  
  <pre><code>(000001, mfp=621|mdus=4.0|mduc=5.0|mas=1|mpc=4.0|mfn=1|country=ABC)
  (00002, address=1000+mity|mus=1|name=kailtig+bksyt|mas=1|mpc=4.977552|country=ABC)
  </code></pre>
  
  <p>The fields are identifier and set of attributes.</p>
  
  <p>I am trying to populate all the attributes in the data and do some operations on them. </p>
  
  <p>So, I prepared my script as follows:</p>
  
  <pre><code>A = load 'myData.txt' using PigStorage(',') as (ID, ATTRIBUTES);
  B = foreach A generate FLATTEN(STRSPLIT(ATTRIBUTES, '\\|')) ;
  C = foreach B generate FLATTEN(TOBAG(*));
  Dump C;
  
  ()
  ( mfp=621)
  (mdus=4.0)
  (mduc=5.0)
  (mas=1)
  (mpc=4.0)
  (mfn=1)
  (country=ABC))
  ( address=1000+mity)
  (mus=1)
  (name=kailtig+bksyt)
  (mpc=4.977552)
  </code></pre>
  
  <p>Upto this point, it is working all right. But, the problem starts here. </p>
  
  <p>When I try to do some operations on these attributes, for example replace 'm' by 'market'</p>
  
  <pre><code>D = foreach C generate REPLACE($0,'m','market');
  </code></pre>
  
  <p>gives me an error as follows:</p>
  
  <pre><code> Could not infer the matching function for org.apache.pig.builtin.REPLACE as 
   multiple or none of them fit. Please use an explicit cast.
  </code></pre>
  
  <p>When I try to cast the bytearray to chararray </p>
  
  <pre><code>D = foreach C generate (chararray)$0;
  </code></pre>
  
  <p>gives me error as:</p>
  
  <pre><code> ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1052:
   &lt;line 4, column 24&gt; Cannot cast bytearray to chararray
  </code></pre>
  
  <p>But, the following link <a href="http://pig.apache.org/docs/r0.11.1/basic.html#cast" rel="noreferrer">http://pig.apache.org/docs/r0.11.1/basic.html#cast</a> says that piglatin supports cast from bytearray to chararray.</p>
  
  <p>How can I solve this problem. Please help.</p>
  
  <p>Thanks.</p>