/**
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed 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 parquet.cascading;

import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.RecordReader;
import org.apache.thrift.TBase;

import parquet.hadoop.ParquetInputFormat;
import parquet.hadoop.mapred.DeprecatedParquetInputFormat;
import parquet.hadoop.mapred.DeprecatedParquetOutputFormat;
import parquet.hadoop.thrift.ThriftReadSupport;
import parquet.hadoop.thrift.ThriftWriteSupport;
import parquet.thrift.TBaseRecordConverter;
import cascading.flow.FlowProcess;
import cascading.tap.Tap;

public class ParquetTBaseScheme<T extends TBase<?,?>> extends ParquetValueScheme<T> {

  private final Class<T> thriftClass;

  public ParquetTBaseScheme(Class<T> thriftClass) {
    this.thriftClass = thriftClass;
  }

  @SuppressWarnings("rawtypes")
  @Override
  public void sourceConfInit(FlowProcess<JobConf> fp,
      Tap<JobConf, RecordReader, OutputCollector> tap, JobConf jobConf) {
    jobConf.setInputFormat(DeprecatedParquetInputFormat.class);
    ParquetInputFormat.setReadSupportClass(jobConf, ThriftReadSupport.class);
    ThriftReadSupport.setRecordConverterClass(jobConf, TBaseRecordConverter.class);
  }

  @SuppressWarnings("rawtypes")
  @Override
  public void sinkConfInit(FlowProcess<JobConf> fp,
      Tap<JobConf, RecordReader, OutputCollector> tap, JobConf jobConf) {
    jobConf.setOutputFormat(DeprecatedParquetOutputFormat.class);
    DeprecatedParquetOutputFormat.setWriteSupportClass(jobConf, ThriftWriteSupport.class);
    ThriftWriteSupport.<T>setThriftClass(jobConf, thriftClass);
  }
}

@@ -937,32 +937,87 @@
 etOutputFormat;%0A
+import parquet.hadoop.thrift.ParquetThriftInputFormat;%0A
 import parquet.h
@@ -1304,14 +1304,8 @@
 ate 
-final 
 Clas
@@ -1323,16 +1323,132 @@
 Class;%0A%0A
+  // In the case of reads, we can read the thrift class from the file metadata%0A  public ParquetTBaseScheme() %7B%0A  %7D%0A%0A
   public
@@ -1925,24 +1925,131 @@
 rter.class);
+%0A%0A    if (thriftClass != null) %7B%0A      ParquetThriftInputFormat.setThriftClass(jobConf, thriftClass);%0A    %7D
 %0A  %7D%0A%0A  @Sup
@@ -2204,32 +2204,204 @@
 Conf jobConf) %7B%0A
+%0A    if (thriftClass == null) %7B%0A      throw new IllegalArgumentException(%22To use ParquetTBaseScheme as a sink, you must specify a thrift class in the constructor%22);%0A    %7D%0A%0A
     jobConf.setO

add an empty constructor for ParquetTBaseScheme (which only works for reads)