本文整理了Java中org.apache.pig.data.Tuple.size()
方法的一些代码示例,展示了Tuple.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.size()
方法的具体详情如下:
包路径:org.apache.pig.data.Tuple
类名称:Tuple
方法名:size
[英]Find the size of the tuple. Used to be called arity().
[中]找到元组的大小。以前被称为arity()。
代码示例来源: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: 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: 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: 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: 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: org.apache.pig/pig
/**
* @param value
* @return
* @throws ExecException
*/
protected float[] getProbVec(Tuple values) throws ExecException {
float[] probVec = new float[values.size()];
for(int i = 0; i < values.size(); i++) {
probVec[i] = (Float)values.get(i);
}
return probVec;
}
代码示例来源: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());
代码示例来源:origin: org.apache.pig/pig
protected long getMemorySize(Tuple t) {
int s = t.size();
try {
return (Long) t.get(s - 2);
} catch (ExecException e) {
throw new RuntimeException(
"Unable to retrive the size field from tuple.", e);
}
}
}
代码示例来源:origin: org.apache.pig/pig
@Override
public BigInteger exec(Tuple input) throws IOException {
if (input == null || input.size() == 0 || input.get(0) == null)
return null;
return ((BigInteger)input.get(0)).abs();
}
代码示例来源:origin: org.apache.pig/pig
@Override
public Long exec(Tuple input) throws IOException
{
if (input == null || input.size() < 1 || input.get(0) == null) {
return null;
}
DateTime result = (DateTime) input.get(0);
return result.getMillis();
}
代码示例来源:origin: org.apache.pig/pig
@Override
public Integer exec(Tuple input) throws IOException {
if (input == null || input.size() < 1 || input.get(0) == null) {
return null;
}
return ((DateTime) input.get(0)).getMonthOfYear();
}
代码示例来源:origin: mozilla-metrics/akela
@SuppressWarnings("rawtypes")
@Override
public Boolean exec(Tuple input) throws IOException {
if (input == null || input.size() < 2) {
return false;
}
Map m = (Map)input.get(0);
Object k = input.get(1);
return m.containsKey(k);
}
代码示例来源:origin: mozilla-metrics/akela
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0) {
return null;
}
Matcher m = p.matcher((String)input.get(0));
return m.replaceAll("chrome%3A%2F%2Fglobal%2Flocale%2Fintl.properties");
}
}
代码示例来源: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: mozilla-metrics/akela
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0 || input.get(0) == null) {
return null;
}
Matcher m = p.matcher((String)input.get(0));
return m.find() ? m.group() : null;
}
}
代码示例来源: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;
}
代码示例来源:origin: org.apache.pig/pig
static protected long count(Tuple input) throws ExecException {
DataBag values = (DataBag)input.get(0);
Iterator it = values.iterator();
long cnt = 0;
while (it.hasNext()){
Tuple t = (Tuple)it.next();
if (t != null && t.size() > 0 && t.get(0) != null)
cnt++;
}
return cnt;
}
代码示例来源:origin: org.apache.pig/pig
@Override
public Integer exec(Tuple input) throws IOException {
if (input == null || input.size() < 1 || input.get(0) == null) {
return null;
}
return ((DateTime) input.get(0)).getMillisOfSecond();
}
内容来源于网络,如有侵权,请联系作者删除!