当前位置: 首页>>代码示例>>Java>>正文


Java Tuple.set方法代码示例

本文整理汇总了Java中org.apache.pig.data.Tuple.set方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.set方法的具体用法?Java Tuple.set怎么用?Java Tuple.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.pig.data.Tuple的用法示例。


在下文中一共展示了Tuple.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public DataBag exec(final Tuple input) throws IOException {
  if ((input == null) || (input.size() == 0)) {
    return null;
  }

  final DataByteArray dba = (DataByteArray) input.get(0);
  final ItemsSketch<String> sketch =
      ItemsSketch.getInstance(Memory.wrap(dba.get()), new ArrayOfStringsSerDe());
  final ItemsSketch.Row<String>[] result = sketch.getFrequentItems(errorType);

  final DataBag bag = BagFactory.getInstance().newDefaultBag();
  for (int i = 0; i < result.length; i++) {
    final Tuple tuple = TupleFactory.getInstance().newTuple(4);
    tuple.set(0, result[i].getItem());
    tuple.set(1, result[i].getEstimate());
    tuple.set(2, result[i].getLowerBound());
    tuple.set(3, result[i].getUpperBound());
    bag.add(tuple);
  }
  return bag;
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:23,代码来源:FrequentStringsSketchToEstimates.java

示例2: degenerateExecInput

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void degenerateExecInput() {
  final ReservoirSampling rs = new ReservoirSampling("256");

  // all these tests should do nothing
  try {
    rs.exec(null);

    Tuple input = TupleFactory.getInstance().newTuple(0);
    rs.exec(input);

    input = TupleFactory.getInstance().newTuple(1);
    input.set(0, null);
    rs.exec(input);
  } catch (final IOException e) {
    fail("Unexpected IOException: " + e.getMessage());
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:19,代码来源:ReservoirSamplingTest.java

示例3: checkNotDBAExcep

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void checkNotDBAExcep() throws IOException {
  DataToSketch inter = new DataToSketch();
  //create inputTuple and a bag, add bag to inputTuple
  Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  inputTuple.set(0, bag);
  
  Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
  bag.add(innerTuple);
  inter.accumulate(inputTuple); //add empty tuple
  
  innerTuple.set(0, new Double(1.0));  //not a DBA
  inter = new DataToSketch();
  inter.accumulate(inputTuple); //add wrong type
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:17,代码来源:DataToSketchTest.java

示例4: algebraicInitialOneParam

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void algebraicInitialOneParam() throws Exception {
  EvalFunc<Tuple> func = new DataToDoubleSummarySketch.Initial(null);
  Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  bag.add(PigUtil.objectsToTuple(null, null));
  bag.add(PigUtil.objectsToTuple(null, null));
  bag.add(PigUtil.objectsToTuple(null, null));
  inputTuple.set(0, bag);

  Tuple resultTuple = func.exec(inputTuple);
  Assert.assertNotNull(resultTuple);
  Assert.assertEquals(resultTuple.size(), 1);
  DataBag resultBag = (DataBag) resultTuple.get(0);
  Assert.assertEquals(resultBag.size(), 3);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:17,代码来源:DataToDoubleSummarySketchTest.java

示例5: testFiveArg

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void testFiveArg() throws Exception {
  EpochToCalendar test = new EpochToCalendar();
  TupleFactory Maker = TupleFactory.getInstance();

  String[] strArray = new String[] { "EPOCH", "YEAR", "MINUTE", "DATE", "MONTH", "HOUR" };
  List strList = Arrays.asList(strArray);
  Tuple test1a = Maker.newTuple(strList);
  test1a.set(0, 684175980000L);
  assertEquals(test1a.toString(), "(684175980000,YEAR,MINUTE,DATE,MONTH,HOUR)");
  Tuple test1 = test.exec(test1a);
  assertEquals(test1.toString(), "(1991,53,6,8,16)");

  String[] strArray2 = new String[] { "EPOCH", "HOUR", "YEAR", "MILLISECOND", "SECOND", "MINUTE" };
  List strList2 = Arrays.asList(strArray2);
  Tuple test2a = Maker.newTuple(strList2);
  test2a.set(0, 915313370015L);
  assertEquals(test2a.toString(), "(915313370015,HOUR,YEAR,MILLISECOND,SECOND,MINUTE)");
  Tuple test2 = test.exec(test2a);
  assertEquals(test2.toString(), "(21,1999,15,50,42)");
}
 
开发者ID:lucidworks,项目名称:pig-solr,代码行数:22,代码来源:EpochToCalendarTest.java

示例6: testSevenArg

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void testSevenArg() throws Exception {
  EpochToCalendar test = new EpochToCalendar();
  TupleFactory Maker = TupleFactory.getInstance();

  String[] strArray = new String[] { "EPOCH", "YEAR", "MINUTE", "DATE", "MONTH", "HOUR", "MILLISECOND", "SECOND" };
  List strList = Arrays.asList(strArray);
  Tuple test1a = Maker.newTuple(strList);
  test1a.set(0, 5838804043L);
  assertEquals(test1a.toString(), "(5838804043,YEAR,MINUTE,DATE,MONTH,HOUR,MILLISECOND,SECOND)");
  Tuple test1 = test.exec(test1a);
  assertEquals(test1.toString(), "(1970,53,9,2,13,43,24)");

  String[] strArray2 = new String[] { "EPOCH", "HOUR", "YEAR", "MILLISECOND", "SECOND", "MINUTE", "MONTH", "DATE" };
  List strList2 = Arrays.asList(strArray2);
  Tuple test2a = Maker.newTuple(strList2);
  test2a.set(0, 423618152015L);
  assertEquals(test2a.toString(), "(423618152015,HOUR,YEAR,MILLISECOND,SECOND,MINUTE,MONTH,DATE)");
  Tuple test2 = test.exec(test2a);
  assertEquals(test2.toString(), "(23,1983,15,32,42,5,4)");
}
 
开发者ID:lucidworks,项目名称:pig-solr,代码行数:22,代码来源:EpochToCalendarTest.java

示例7: algebraicInitial

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void algebraicInitial() throws Exception {
  EvalFunc<Tuple> func = new DataToArrayOfDoublesSketch.Initial(null);
  Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  bag.add(PigUtil.objectsToTuple(null, null));
  bag.add(PigUtil.objectsToTuple(null, null));
  bag.add(PigUtil.objectsToTuple(null, null));
  inputTuple.set(0, bag);

  Tuple resultTuple = func.exec(inputTuple);
  Assert.assertNotNull(resultTuple);
  Assert.assertEquals(resultTuple.size(), 1);
  DataBag resultBag = (DataBag) resultTuple.get(0);
  Assert.assertEquals(resultBag.size(), 3);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:17,代码来源:DataToArrayOfDoublesSketchTest.java

示例8: testRejectionOfNonSimpleType

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") //still triggers unchecked warning
@Test(expectedExceptions = IllegalArgumentException.class)
public void testRejectionOfNonSimpleType() throws IOException {
  TupleFactory mTupleFactory = TupleFactory.getInstance();
  BagFactory bagFactory = BagFactory.getInstance();
  
  Tuple outerTuple = mTupleFactory.newTuple(1);
  DataBag outerBag = bagFactory.newDefaultBag();
  Tuple innerTuple = mTupleFactory.newTuple(1);
  DataBag innerBag = bagFactory.newDefaultBag();
  innerTuple.set(0, innerBag);
  outerBag.add(innerTuple);
  outerTuple.set(0, outerBag);
  
  String[] ctorArgs = { "128" };
  EvalFunc<Tuple> dataUdf =
      (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(udfName, ctorArgs));
  dataUdf.exec(outerTuple);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:20,代码来源:DataToSketchTest.java

示例9: checkAlgFinalInnerBagEmpty

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test(expectedExceptions = SketchesStateException.class)
public void checkAlgFinalInnerBagEmpty() throws IOException {
  EvalFunc<Tuple> interFuncFinal = new Intersect.IntermediateFinal();
  EvalFunc<Double> estFunc = new Estimate();
  
  Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
  Tuple resultTuple = interFuncFinal.exec(inputTuple);
  assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
  
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  inputTuple.set(0, bag); //inputTuple.bag0:null
  resultTuple = interFuncFinal.exec(inputTuple);
  assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
  
  Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
  bag.add(innerTuple);
  DataBag bag2 = BagFactory.getInstance().newDefaultBag();
  innerTuple.set(0, bag2);
  
  resultTuple = interFuncFinal.exec(inputTuple); //Throws Illegal Result from HeapIntersection
  //assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:23,代码来源:IntersectTest.java

示例10: getNext

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Tuple getNext() throws IOException {
	try {
		boolean notDone = in.nextKeyValue();
		if (!notDone) {
			return null;
		}
		Text value = (Text) in.getCurrentValue();
		// Use the Parser to parse the input line into a Triple
		String[] triple = rdfParser.parseTriple(value.toString());
		// If the parser returns null this line was not a valid RDF triple
		// We then continue with the next line
		if (triple == null) {
			mLog.warn("This is not an RDF triple -> ignored: " + value.toString());
			return getNext();
		}
		// Tuples are always triples of Subject, Predicate, Object
		Tuple t = mTupleFactory.newTuple(3);
		// set the fields of the Tuple as Subject, Predicate, Object
		t.set(0, new DataByteArray(triple[0])); // Subject
		t.set(1, new DataByteArray(triple[1])); // Predicate
		t.set(2, new DataByteArray(triple[2])); // Object
		return t;
	} catch (InterruptedException e) {
		int errCode = 6018;
		String errMsg = "Error while reading input";
		throw new ExecException(errMsg, errCode,
				PigException.REMOTE_ENVIRONMENT, e);
	}
}
 
开发者ID:aschaetzle,项目名称:PigSPARQL,代码行数:31,代码来源:NTriplesStorage.java

示例11: checkExactAccumulator

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void checkExactAccumulator() throws IOException {
  Accumulator<Tuple> interFunc = new Intersect();
  EvalFunc<Double> estFunc = new Estimate();
  
  //create inputTuple and a bag, add bag to inputTuple
  Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  inputTuple.set(0, bag);
  
  //create 4 distinct sketches of 32 in a bag
  for (int i = 0; i < 4; i++ ) {
    Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
    dataTuple.set(0, createDbaFromQssRange(256, i*64, 256));
    
    bag.add(dataTuple);
  }
  
  interFunc.accumulate(inputTuple); //A tuple, bag with 4 sketches
  
  Tuple resultTuple = interFunc.getValue();
  assertNotNull(resultTuple);
  assertEquals(resultTuple.size(), 1);
  
  DataByteArray dba = (DataByteArray) resultTuple.get(0);
  assertTrue(dba.size() > 0);
  
  Double est = estFunc.exec(resultTuple);
  assertEquals(est, 64.0, 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:31,代码来源:IntersectTest.java

示例12: transformToTuple

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
private static Tuple transformToTuple(
    List<?> objList, com.cloudera.recordservice.mr.Schema schema) throws Exception {
  if (objList == null) {
    return null;
  }
  Tuple t = tupFac.newTuple(objList.size());
  for (int i = 0; i < schema.getNumColumns(); i++) {
    t.set(i, extractPigObject(objList.get(i), schema.getColumnInfo(i).type));
  }
  return t;
}
 
开发者ID:cloudera,项目名称:RecordServiceClient,代码行数:12,代码来源:PigHCatUtil.java

示例13: checkNullEmptyAccumulator

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void checkNullEmptyAccumulator() throws IOException {
  Accumulator<Tuple> unionFunc = new Union("256");
  EvalFunc<Double> estFunc = new Estimate();
  
  Tuple inputTuple = null;
  unionFunc.accumulate(inputTuple); //does nothing, just returns
  
  inputTuple = TupleFactory.getInstance().newTuple(0); //invalid size
  unionFunc.accumulate(inputTuple); //does nothing, just returns
  
  inputTuple = TupleFactory.getInstance().newTuple(1); //valid size, but null
  unionFunc.accumulate(inputTuple); //does nothing, just returns
  
  inputTuple = TupleFactory.getInstance().newTuple(1); //valid size
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  inputTuple.set(0, bag); //correct type, but empty
  unionFunc.accumulate(inputTuple); //does nothing, just returns
  
  Tuple innerTuple = TupleFactory.getInstance().newTuple(0); //empty
  bag.add(innerTuple);
  unionFunc.accumulate(inputTuple); //does nothing, just returns
  
  inputTuple = TupleFactory.getInstance().newTuple(1); //valid size
  bag = BagFactory.getInstance().newDefaultBag();
  inputTuple.set(0, bag); //correct type
  innerTuple = TupleFactory.getInstance().newTuple(1); //correct size
  bag.add(innerTuple); //but innerTuple(0) is null
  unionFunc.accumulate(inputTuple); //ignores
  
  Tuple resultTuple = unionFunc.getValue();
  assertNotNull(resultTuple);
  assertEquals(resultTuple.size(), 1);
  
  Double est = estFunc.exec(resultTuple);
  assertEquals(est, 0.0, 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:38,代码来源:UnionTest.java

示例14: checkAlgFinalFromPriorIntermed

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void checkAlgFinalFromPriorIntermed() throws IOException {
  EvalFunc<Tuple> interFuncIFinal = new Intersect.IntermediateFinal();
  EvalFunc<Double> estFunc = new Estimate();
  
  Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  inputTuple.set(0, bag); //inputTuple.bag0:null
  
  for (int i = 0; i < 4; i++ ) {
    Tuple sketchTuple = TupleFactory.getInstance().newTuple(1);
    sketchTuple.set(0, createDbaFromQssRange(256, i*64, 256));
    
    bag.add(sketchTuple); 
    //inputTuple.bag0:sketchTuple0.DBA0
    //inputTuple.bag0:sketchTuple1.DBA1
    //inputTuple.bag0:sketchTuple2.DBA2
    //inputTuple.bag0:sketchTuple3.DBA3
  }
  
  Tuple resultTuple = interFuncIFinal.exec(inputTuple);
  
  assertNotNull(resultTuple);
  assertEquals(resultTuple.size(), 1);
  
  DataByteArray bytes = (DataByteArray) resultTuple.get(0);
  assertTrue(bytes.size() > 0);
  
  Double est = estFunc.exec(resultTuple);
  assertEquals(est, 64.0, 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:32,代码来源:IntersectTest.java

示例15: testExactNoDetailWithSeed

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void testExactNoDetailWithSeed() throws IOException {
  EvalFunc<String> func = new SketchToString("false", Long.toString(DEFAULT_UPDATE_SEED));
  
  Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
  dataTuple.set(0, createDbaFromQssRange(64, 0, 64));
  
  String result = func.exec(dataTuple);
  assertNotNull(result);
  assertTrue(result.contains("SUMMARY"));
  assertFalse(result.contains("SKETCH DATA DETAIL"));
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:13,代码来源:SketchToStringTest.java


注:本文中的org.apache.pig.data.Tuple.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。