當前位置: 首頁>>代碼示例>>Java>>正文


Java ThriftToPig類代碼示例

本文整理匯總了Java中com.twitter.elephantbird.pig.util.ThriftToPig的典型用法代碼示例。如果您正苦於以下問題:Java ThriftToPig類的具體用法?Java ThriftToPig怎麽用?Java ThriftToPig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ThriftToPig類屬於com.twitter.elephantbird.pig.util包,在下文中一共展示了ThriftToPig類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateSameTupleAsEB

import com.twitter.elephantbird.pig.util.ThriftToPig; //導入依賴的package包/類
/**
 * <ul> steps:
 * <li>Writes using the thrift mapping
 * <li>Reads using the pig mapping
 * <li>Use Elephant bird to convert from thrift to pig
 * <li>Check that both transformations give the same result
 * @param o the object to convert
 * @throws TException
 */
public static <T extends TBase<?,?>> void validateSameTupleAsEB(T o) throws TException {
  final ThriftSchemaConverter thriftSchemaConverter = new ThriftSchemaConverter();
  @SuppressWarnings("unchecked")
  final Class<T> class1 = (Class<T>) o.getClass();
  final MessageType schema = thriftSchemaConverter.convert(class1);

  final StructType structType = ThriftSchemaConverter.toStructType(class1);
  final ThriftToPig<T> thriftToPig = new ThriftToPig<T>(class1);
  final Schema pigSchema = thriftToPig.toSchema();
  final TupleRecordMaterializer tupleRecordConverter = new TupleRecordMaterializer(schema, pigSchema, true);
  RecordConsumer recordConsumer = new ConverterConsumer(tupleRecordConverter.getRootConverter(), schema);
  final MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
  ParquetWriteProtocol p = new ParquetWriteProtocol(new RecordConsumerLoggingWrapper(recordConsumer), columnIO, structType);
  o.write(p);
  final Tuple t = tupleRecordConverter.getCurrentRecord();
  final Tuple expected = thriftToPig.getPigTuple(o);
  assertEquals(expected.toString(), t.toString());
  final MessageType filtered = new PigSchemaConverter().filter(schema, pigSchema);
  assertEquals(schema.toString(), filtered.toString());
}
 
開發者ID:apache,項目名稱:parquet-mr,代碼行數:30,代碼來源:TestThriftToPigCompatibility.java

示例2: init

import com.twitter.elephantbird.pig.util.ThriftToPig; //導入依賴的package包/類
protected void init(Class<T> thriftClass) {
  this.thriftClass = thriftClass;
  this.thriftStruct = getThriftStruct();

  this.schema = ThriftSchemaConverter.convertWithoutProjection(thriftStruct);

  final Map<String, String> extraMetaData = new ThriftMetaData(thriftClass.getName(), thriftStruct).toExtraMetaData();
  // adding the Pig schema as it would have been mapped from thrift
  // TODO: make this work for non-tbase types
  if (isPigLoaded() && TBase.class.isAssignableFrom(thriftClass)) {
    new PigMetaData(new ThriftToPig((Class<? extends TBase<?,?>>)thriftClass).toSchema()).addToMetaData(extraMetaData);
  }

  this.writeContext = new WriteContext(schema, extraMetaData);
}
 
開發者ID:apache,項目名稱:parquet-mr,代碼行數:16,代碼來源:AbstractThriftWriteSupport.java

示例3: validatePig

import com.twitter.elephantbird.pig.util.ThriftToPig; //導入依賴的package包/類
private MessageType validatePig(String[] expectations, TBase<?, ?> a) {
  ThriftToPig<TBase<?,?>> thriftToPig = new ThriftToPig(a.getClass());
  ExpectationValidatingRecordConsumer recordConsumer = new ExpectationValidatingRecordConsumer(new ArrayDeque<String>(Arrays.asList(expectations)));
  Schema pigSchema = thriftToPig.toSchema();
  LOG.info("{}", pigSchema);
  MessageType schema = new PigSchemaConverter().convert(pigSchema);
  LOG.info("{}", schema);
  TupleWriteSupport tupleWriteSupport = new TupleWriteSupport(pigSchema);
  tupleWriteSupport.init(null);
  tupleWriteSupport.prepareForWrite(recordConsumer);
  final Tuple pigTuple = thriftToPig.getPigTuple(a);
  LOG.info("{}", pigTuple);
  tupleWriteSupport.write(pigTuple);
  return schema;
}
 
開發者ID:apache,項目名稱:parquet-mr,代碼行數:16,代碼來源:TestParquetWriteProtocol.java


注:本文中的com.twitter.elephantbird.pig.util.ThriftToPig類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。