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

x33g5p2x  于2022-01-29 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(72)

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

Tuple.set介绍

[英]Set the value in a given field. This should not be called unless the tuple was constructed by TupleFactory#newTuple(int) with an argument greater than the fieldNum being passed here. This call will not automatically expand the tuple size. That is if you called TupleFactory#newTuple(int) with a 2, it is okay to call this function with a 1, but not with a 2 or greater.
[中]在给定字段中设置值。除非tuple是由TupleFactory#newTuple(int)构造的,其参数大于此处传递的fieldNum,否则不应调用该函数。此调用不会自动扩展元组大小。也就是说,如果用2调用TupleFactory#newTuple(int),可以用1调用此函数,但不能用2或更大。

代码示例

代码示例来源: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: 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: apache/phoenix

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.set(i, DataType.toDouble(object));
  break;
case DataType.FLOAT:
  tuple.set(i, DataType.toFloat(object));
  break;
case DataType.INTEGER:
  tuple.set(i, DataType.toInteger(object));
  break;
case DataType.LONG:
  tuple.set(i, DataType.toLong(object));
  break;
case DataType.BOOLEAN:
  tuple.set(i, DataType.toBoolean(object));
  break;
case DataType.DATETIME:
  if (object instanceof java.sql.Timestamp)

代码示例来源: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: apache/phoenix

private void doTest(Connection conn, UDFTestProperties props) throws Exception {
  setCurrentValue(conn, props.getCurrentValue());
  Tuple tuple = tupleFactory.newTuple(3);
  tuple.set(0, props.getNumToReserve());
  tuple.set(1, props.getSequenceName());
  tuple.set(2, zkQuorum);
  Long result = null;
  try {
    final String tenantId = conn.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB);
    ReserveNSequence udf = new ReserveNSequence(zkQuorum, tenantId);
    result = udf.exec(tuple);
    validateReservedSequence(conn, props.getCurrentValue(), props.getNumToReserve(), result);
    // Calling this to cleanup for the udf. To close the connection
    udf.finish();
  } catch (Exception e) {
    if (props.isExceptionExpected()) {
      assertEquals(props.getExceptionClass(), e.getClass());
      e.getMessage().contains(props.getErrorMessage());
    } else {
      throw e;
    }
  }
}

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

private Tuple toTuple(int[] digits) throws IOException, ExecException{
  Tuple t = mTupleFactory.newTuple(numInputs);
  for (int i=0; i<numInputs; i++){
    t.set(i, digits[i]);
  }
  return t;
}

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

@Override
  protected Tuple transform(Tuple next) {
    try {
      Tuple tuple = tf.newTuple(3);
      tuple.set(0, index);
      tuple.set(1, next);
      return tuple;
    } catch (ExecException e) {
      throw new RuntimeException(e);
    }
  }
});

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

public Tuple getIntermediateTuple(TupleFactory tupleFactory)
{
 Tuple intermediateTuple = tupleFactory.newTuple(2);
 try {
  intermediateTuple.set(0, score);
  intermediateTuple.set(1, tuple);
 }
 catch (ExecException e) {
  throw new RuntimeException(e);
 }
 
 return intermediateTuple;
}

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

/**
 * @param obj
 */
public NullableBytesWritable(Object obj) {
  mValue = mTupleFactory.newTuple(1);
  try {
    ((Tuple)mValue).set(0, obj);
  } catch (ExecException e) {
    throw new RuntimeException(e);
  }
}

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

protected Tuple constructOutput(List<Result> resLst, Tuple value) throws ExecException{
  // Construct key
  Object key;
  if (resLst.size() > 1) {
    Tuple t = mTupleFactory.newTuple(resLst.size());
    int i = -1;
    for (Result res : resLst) {
      t.set(++i, res.result);
    }
    key = t;
  }
  else {
    key = resLst.get(0).result;
  }
  // Put key and value in a tuple and return
  output.set(0, key);
  output.set(1, value);
  return output;
}

代码示例来源: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: com.linkedin.datafu/datafu

public HashMap<Object, List<Tuple>> insertNullTuples(HashMap<Object, List<Tuple>> groupedData, int tupleSize) throws ExecException {
 Tuple nullTuple = TupleFactory.getInstance().newTuple(tupleSize);
 for (int i=0; i<tupleSize; i++) {
  nullTuple.set(i, null);
 }     
 for (Object key : joinData.keySet()) {
  if (!groupedData.containsKey(key)) {
   groupedData.put(key, Collections.singletonList(nullTuple));
  }
 }
 return groupedData;      
}

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

private Result getStreamCloseResult() throws ExecException {
    if (outputBag != null) {
      Tuple tup = mTupleFactory.newTuple(2);
      tup.set(0, prevKey);
      tup.set(1, outputBag);
      outputBag = null;
      return new Result(POStatus.STATUS_OK, tup);
    }

    return new Result(POStatus.STATUS_EOP, null);
  }
}

代码示例来源:origin: org.apache.hive.hcatalog/hive-hcatalog-pig-adapter

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: com.github.hyukjinkwon.hcatalog/hive-hcatalog-pig-adapter

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

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: 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: 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: 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;
}

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

public static Tuple bytesToTuple(DataInput in) throws IOException {
  // Don't use Tuple.readFields, because it requires you to
  // create a tuple with no size and then append fields.
  // That's less efficient than allocating the tuple size up
  // front and then filling in the spaces.
  // Read the size.
  int sz = in.readInt();
  // if sz == 0, we construct an "empty" tuple -
  // presumably the writer wrote an empty tuple!
  if (sz < 0) {
    throw new IOException("Invalid size " + sz + " for a tuple");
  }
  Tuple t = mTupleFactory.newTuple(sz);
  for (int i = 0; i < sz; i++) {
    t.set(i, readDatum(in));
  }
  return t;
}

相关文章