本文整理匯總了Java中org.apache.pig.data.Tuple類的典型用法代碼示例。如果您正苦於以下問題:Java Tuple類的具體用法?Java Tuple怎麽用?Java Tuple使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Tuple類屬於org.apache.pig.data包,在下文中一共展示了Tuple類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNext
import org.apache.pig.data.Tuple; //導入依賴的package包/類
@Override
public Tuple getNext() throws IOException {
try {
boolean flag = recordReader.nextKeyValue();
if (!flag) {
return null;
}
Text value = (Text) recordReader.getCurrentValue();
Map<String, Object> stringObjectMap = NginxAccessLogParser.parseLine(value.toString());
List propertiyList = new ArrayList<String>();
propertiyList.add(0, stringObjectMap.get("remoteAddr"));
propertiyList.add(1, DateFormatUtils.format((Date) stringObjectMap.get("accessTime"), "yyyy-MM-dd HH:mm:ss"));
propertiyList.add(2, stringObjectMap.get("method"));
propertiyList.add(3, stringObjectMap.get("url"));
propertiyList.add(4, stringObjectMap.get("protocol"));
propertiyList.add(5, stringObjectMap.get("agent"));
propertiyList.add(6, stringObjectMap.get("refer"));
propertiyList.add(7, stringObjectMap.get("status"));
propertiyList.add(8, stringObjectMap.get("length"));
return TupleFactory.getInstance().newTuple(propertiyList);
} catch (InterruptedException e) {
throw new ExecException("Read data error", PigException.REMOTE_ENVIRONMENT, e);
}
}
示例2: 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;
}
示例3: 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);
}
}
示例4: testParseUserAgentPigUDF_NULL
import org.apache.pig.data.Tuple; //導入依賴的package包/類
@Test
public void testParseUserAgentPigUDF_NULL() throws Exception {
TupleFactory tupleFactory = TupleFactory.getInstance();
Tuple nullInput = tupleFactory.newTuple();
nullInput.append(null);
ParseUserAgent udf = new ParseUserAgent();
Tuple data = udf.exec(nullInput);
Schema schema = udf.outputSchema(null).getField(0).schema;
System.out.println(schema.toString());
checkResult(data, schema, "DeviceClass", "Hacker" );
checkResult(data, schema, "DeviceName", "Hacker" );
checkResult(data, schema, "OperatingSystemClass", "Hacker" );
checkResult(data, schema, "OperatingSystemName", "Hacker" );
checkResult(data, schema, "OperatingSystemVersion", "Hacker" );
checkResult(data, schema, "LayoutEngineClass", "Hacker" );
checkResult(data, schema, "LayoutEngineName", "Hacker" );
checkResult(data, schema, "LayoutEngineVersion", "Hacker" );
checkResult(data, schema, "AgentClass", "Hacker" );
checkResult(data, schema, "AgentName", "Hacker" );
checkResult(data, schema, "AgentVersion", "Hacker" );
checkResult(data, schema, "HackerAttackVector", "Unknown" );
checkResult(data, schema, "HackerToolkit", "Unknown" );
}
示例5: 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 ) );
}
}
示例6: putNext
import org.apache.pig.data.Tuple; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void putNext(Tuple tuple) throws IOException {
if (tuple == null || tuple.size() == 0) {
return;
}
String data = null;
if (createDocOp) {
data = createDocumentOperation(tuple);
} else if (!tuple.isNull(0)) {
data = tuple.get(0).toString(); // assume single field with correctly formatted doc op.
}
if (data == null || data.length() == 0) {
return;
}
try {
recordWriter.write(0, data);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
示例7: getNext
import org.apache.pig.data.Tuple; //導入依賴的package包/類
@Override
public Tuple getNext() throws IOException {
try {
boolean done = recordReader.nextKeyValue();
if (done) {
return null;
}
Text json = recordReader.getCurrentKey();
if (json == null) {
return null;
}
return tupleFactory.newTuple(json.toString());
} catch (InterruptedException ex) {
return null;
}
}
示例8: shouldWriteTupleStart
import org.apache.pig.data.Tuple; //導入依賴的package包/類
private static boolean shouldWriteTupleStart(Tuple tuple, String name, Properties properties) {
if (tuple.size() > 1 || properties == null) {
return true;
}
String simpleArrayFields = properties.getProperty(SIMPLE_ARRAY_FIELDS);
if (simpleArrayFields == null) {
return true;
}
if (simpleArrayFields.equals("*")) {
return false;
}
String[] fields = simpleArrayFields.split(",");
for (String field : fields) {
if (field.trim().equalsIgnoreCase(name)) {
return false;
}
}
return true;
}
示例9: testStringTypeInTuple
import org.apache.pig.data.Tuple; //導入依賴的package包/類
@Test
public void testStringTypeInTuple() throws IOException {
Query query = new Query();
query.value = "";
Schema fakeSchema = getSchema(makeFieldSchema("a", DataType.BYTE),
makeFieldSchema("b", DataType.BYTEARRAY),
makeFieldSchema("c", DataType.CHARARRAY));
Tuple fakeTuple = makeTuple(Byte.valueOf("1"), new DataByteArray("foo".getBytes()), "bar");
sty = getSty(withMockResult(withMockSchema(getServer(), fakeSchema), fakeTuple));
runWithoutOutput(() -> sty.execute(query));
Assert.assertFalse(query.failed());
List<TypedObject> columnOne = query.getResult().getColumn("a").getValues();
List<TypedObject> columnTwo = query.getResult().getColumn("b").getValues();
List<TypedObject> columnThree = query.getResult().getColumn("c").getValues();
Assert.assertNotNull(columnOne);
Assert.assertEquals(columnOne.size(), 1);
Assert.assertEquals(columnOne.get(0).data, "1");
Assert.assertNotNull(columnTwo);
Assert.assertEquals(columnTwo.size(), 1);
Assert.assertEquals(columnTwo.get(0).data, "foo");
Assert.assertNotNull(columnThree);
Assert.assertEquals(columnThree.size(), 1);
Assert.assertEquals(columnThree.get(0).data, "bar");
}
示例10: nonEmptyInputSketchEstimationMode
import org.apache.pig.data.Tuple; //導入依賴的package包/類
@Test
public void nonEmptyInputSketchEstimationMode() throws Exception {
EvalFunc<Tuple> func = new ArrayOfDoublesSketchToEstimateAndErrorBounds();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
int numKeys = 10000; // to saturate the sketch with default number of nominal entries (4K)
for (int i = 0; i < numKeys; i++ ) {
sketch.update(i, new double[] {0});
}
Tuple resultTuple = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.compact().toByteArray())));
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 3);
double estimate = (double) resultTuple.get(0);
double lowerBound = (double) resultTuple.get(1);
double upperBound = (double) resultTuple.get(2);
Assert.assertEquals(estimate, numKeys, numKeys * 0.04);
Assert.assertEquals(lowerBound, numKeys, numKeys * 0.04);
Assert.assertEquals(upperBound, numKeys, numKeys * 0.04);
Assert.assertTrue(lowerBound < estimate);
Assert.assertTrue(upperBound > estimate);
}
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:21,代碼來源:ArrayOfDoublesSketchToEstimateAndErrorBoundsTest.java
示例11: testSimplePredicateRange
import org.apache.pig.data.Tuple; //導入依賴的package包/類
public void testSimplePredicateRange() throws Exception {
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "a"),new RyaURI(namespace,"p"), new RyaType("l")));
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "b"), new RyaURI(namespace, "p"), new RyaType("l")));
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "c"), new RyaURI(namespace, "n"), new RyaType("l")));
int count = 0;
List<StatementPatternStorage> storages = createStorages("accumulo://" + tablePrefix + "?instance=" + instance + "&user=" + user + "&password=" + pwd + "&predicate=<" + namespace + "p>&mock=true");
for (StatementPatternStorage storage : storages) {
while (true) {
Tuple next = storage.getNext();
if (next == null) {
break;
}
count++;
}
}
assertEquals(2, count);
ryaDAO.destroy();
}
示例12: compactCqlTableSchemaTest
import org.apache.pig.data.Tuple; //導入依賴的package包/類
private void compactCqlTableSchemaTest(String initialQuery) throws IOException
{
pig.registerQuery(initialQuery);
Iterator<Tuple> it = pig.openIterator("rows");
if (it.hasNext()) {
Tuple t = it.next();
Assert.assertEquals(t.get(0).toString(), "key1");
Assert.assertEquals(t.get(1), 100);
Assert.assertEquals(t.get(2), 10.1f);
Assert.assertEquals(3, t.size());
}
else
{
Assert.fail("Failed to get data for query " + initialQuery);
}
}
示例13: cqlTableSchemaTest
import org.apache.pig.data.Tuple; //導入依賴的package包/類
private void cqlTableSchemaTest(String initialQuery) throws IOException
{
pig.registerQuery(initialQuery);
Iterator<Tuple> it = pig.openIterator("rows");
if (it.hasNext()) {
Tuple t = it.next();
Assert.assertEquals(t.get(0).toString(), "key1");
Assert.assertEquals(t.get(1), 111);
Assert.assertEquals(t.get(2), 100);
Assert.assertEquals(t.get(3), 10.1f);
Assert.assertEquals(4, t.size());
}
else
{
Assert.fail("Failed to get data for query " + initialQuery);
}
}
示例14: updateUnion
import org.apache.pig.data.Tuple; //導入依賴的package包/類
static void updateUnion(final DataBag bag, final Union union) throws ExecException {
// Bag is not empty. process each innerTuple in the bag
for (final Tuple innerTuple : bag) {
final Object f0 = innerTuple.get(0); // consider only field 0
if (f0 == null) {
continue;
}
final byte type = innerTuple.getType(0);
if (type == DataType.BYTEARRAY) {
final DataByteArray dba = (DataByteArray) f0;
union.update(HllSketch.wrap(Memory.wrap(dba.get())));
} else {
throw new IllegalArgumentException("Field type was not DataType.BYTEARRAY: " + type);
}
}
}
示例15: cqlStorageCounterTableTest
import org.apache.pig.data.Tuple; //導入依賴的package包/類
private void cqlStorageCounterTableTest(String initialQuery) throws IOException
{
pig.registerQuery(initialQuery);
//(chuck,fist,1)
//(chuck,kick,3)
// {key: chararray,column1: chararray,value: long}
Iterator<Tuple> it = pig.openIterator("cc_data");
int count = 0;
while (it.hasNext()) {
count ++;
Tuple t = it.next();
if ("chuck".equals(t.get(0)) && "fist".equals(t.get(1)))
Assert.assertEquals(t.get(2), 1L);
else if ("chuck".equals(t.get(0)) && "kick".equals(t.get(1)))
Assert.assertEquals(t.get(2), 3L);
}
Assert.assertEquals(count, 2);
}