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

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

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

Tuple.get介绍

[英]Get the value in a given field.
[中]获取给定字段中的值。

代码示例

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

@Override
public void putNext(Tuple tuple) throws IOException {
 List<Object> outgoing = new ArrayList<Object>(tuple.size());
 int i = 0;
 for (HCatFieldSchema fSchema : computedSchema.getFields()) {
  outgoing.add(getJavaObj(tuple.get(i++), fSchema));
 }
 try {
  writer.write(null, new DefaultHCatRecord(outgoing));
 } catch (InterruptedException e) {
  throw new BackendException("Error while writing tuple: " + tuple, PigHCatUtil.PIG_EXCEPTION_CODE, e);
 }
}

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

private Object extractKeysFromIdxTuple(Tuple idxTuple) throws ExecException{
  int idxTupSize = idxTuple.size();
  if(idxTupSize == 3)
    return idxTuple.get(0);
  int numColsInKey = (idxTupSize - 2);
  List<Object> list = new ArrayList<Object>(numColsInKey);
  for(int i=0; i < numColsInKey; i++)
    list.add(idxTuple.get(i));
  return mTupleFactory.newTupleNoCopy(list);
}

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

private Tuple createTuple(Tuple[] data) throws ExecException {
  Tuple out = TupleFactory.getInstance().newTuple();
  for (int i = 0; i < data.length; ++i) {
    Tuple t = data[i];
    int size = t.size();
    for (int j = 0; j < size; ++j) {
      out.append(t.get(j));
    }
  }
  return illustratorMarkup(out, out, 0);
}

代码示例来源:origin: larsgeorge/hbase-book

@Override
public Map<String, String> exec(Tuple input) throws IOException {
 try {
  if (input == null || input.size() < 1) {
   throw new IOException("Not enough arguments to " +
    this.getClass().getName() + ": got " + input.size() +
    ", expected at least 1");
  }
  if (input.get(0) == null) {
   return null;
  }
  String jsonLiteral = (String) input.get(0);
  return parseStringToMap(jsonLiteral);
 } catch (ExecException e) {
  LOG.warn("Error in " + getClass() + " with input " + input, e);
  throw new IOException(e);
 }
}

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

ExampleTuple GenerateMatchingTuple(Tuple constraint, LogicalExpressionPlan predicate,
    boolean invert) throws ExecException, FrontendException {
  Tuple t = TupleFactory.getInstance().newTuple(constraint.size());
  ExampleTuple tOut = new ExampleTuple(t);
  for (int i = 0; i < t.size(); i++)
    tOut.set(i, constraint.get(i));
  GenerateMatchingTupleHelper(tOut, predicate
      .getSources().get(0), invert);
  tOut.synthetic = true;
  return tOut;
}

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

/**
 * Reserve N next sequences for a sequence name. N is the first field in the tuple. Sequence name is the second
 * field in the tuple zkquorum is the third field in the tuple
 */
@Override
public Long exec(Tuple input) throws IOException {
  Preconditions.checkArgument(input != null && input.size() >= 2, INVALID_TUPLE_MESSAGE);
  Long numToReserve = (Long)(input.get(0));
  Preconditions.checkArgument(numToReserve > 0, INVALID_NUMBER_MESSAGE);
  String sequenceName = (String)input.get(1);
  Preconditions.checkNotNull(sequenceName, EMPTY_SEQUENCE_NAME_MESSAGE);
  // It will create a connection when called for the first Tuple per task.
  // The connection gets cleaned up in finish() method
  if (connection == null) {
    initConnection();
  }
  ResultSet rs = null;
  try {
    String sql = getNextNSequenceSelectStatement(Long.valueOf(numToReserve), sequenceName);
    rs = connection.createStatement().executeQuery(sql);
    Preconditions.checkArgument(rs.next());
    Long startIndex = rs.getLong(1);
    rs.close();
    connection.commit();
    return startIndex;
  } catch (SQLException e) {
    throw new IOException("Caught exception while processing row." + e.getMessage(), e);
  }
}

代码示例来源:origin: pl.edu.icm.coansys/commons

@Override
public Tuple exec(Tuple input) throws IOException {
  Tuple t = TupleFactory.getInstance().newTuple();
  t.append(((DataByteArray) input.get(0)).toString());
  return t;
}

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

@Override
public void putNext(Tuple t) throws IOException {
  ResourceFieldSchema[] fieldSchemas = (schema == null) ? null : schema.getFields();      
  
  PhoenixRecord record = new PhoenixRecord(fieldSchemas);
  
  for(int i=0; i<t.size(); i++) {
    record.add(t.get(i));
  }
  
  try {
    writer.write(null, record);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  
}

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

@Override
public Tuple exec(Tuple input) throws IOException {
  DataByteArray dba = (DataByteArray) input.get(0);
  DocumentMetadata metadata = DocumentWrapper.parseFrom(dba.get())
      .getDocumentMetadata();
  Tuple output = TupleFactory.getInstance().newTuple(
      fieldNumberMap.size());
  output = addDocumentMetatdataFields(metadata, output);
  return output;
}

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

@Override
public void putNext(Tuple t) throws IOException {
  ResourceFieldSchema[] fieldSchemas = (schema == null) ? null : schema.getFields();
  PhoenixRecordWritable record = new PhoenixRecordWritable(this.columnInfo);
  try {
    for(int i=0; i<t.size(); i++) {
      Object value = t.get(i);
      if(value == null) {
        record.add(null);
        continue;
      }
      ColumnInfo cinfo = this.columnInfo.get(i);
      byte type = (fieldSchemas == null) ? DataType.findType(value) : fieldSchemas[i].getType();
      PDataType pDataType = PDataType.fromTypeId(cinfo.getSqlType());
      Object v =  TypeUtil.castPigTypeToPhoenix(value, type, pDataType);
      record.add(v);
    }
    this.writer.write(null, record);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new RuntimeException(e);
  } catch (SQLException e) {
    LOG.error("Error on tuple {} .",t);
    throw new IOException(e);
  }
  
}

代码示例来源:origin: nielsbasjes/yauaa

@Override
public Tuple exec(Tuple tuple) throws IOException {
  initialize();
  String userAgentString = (String) tuple.get(0);
  UserAgent agent = analyzer.parse(userAgentString);
  Tuple result = TUPLE_FACTORY.newTuple();
  for (String fieldName: requestedFields) {
    result.append(agent.getValue(fieldName));
  }
  return result;
}

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

assertEquals(DataType.LONG, DataType.findType(t.get(2)));
assertEquals(DataType.TUPLE, DataType.findType(t.get(4)));
Tuple doubleArrayTuple = (Tuple)t.get(4);
assertEquals(2,doubleArrayTuple.size());
assertEquals(DataType.BIGDECIMAL, DataType.findType(t.get(0)));
assertEquals(DataType.BIGINTEGER, DataType.findType(t.get(1)));

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

@Override
  public Tuple exec(Tuple tuple) throws IOException {
    DataByteArray dba = (DataByteArray) tuple.get(1);
    DocumentProtos.DocumentWrapper docWrapper = DocumentProtos.DocumentWrapper.parseFrom(dba.get());
    String id = docWrapper.getDocumentMetadata().getKey();
    String title = docWrapper.getDocumentMetadata().getBasicMetadata().getTitle(0).getText();
    Tuple retTuple = TupleFactory.getInstance().newTuple(Arrays.asList(id, title));
    return retTuple;
  }
}

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

@Override
public Long exec(Tuple input) throws IOException
{
  if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) {
    return null;
  }
  DateTime startDate = (DateTime) input.get(0);
  DateTime endDate = (DateTime) input.get(1);
  // Larger date first
  // Subtraction may overflow
  return (startDate.getMillis() - endDate.getMillis()) / 60000L;
}

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

@Override
public Long exec(Tuple input) throws IOException
{
  if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) {
    return null;
  }
  DateTime startDate = (DateTime) input.get(0);
  DateTime endDate = (DateTime) input.get(1);
  // Larger date first
  // Subtraction may overflow
  return startDate.getMillis() - endDate.getMillis();
}

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

@Override
public DateTime exec(Tuple input) throws IOException {
  if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) {
    return null;
  }
  
  return ((DateTime) input.get(0)).plus(new Period((String) input.get(1)));
}

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

@Override
public Long exec(Tuple input) throws IOException
{
  if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) {
    return null;
  }
  DateTime startDate = (DateTime) input.get(0);
  DateTime endDate = (DateTime) input.get(1);
  // Larger date first
  return (startDate.getMillis() - endDate.getMillis()) / 3600000L;
}

相关文章