Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.pig.impl.io;
 
 
LOAD FUNCTION FOR PIG INTERNAL USE ONLY! This load function is used for storing intermediate data between MR jobs of a pig query. The serialization format of this load function can change in newer versions of pig, so this should NOT be used to store any persistent data.
 
 public class TFileStorage extends FileInputLoadFunc implements
                 StoreFuncInterfaceLoadMetadata {
 
     private static final Log mLog = LogFactory.getLog(TFileStorage.class);
     public static final String useLog = "TFile storage in use";
 
     private TFileRecordReader recReader = null;
     private TFileRecordWriter recWriter = null;

    
Simple binary nested reader format
 
     public TFileStorage() throws IOException {
         .debug();
     }
 
     @Override
     public Tuple getNext() throws IOException {
         if (.nextKeyValue()) {
             return .getCurrentValue();
         }
         else {
             return null;
         }
     }
 
     @Override
     public void putNext(Tuple tthrows IOException {
         try {
             .write(nullt);
         }
         catch (InterruptedException e) {
             throw new IOException(e);
         }
     }
 
     public static class TFileInputFormat extends
                     PigFileInputFormat<TextTuple> {
 
         /* (non-Javadoc)
         * @see org.apache.hadoop.mapreduce.InputFormat#createRecordReader(org.apache.hadoop.mapreduce.InputSplit, org.apache.hadoop.mapreduce.TaskAttemptContext)
         */
        @Override
        public RecordReader<TextTuplecreateRecordReader(InputSplit split,
                        TaskAttemptContext contextthrows IOException,
                        InterruptedException {
            return new TFileRecordReader();
        }
    }
    @Override
    public InputFormat getInputFormat() {
        return new TFileInputFormat();
    }
    @Override
    public int hashCode() {
        return 42;
    }
    @Override
    public void prepareToRead(RecordReader readerPigSplit split) {
         = (TFileRecordReaderreader;
    }
    @Override
    public void setLocation(String locationJob jobthrows IOException {
        FileInputFormat.setInputPaths(joblocation);
    }
    public static class TFileOutputFormat
                    extends
                    FileOutputFormat<org.apache.hadoop.io.WritableComparableTuple> {
        /* (non-Javadoc)
         * @see org.apache.hadoop.mapreduce.lib.output.FileOutputFormat#getRecordWriter(org.apache.hadoop.mapreduce.TaskAttemptContext)
         */
        @Override
                        TaskAttemptContext jobthrows IOException,
                        InterruptedException {
            Configuration conf = job.getConfiguration();
            String codec = conf.get(."");
            if (!codec.equals("lzo") && !codec.equals("gz") && !codec.equals("gzip"))
                throw new IOException(
                                "Invalid temporary file compression codec [" + codec + "]. Expected compression codecs are gz(gzip) and lzo");
            if (codec.equals("gzip")) {
                codec = "gz";
            }
            .info(codec + " compression codec in use");
            Path file = getDefaultWorkFile(job"");
            return new TFileRecordWriter(filecodecconf);
        }
    }
    @Override
    public OutputFormat getOutputFormat() {
        return new TFileOutputFormat();
    }
    @Override
    public void prepareToWrite(RecordWriter writer) {
        this. = (TFileRecordWriterwriter;
    }
    @Override
    public void setStoreLocation(String locationJob jobthrows IOException {
        FileOutputFormat.setOutputPath(jobnew Path(location));
    }
    @Override
    public void checkSchema(ResourceSchema sthrows IOException {
    }
    @Override
    public String relToAbsPathForStoreLocation(String locationPath curDir)
                    throws IOException {
        return LoadFunc.getAbsolutePath(locationcurDir);
    }
    @Override
    public String[] getPartitionKeys(String locationJob job)
                    throws IOException {
        return null;
    }
    @Override
    public ResourceSchema getSchema(String locationJob job)
                    throws IOException {
        return Utils.getSchema(thislocationtruejob);
    }
    @Override
    public ResourceStatistics getStatistics(String locationJob job)
                    throws IOException {
        return null;
    }
    @Override
    public void setPartitionFilter(Expression planthrows IOException {
        throw new UnsupportedOperationException();
    }
    @Override
    public void setStoreFuncUDFContextSignature(String signature) {
    }
    @Override
    public void cleanupOnFailure(String locationJob jobthrows IOException {
        StoreFunc.cleanupOnFailureImpl(locationjob);
    }
    @Override
    public void cleanupOnSuccess(String locationJob jobthrows IOException {
        // DEFAULT: do nothing
    }
New to GrepCode? Check out our FAQ X