org.apache.pig.data.TupleFactory.newTuple()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(74)

本文整理了Java中org.apache.pig.data.TupleFactory.newTuple()方法的一些代码示例,展示了TupleFactory.newTuple()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TupleFactory.newTuple()方法的具体详情如下:
包路径:org.apache.pig.data.TupleFactory
类名称:TupleFactory
方法名:newTuple

TupleFactory.newTuple介绍

[英]Create an empty tuple. This should be used as infrequently as possible, use newTuple(int) instead.
[中]创建一个空元组。这应该尽可能少地使用,而是使用newTuple(int)。

代码示例

代码示例来源:origin: apache/hive

private static Tuple transformToTuple(List<?> objList, HCatSchema hs) throws Exception {
 if (objList == null) {
  return null;
 }
 Tuple t = tupFac.newTuple(objList.size());
 List<HCatFieldSchema> subFields = hs.getFields();
 for (int i = 0; i < subFields.size(); i++) {
  t.set(i, extractPigObject(objList.get(i), subFields.get(i)));
 }
 return t;
}

代码示例来源:origin: org.apache.pig/pig

private void iterativelyRollup(List<Tuple> result, Tuple input) throws ExecException {
Tuple tempTup = tf.newTuple(input.getAll());
for (int i = input.size() - 1; i >= 0; i--) {
  tempTup.set(i, allMarker);
  result.add(tf.newTuple(tempTup.getAll()));
}
}

代码示例来源:origin: org.apache.pig/pig

private Result getOutputTuple() throws ExecException{
  workingOnNewKey = true;
  createNewBags = true;
  Tuple out = mTupleFactory.newTuple(relationCnt+1);
  out.set(0, prevTopOfHeap.get(1));
  for(int i=0; i < relationCnt; i++)
    out.set(i+1,(outBags[i]));
  return new Result(POStatus.STATUS_OK, out);        
}

代码示例来源:origin: org.apache.pig/pig

@Override
  public Tuple exec(Tuple input) throws IOException {
    // Since Initial is guaranteed to be called
    // only in the map, it will be called with an
    // input of a bag with a single tuple - the 
    // count should always be 1 if bag is non empty
    DataBag bag = (DataBag)input.get(0);
    return mTupleFactory.newTuple(bag.iterator().hasNext()? 
        Long.valueOf(1L) : Long.valueOf(0L));
  }
}

代码示例来源:origin: org.apache.pig/pig

@Override
public Tuple call(Tuple input) throws Exception {
  Tuple output = TupleFactory.getInstance()
      .newTuple(input.getAll().size() - 2);
  
  for (int i = 1; i < input.getAll().size() - 2; i ++) {
    output.set(i, input.get(i+2));
  }
  
  long offset = calculateOffset((Integer) input.get(0));
  output.set(0, offset + (Long)input.get(2));
  return output;
}

代码示例来源:origin: mozilla-metrics/akela

@Override
public Tuple exec(Tuple input) throws IOException {
  if (input == null || input.size() == 0) {
    return null;
  }
  DataBag db = (DataBag) input.get(0);
  Iterator<Tuple> iter = db.iterator();
  Tuple output = tupleFactory.newTuple();
  while (iter.hasNext()) {
    Tuple t = iter.next();
    for (Object o : t.getAll()) {
      output.append(o);
    }
  }
  return output;
}

代码示例来源:origin: pl.edu.icm.coansys/coansys-io-output

@Override
  public Tuple exec(Tuple tuple) throws IOException {
    if (tuple == null || tuple.size() != 2 || tuple.getType(1) != DataType.BYTEARRAY) {
      throw new IOException("" + this.getClass().getName() +
          " expects 2 arguments, 2nd must be a bytearray");
    }

    String rowId = (String) tuple.get(0);
    DataByteArray protoDBA = (DataByteArray) tuple.get(1);
    byte[] protoBytes = protoDBA.get();

    DocumentWrapper doc = DocumentProtos.DocumentWrapper.parseFrom(protoBytes);

    Tuple result = tupleFactory.newTuple();
    result.append(rowId);
    result.append(doc.getDocumentMetadata().getKey());
    result.append(protoDBA);

    return result;
  }
}

代码示例来源:origin: org.apache.pig/pig

@Override
  public Tuple exec(Tuple input) throws IOException {
    // the input has  a single field which is a tuple
    // representing the data we want to distinct.
    // unwrap, put in a bag and send down
    try {
      Tuple single = (Tuple)input.get(0);
      DataBag bag = single == null ? createDataBag() : new SingleTupleBag(single);
      return tupleFactory.newTuple(bag);
    } catch (ExecException e) {
      throw e;
    }
  }
}

代码示例来源:origin: org.apache.pig/pig

Tuple GetJoinInput(Tuple group, List<Integer> groupCols0, List<Integer> groupCols,
  int numFields) throws ExecException {
  Tuple t = TupleFactory.getInstance().newTuple(numFields);
  if (groupCols.size() == 1) {
    // GroupLabel would be a data atom
    t.set(groupCols.get(0), group.get(groupCols0.get(0)));
  } else {
    if (!(group instanceof Tuple))
      throw new RuntimeException("Unrecognized group label!");
    for (int i = 0; i < groupCols.size(); i++) {
      t.set(groupCols.get(i), group.get(groupCols0.get(i)));
    }
  }
  return t;
}

代码示例来源:origin: elastic/elasticsearch-hadoop

dataMap = reader.getCurrentValue();
Tuple tuple = TupleFactory.getInstance().newTuple(dataMap.size());
    tuple.set(i, result);
  Set<Entry<?, ?>> entrySet = dataMap.entrySet();
  for (Map.Entry entry : entrySet) {
    tuple.set(i++, entry.getValue());

代码示例来源:origin: org.apache.pig/pig

private void recursivelyCube(List<Tuple> result, Tuple input, int index, Tuple newt) throws ExecException {
  newt.set(index, input.get(index));
  if (index == input.size() - 1 ) {
    result.add(newt);
  } else {
    recursivelyCube(result, input, index + 1, newt);
  }
  // tf.newTuple makes a copy. tf.newTupleNoCopy doesn't.
  Tuple newnewt = tf.newTuple(newt.getAll());
  newnewt.set(index, allMarker);
  if (index == input.size() - 1) {
    result.add(newnewt);
  } else {
    recursivelyCube(result, input, index + 1, newnewt);
  }
}

代码示例来源:origin: com.linkedin.datafu/datafu

@Override
public void accumulate(Tuple arg0) throws IOException
{
 DataBag inputBag = (DataBag)arg0.get(0);
 for (Tuple t : inputBag) {
  Tuple t1 = TupleFactory.getInstance().newTuple(t.getAll());
  t1.append(i);
  outputBag.add(t1);
  if (count % 1000000 == 0) {
   outputBag.spill();
   count = 0;
  }
  i++;
  count++;
 }
}

代码示例来源:origin: org.apache.pig/pig

@Override
  public Tuple exec(Tuple input) throws IOException {
    // Since Initial is guaranteed to be called
    // only in the map, it will be called with an
    // input of a bag with a single tuple - the 
    // count should always be 1 if bag is non empty
    DataBag bag = (DataBag)input.get(0);
    Iterator it = bag.iterator();
    if (it.hasNext()){
      Tuple t = (Tuple)it.next();
      if (t != null && t.size() > 0 && t.get(0) != null)
        return mTupleFactory.newTuple(Long.valueOf(1));
    }
    return mTupleFactory.newTuple(Long.valueOf(0));
  }
}

代码示例来源:origin: org.apache.pig/pig

Tuple GetJoinInput(Tuple group, List<Integer> groupCols,
  int numFields) throws ExecException {
  Tuple t = TupleFactory.getInstance().newTuple(numFields);
  if (groupCols.size() == 1) {
    // GroupLabel would be a data atom
    t.set(groupCols.get(0), group);
  } else {
    if (!(group instanceof Tuple))
      throw new RuntimeException("Unrecognized group label!");
    for (int i = 0; i < groupCols.size(); i++) {
      t.set(groupCols.get(i), group.get(i));
    }
  }
  return t;
}

代码示例来源:origin: apache/phoenix

|| projectedColumns.length != columnValues.size()) { return null; }
int numColumns = columnValues.size();
Tuple tuple = TUPLE_FACTORY.newTuple(numColumns);
try {
  int i = 0;
    Object object = entry.getValue();
    if (object == null) {
      tuple.set(i++, null);
      continue;
    case DataType.BYTEARRAY:
      byte[] bytes = PDataType.fromTypeId(PBinary.INSTANCE.getSqlType()).toBytes(object);
      tuple.set(i, new DataByteArray(bytes, 0, bytes.length));
      break;
    case DataType.CHARARRAY:
      tuple.set(i, DataType.toString(object));
      break;
    case DataType.DOUBLE:
      Tuple t = TUPLE_FACTORY.newTuple(array.getDimensions());;
      for(int j = 0 ; j < array.getDimensions() ; j++) {
        t.set(j,array.getElement(j));

代码示例来源:origin: pl.edu.icm.coansys/document-similarity-logic

@Override
  public Tuple exec(Tuple input) throws ExecException{
      String title = (String) input.get(0);
      DataBag kwds = (DataBag) input.get(1);
      
      List<String> l = new ArrayList<String>();
      for(Tuple kwd : kwds){
        l.add((String) kwd.get(0));
      }
      Collections.sort(l);
      
      Tuple t = TupleFactory.getInstance().newTuple();
      t.append(title + " " + Joiner.on(" ").join(l));
      
      return t;
  }
}

代码示例来源:origin: org.apache.pig/pig

Tuple GetGroupByInput(Object groupLabel, List<Integer> groupCols,
    int numFields) throws ExecException {
  Tuple t = TupleFactory.getInstance().newTuple(numFields);
  if (groupCols.size() == 1) {
    // GroupLabel would be a data atom
    t.set(groupCols.get(0), groupLabel);
  } else {
    if (!(groupLabel instanceof Tuple))
      throw new RuntimeException("Unrecognized group label!");
    Tuple group = (Tuple) groupLabel;
    for (int i = 0; i < groupCols.size(); i++) {
      t.set(groupCols.get(i), group.get(i));
    }
  }
  return t;
}

代码示例来源:origin: apache/phoenix

/**
 * Test Use the udf to reserve multiple tuples
 * 
 * @throws Exception
 */
@Test
public void testMultipleTuples() throws Exception {
  Tuple tuple = tupleFactory.newTuple(2);
  tuple.set(0, 2L);
  tuple.set(1, SEQUENCE_NAME);
  final String tentantId = conn.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB);
  ReserveNSequence udf = new ReserveNSequence(zkQuorum, tentantId);
  for (int i = 0; i < 2; i++) {
    udf.exec(tuple);
  }
  long nextValue = getNextSequenceValue(conn);
  assertEquals(5L, nextValue);
}

代码示例来源:origin: pl.edu.icm.coansys/coansys-io-output

@Override
  public Tuple exec(Tuple tuple) throws IOException {
    if (tuple == null) {
      throw new IOException("" + this.getClass().getName() +": null tuple has been passed to UDF!");
    }
    
    Tuple ret = tupleFactory.newTuple();
    for(int i=1;i<(tuple.size()-1);i++){
      ret.append(tuple.get(i));
    }
    ret.append(tuple.get(0));
    return ret;
  }
}

代码示例来源:origin: lucidworks/solr-scale-tk

public DataBag exec(Tuple input) throws IOException {
  DataBag outputBag = bagFactory.newDefaultBag();        
  String idBase = (String)input.get(0);        
  for (int k=0; k < numKeys; k++) {
   String key = idBase+k;
   int key_bucket = random.nextInt(maxRandom);
   Tuple next = tupleFactory.newTuple(2);
   next.set(0, key);
   next.set(1, key_bucket);
   outputBag.add(next);
  }
  return outputBag;
}

相关文章

微信公众号

最新文章

更多