当前位置: 首页>>代码示例>>Java>>正文


Java Tuple类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:mumuhadoop,项目名称:mumu-pig,代码行数:27,代码来源:NginxLogLoader.java

示例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;
}
 
开发者ID:mumuhadoop,项目名称:mumu-pig,代码行数:18,代码来源:DateFormatEval.java

示例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);
    }
}
 
开发者ID:mumuhadoop,项目名称:mumu-pig,代码行数:17,代码来源:ISGoodQuarityFilter.java

示例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"  );
}
 
开发者ID:nielsbasjes,项目名称:yauaa,代码行数:27,代码来源:TestParseUserAgent.java

示例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 ) );
    }
}
 
开发者ID:yahoo,项目名称:FEL,代码行数:23,代码来源:NormalizeText.java

示例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);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:25,代码来源:VespaStorage.java

示例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;
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:18,代码来源:VespaSimpleJsonLoader.java

示例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;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:20,代码来源:VespaDocumentOperation.java

示例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");
}
 
开发者ID:yahoo,项目名称:validatar,代码行数:26,代码来源:StyTest.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:21,代码来源:StatementPatternStorageTest.java

示例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);
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:17,代码来源:CqlTableTest.java

示例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);
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:18,代码来源:CqlTableTest.java

示例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);
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:17,代码来源:UnionSketch.java

示例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);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:21,代码来源:ThriftColumnFamilyTest.java


注:本文中的org.apache.pig.data.Tuple类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。