本文整理汇总了Java中org.apache.pig.data.Tuple.get方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.get方法的具体用法?Java Tuple.get怎么用?Java Tuple.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pig.data.Tuple
的用法示例。
在下文中一共展示了Tuple.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public String exec(final Tuple tuple) throws IOException {
if (tuple == null || tuple.size() == 0) {
return null;
}
Object dateString = tuple.get(0);
if (dateString == null) {
return null;
}
try {
Date date = DateUtils.parseDate(dateString.toString(), new String[]{"yyyy-MM-dd HH:mm:ss"});
return DateFormatUtils.format(date, formatPattern);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例2: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Boolean exec(final Tuple tuple) throws IOException {
if (tuple == null || tuple.size() == 0) {
return false;
}
try {
Object object = tuple.get(0);
if (object == null) {
return false;
}
int i = (Integer) object;
return i == 0 || i == 1 || i == 4 || i == 5 || i == 9;
} catch (ExecException e) {
throw new IOException(e);
}
}
示例3: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public String exec( Tuple input ) throws IOException {
if( input == null ) {
throw new IOException( "No arguments: Usage NormalizeText(String, ASCII)" );
}
if( input.size() != 2 ) {
throw new IOException( "Wrong arguments: Usage NormalizeText(String, ASCII)" );
}
for( int i = 0; i < input.size(); i++ ) {
if( input.get( i ) == null ) {
return null;
}
}
if( Boolean.parseBoolean( ( String ) input.get( 1 ) ) ) {
String norm = normalizeToASCII( ( String ) input.get( 0 ) );
return normalize( norm );
} else {
return normalize( ( String ) input.get( 0 ) );
}
}
示例4: execMinMode
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void execMinMode() throws Exception {
EvalFunc<Tuple> func = new DataToDoubleSummarySketch("32", "Min");
DataBag bag = BagFactory.getInstance().newDefaultBag();
bag.add(PigUtil.objectsToTuple("a", 1.0));
bag.add(PigUtil.objectsToTuple("b", 2.0));
bag.add(PigUtil.objectsToTuple("a", 2.0));
bag.add(PigUtil.objectsToTuple("b", 1.0));
Tuple inputTuple = PigUtil.objectsToTuple(bag);
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
for (DoubleSummary summary: sketch.getSummaries()) {
Assert.assertEquals(summary.getValue(), 1.0);
}
}
示例5: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@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);
}
}
示例6: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Map<String, String> exec(Tuple tuple) throws IOException {
if (tuple == null || tuple.size() == 0) {
return null;
}
Map<String, String> merged = new HashMap<String, String>();
for (int i = 0; i < tuple.size(); i++) {
if (tuple.get(i) != null) {
@SuppressWarnings("unchecked")
Map<String, String> element = (Map<String, String>) tuple.get(i);
for (Map.Entry<String, String> entry : element.entrySet()) {
if (merged.get(entry.getKey()) == null) {
merged.put(entry.getKey(), entry.getValue());
}
}
}
}
if (merged.isEmpty()) {
return null;
}
return merged;
}
示例7: accumulate
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public void accumulate(final Tuple inputTuple) throws IOException {
if (inputTuple == null || inputTuple.size() < 1 || inputTuple.isNull(0)) {
return;
}
final DataBag samples = (DataBag) inputTuple.get(0);
if (sketch_ == null) {
sketch_ = VarOptItemsSketch.newInstance(targetK_);
}
for (final Tuple t : samples) {
final double weight = (double) t.get(weightIdx_);
sketch_.update(t, weight);
}
}
示例8: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Tuple exec(Tuple tuple) throws IOException {
if (tuple == null || tuple.size() < 2) {
throw new IOException("Not enough values");
}
long epoch = (Long) tuple.get(0);
Tuple out = TupleFactory.getInstance().newTuple(tuple.size() - 1);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.setTimeInMillis(epoch);
for (int i = 1; i < tuple.size(); i++) {
String key = (String) tuple.get(i);
Integer calKey = calMap.get(key);
if (calKey == null) {
out.set(i - 1, null);
} else {
out.set(i - 1, cal.get(calKey));
}
}
return out;
}
示例9: accumulate
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public void accumulate(final Tuple inputTuple) throws IOException {
if (inputTuple == null || inputTuple.size() < 1 || inputTuple.isNull(0)) {
return;
}
final DataBag samples = (DataBag) inputTuple.get(0);
if (reservoir_ == null) {
reservoir_ = ReservoirItemsSketch.newInstance(targetK_);
}
for (Tuple t : samples) {
reservoir_.update(t);
}
}
示例10: accumulate
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public void accumulate(final Tuple inputTuple) throws IOException {
if (isFirstCall_) {
// this is to see in the log which way was used by Pig
Logger.getLogger(getClass()).info("accumulate is used");
isFirstCall_ = false;
}
if (accumSketch_ == null) {
accumSketch_ =
new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(sketchSize_)
.setSamplingProbability(samplingProbability_).setNumberOfValues(numValues_).build();
}
if (inputTuple.size() != 1) {
throw new IllegalArgumentException("Input tuple must have 1 bag");
}
final DataBag bag = (DataBag) inputTuple.get(0);
updateSketch(bag, accumSketch_, numValues_);
}
示例11: accumulate
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public void accumulate(final Tuple inputTuple) throws IOException {
if (inputTuple == null || inputTuple.size() < 1 || inputTuple.isNull(0)) {
return;
}
final DataBag sketches = (DataBag) inputTuple.get(0);
if (union_ == null) {
union_ = VarOptItemsUnion.newInstance(maxK_);
}
for (Tuple t : sketches) {
final DataByteArray dba = (DataByteArray) t.get(0);
final Memory sketch = Memory.wrap(dba.get());
union_.update(sketch, SERDE);
}
}
示例12: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@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;
}
示例13: runQueryTest
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
private void runQueryTest(String script, MockQueryHandler queryHandler, int port) throws Exception {
final String endpoint = "http://localhost:" + port;
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext("/", queryHandler);
server.start();
PigServer ps = setup(script, endpoint);
Iterator<Tuple> recommendations = ps.openIterator("recommendations");
while (recommendations.hasNext()) {
Tuple tuple = recommendations.next();
String userid = (String) tuple.get(0);
Integer rank = (Integer) tuple.get(1);
String docid = (String) tuple.get(2);
Double relevance = (Double) tuple.get(3);
String fieldId = (String) tuple.get(4);
String fieldContent = (String) tuple.get(5);
MockQueryHandler.MockQueryHit hit = queryHandler.getHit(userid, rank);
assertEquals(docid, hit.id);
assertEquals(relevance, hit.relevance, 1e-3);
assertEquals(fieldId, hit.fieldId);
assertEquals(fieldContent, hit.fieldContent);
}
if (server != null) {
server.stop(0);
}
}
示例14: algebraicIntermediateFinal
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Test
public void algebraicIntermediateFinal() throws Exception {
EvalFunc<Tuple> func = new DataToDoubleSummarySketch.IntermediateFinal("32");
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
inputTuple.set(0, bag);
// this is to simulate the output from Initial
bag.add(PigUtil.objectsToTuple(PigUtil.tuplesToBag(PigUtil.objectsToTuple("a", 1.0))));
// this is to simulate the output from a prior call of IntermediateFinal
UpdatableSketch<Double, DoubleSummary> ts = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
ts.update("b", 1.0);
ts.update("a", 2.0);
ts.update("b", 2.0);
Sketch<DoubleSummary> cs = ts.compact();
bag.add(PigUtil.objectsToTuple(new DataByteArray(cs.toByteArray())));
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
for (DoubleSummary summary: sketch.getSummaries()) {
Assert.assertEquals(summary.getValue(), 3.0);
}
}
示例15: exec
import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Integer exec(final Tuple input) throws IOException {
if (input.size() != 1) {
throw new IllegalArgumentException("HashCode function requires a String or Number parameter.");
}
final Object obj = input.get(0);
if (!(obj instanceof String) && !(obj instanceof Number)) {
throw new IllegalArgumentException("HashCode only supports Strings and Numbers. Value=" + String.valueOf(obj));
}
return obj.hashCode();
}