title: Creating schema using pig script
body: <p>I need some guidance/help with a simple task to create a schema in Apache Pig for my data file. I have two files that would contribute to this task. First file is a data file which contains the data with no column header, and a second file contains the column header for the data file. So basically, the column_header file is the schema for the data file. How do i outline this in a pig script? Here's what i got so far.</p>
  
  <pre><code>column_header = load 'sitecatalyst/coulmn_headers.tsv' using PigStorage('\t');
  data = load 'sitecatalyst/hit_data.tsv' using PigStorage('\t') as column_header;
  schema = foreach data generate column_header;
  store schema into 'output1' using PigStorage('\t', '-schema');
  withSchema = load 'output1';
  describe withSchema;
  </code></pre>
  
  <p>This is the output for </p>
  
  <pre><code>DUMP column_header
  </code></pre>
  
  <p>(accept_language,browser,browser_height,browser_width)</p>
  
  <p>When i do,</p>
  
  <pre><code>DUMP data;
  </code></pre>
  
  <p>only the first line column of data is being output, which is wrong.</p>
  
  <p>en-US</p>
  
  <p>en-US</p>
  
  <p>en-US</p>
  
  <p>en-US</p>
  
  <p>Instead it should be,</p>
  
  <p>en-US   638 755 1600</p>
  
  <p>en-US   638 655 1342</p>
  
  <p>en-US   638 723 1612</p>
  
  <p>en-US   638 231 1234</p>
  
  <p>How can i trick Pig to use "column_header" as a string that can be use during the PigStorage AS statement on the second line of code?</p>
  
  <p>Edit:
  This code will work but instead of hard-coding my column_header i would like pig script to read it instead.</p>
  
  <pre><code>column_header = load 'sitecatalyst/coulmn_headers.tsv' using PigStorage('\t');
  data = load 'sitecatalyst/hit_data.tsv' using PigStorage('\t') as (accept_language,browser,browser_height,browser_width);
  schema = foreach data generate accept_language,browser,browser_height,browser_width;
  store schema into 'output1' using PigStorage('\t', '-schema');
  withSchema = load 'output1';
  describe withSchema;
  </code></pre>