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


Java Tuple类代码示例

本文整理汇总了Java中com.ibm.streams.operator.Tuple的典型用法代码示例。如果您正苦于以下问题:Java Tuple类的具体用法?Java Tuple怎么用?Java Tuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Tuple类属于com.ibm.streams.operator包,在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toStringStream

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
/**
 * Convert an {@link SPLStream} to a TStream<String>
 * by taking its first attribute.
 * The returned stream will contain a {@code String} tuple for
 * each tuple {@code T} on {@code stream}, the value of the
 * {@code String} tuple is {@code T.getString(0)}.
 * A runtime error will occur if the first attribute (index 0)
 * can not be converted using {@code Tuple.getString(0)}.
 * @param stream Stream to be converted to a TStream<String>.
 * @return Stream that will contain the first attribute of tuples from {@code stream}
 */
public static TStream<String> toStringStream(SPLStream stream) {

    return stream.convert(new Function<Tuple, String>() {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public String apply(Tuple tuple) {
            return tuple.getString(0);
        }
    });
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:27,代码来源:SPLStreams.java

示例2: testSPLContentsBad

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Test
public void testSPLContentsBad() throws Exception {
    final Topology topology = new Topology();
    TStream<String> source = topology.strings("A", "B", "C", "D");
    StreamSchema schema = SPLSchemas.STRING.extend("int32", "id");
    SPLStream tested = SPLStreams.convertStream(source, (s,t) -> {t.setString(0, s); t.setInt(1, s.charAt(0)); return t;}, schema);
    
    
    ExpectedTuples expected = new ExpectedTuples(schema);
    int id = "A".charAt(0);
    expected.addAsTuple(new RString("A"), id);
    expected.addAsTuple(new RString("B"), ++id);
    expected.addAsTuple(new RString("C"), 1241241);
    expected.addAsTuple(new RString("D"), ++id);

    Condition<List<Tuple>> contents = expected.contents(tested);

    boolean passed = complete(topology.getTester(), contents, 10, TimeUnit.SECONDS);
    assertFalse(passed);

    assertFalse(contents.toString(), contents.valid());
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:23,代码来源:ConditionTest.java

示例3: setupHandlersFromConditions

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
private static void setupHandlersFromConditions(
        Map<TStream<?>, Set<StreamHandler<Tuple>>> handlers,
        Map<TStream<?>, Set<UserCondition<?>>> conditions) {
    
    for (TStream<?> stream : conditions.keySet()) {
        Set<UserCondition<?>> streamConditions = conditions.get(stream);
        
        Set<StreamHandler<Tuple>> streamHandlers = handlers.get(stream);
        if (streamHandlers == null)
            handlers.put(stream, streamHandlers = new HashSet<>());
        
        for (UserCondition<?> userCondition : streamConditions) {
            streamHandlers.add(createHandler(userCondition));
        }
    }
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:17,代码来源:HandlerTesterRuntime.java

示例4: createHandler

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static StreamHandler<Tuple> createHandler(UserCondition<?> userCondition) {
    
    HandlerCondition<?,?,?> handlerCondition = null;
    
    if (userCondition instanceof CounterUserCondition) {
        handlerCondition = new CounterHandlerCondition((CounterUserCondition) userCondition);           
    } else if (userCondition instanceof ContentsUserCondition) {
        ContentsUserCondition<?> uc = (ContentsUserCondition<?>) userCondition;
        if (uc.getTupleClass().equals(Tuple.class))
            handlerCondition = new ContentsHandlerCondition((ContentsUserCondition<Tuple>) userCondition);
        else if (uc.getTupleClass().equals(String.class))
            handlerCondition = new StringHandlerCondition((ContentsUserCondition<String>) userCondition);
    } else if (userCondition instanceof StringPredicateUserCondition) {
        handlerCondition = new StringPredicateHandlerCondition((StringPredicateUserCondition) userCondition);
    }
    
    if (handlerCondition == null)
        throw new IllegalStateException();
    
    return handlerCondition.handler;
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:23,代码来源:HandlerTesterRuntime.java

示例5: valid

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Override
public boolean valid() {
    if (failed())
        return false;
           
    List<Tuple> expected = userCondition.getExpected();
    List<Tuple> got = getResult();
    
    if (expected.equals(got))
        return true;
    
    if (checkIfFailed(got, expected))
        fail();
    
    return false;
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:17,代码来源:ContentsHandlerCondition.java

示例6: testFilter

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Test
public void testFilter() throws Exception {
    Topology topology = new Topology("testFilter");
    
    SPLStream tuples = sampleFilterStream(topology);
    
    PythonFunctionalOperatorsTest.addTestToolkit(tuples);
    SPLStream pass = SPL.invokeOperator("com.ibm.streamsx.topology.pysamples.kwargs::ContainsFilter",
    		tuples, tuples.getSchema(), Collections.singletonMap("term", "23"));

    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(pass, 2);
    
    Condition<List<Tuple>> passResult = tester.tupleContents(pass);

    this.getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
 
    assertEquals(TEST_TUPLES[1], passResult.getResult().get(0));
    assertEquals(TEST_TUPLES[3], passResult.getResult().get(1));
    assertTrue(expectedCount.valid());
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:23,代码来源:PythonFunctionalOperatorsKwargsTest.java

示例7: finalizeTester

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
/**
 * 
 * @param graphItems
 * @throws Exception
 */
public void finalizeTester(Map<TStream<?>, Set<StreamHandler<Tuple>>> handlers,
        Map<TStream<?>, Set<UserCondition<?>>> conditions)
        throws Exception {
    
    super.finalizeTester(handlers, conditions);

    addTCPServerAndSink();
    collectorGraph = OperatorGraphFactory.newGraph();
    for (TStream<?> stream : this.handlers.keySet()) {
        int testerId = connectToTesterSink(stream);
        testers.put(stream, new StreamTester(collectorGraph, testerId,
                stream));
    }       

    localCollector = new JavaOperatorTester()
            .executable(collectorGraph);
    
    setupTestHandlers();
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:25,代码来源:TCPTesterRuntime.java

示例8: initialize

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Override
public void initialize(OperatorContext context) throws Exception {
    super.initialize(context);

    setBatchSize(1);
    setPreserveOrder(true);

    InetSocketAddress addr = new InetSocketAddress(getHost(), getPort());
    clients = new TCPTestClient[context.getNumberOfStreamingInputs()];
    encoders = new BinaryEncoding[context.getNumberOfStreamingInputs()];
    for (StreamingInput<Tuple> input : context.getStreamingInputs()) {
        TCPTestClient client = new TCPTestClient(addr);
        client.connect();
        clients[input.getPortNumber()] = client;

        encoders[input.getPortNumber()] = input.getStreamSchema()
                .newNativeBinaryEncoding();
    }
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:20,代码来源:TesterSink.java

示例9: toMessageStream

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
/**
 * Convert an {@link SPLStream} with schema {@link KafkaSchemas.KAFKA}
 * to a TStream&lt;{@link Message}>.
 * The returned stream will contain a {@code Message} tuple for
 * each tuple on {@code stream}.
 * A runtime error will occur if the schema of {@code stream} doesn't
 * have the attributes defined by {@code KafkaSchemas.KAFKA}.
 * @param stream Stream to be converted to a TStream&lt;Message>.
 * @return Stream of {@code Message} tuples from {@code stream}.
 */
private static TStream<Message> toMessageStream(SPLStream stream) {
    return stream.convert(new Function<Tuple, Message>() {
        private static final long serialVersionUID = 1L;

        @Override
        public Message apply(Tuple tuple) {
            return new SimpleMessage(tuple.getString("message"),
                                fromSplValue(tuple.getString("key")),
                                tuple.getString("topic"));
        }
        
        private String fromSplValue(String s) {
            // SPL doesn't allow null value.  For our use,
            // assume an empty string meant null.
            return (s==null || s.isEmpty()) ? null : s;
        }
    });
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:29,代码来源:KafkaConsumer.java

示例10: viewerSpl

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
private String viewerSpl(TWindow<Tuple,?> window, String context, String name) {

        assert window.getStream() instanceof SPLStream;
        SPLWindow splWindow = SPLStreams.triggerCount(window, 1);


        Map<String, Object> params = new HashMap<>();
        params.put("port", port);
        params.put("context", context);
        params.put("contextResourceBase", "opt/html/" + context);

        TSink tv = SPL.invokeSink(name, "com.ibm.streamsx.inet.rest::HTTPTupleView",
                splWindow,
                params);
        if (firstInvocation == null)
            firstInvocation = tv;
        else
            firstInvocation.colocate(tv);

        // Always mapping to a single operator per window
        // so currently it's always port 0.
        return name + "/ports/input/0";
    }
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:24,代码来源:RestServer.java

示例11: testPositionalSampleSimpleFilter

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Test
public void testPositionalSampleSimpleFilter() throws Exception {
    Topology topology = new Topology("testPositionalSampleSimpleFilter");
    
    SPLStream tuples = sampleFilterStream(topology);
    
    addTestToolkit(tuples);
    SPLStream viaPython = SPL.invokeOperator(
    		"com.ibm.streamsx.topology.pysamples.positional::SimpleFilter", tuples, tuples.getSchema(), null);

    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(viaPython, 2);
    
    // first attribute is the sum of the first and second input attributes
    // others are copied across from in to out.
    Tuple r1 = TEST_SCHEMA_SF.getTuple(new Object[] {32, (short) 25, 34535L});
    Tuple r2 = TEST_SCHEMA_SF.getTuple(new Object[] {5, (short) 3, 654932L});
    Condition<List<Tuple>> viaPythonResult = tester.tupleContents(viaPython,
    		r1, r2);

    complete(tester, expectedCount, 10, TimeUnit.SECONDS);

    assertTrue(expectedCount.toString(), expectedCount.valid());
    assertTrue(viaPythonResult.toString(), viaPythonResult.valid());
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:26,代码来源:PythonFunctionalOperatorsTest.java

示例12: initialize

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Override
public void initialize(OperatorContext context) throws Exception {
    super.initialize(context);

    StreamWindow<Tuple> window = getInput(0).getStreamWindow();

    createWindowListener(window);

    if (window.isPartitioned()) {
        if (getKeyGetter() == null)
            throw new IllegalStateException("Missing keyGetter function");
        
        SPLMapping<Object> input0Mapping = getInputMapping(
                this, 0);
        Function<Object,Object> functionKeyGetter = getLogicObject(getKeyGetter());
        window.registerPartitioner(new KeyPartitioner(input0Mapping,
                functionKeyGetter));
    }
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:20,代码来源:FunctionWindow.java

示例13: testMap

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Test
public void testMap() throws Exception {
    Topology topology = new Topology("testMap");
            
    SPLStream tuples = sampleFilterStream(topology);
    
    PythonFunctionalOperatorsTest.addTestToolkit(tuples);
    SPLStream mapped = SPL.invokeOperator("Mp",
    		"com.ibm.streamsx.topology.pytest.pymap::OffByOne",
    		tuples,
    		tuples.getSchema(), null);
    
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(mapped, 3);
           
    Condition<List<Tuple>> result = tester.tupleContents(mapped, TEST_TUPLES[0], TEST_TUPLES[1], TEST_TUPLES[2]);

    getConfig().put(ContextProperties.KEEP_ARTIFACTS, true);
    complete(tester, expectedCount, 10, TimeUnit.SECONDS);
 
    assertTrue(result.getResult().toString(), result.valid());
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:23,代码来源:PythonFunctionalOperatorsKwargsTest.java

示例14: testSimple

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Test
public void testSimple() throws Exception {

    Topology topology = new Topology("testSimple");

    TStream<String> hw = topology.strings("Hello", "World!", "Test!!");
    SPLStream hws = SPLStreams.stringToSPLStream(hw);

    Tester tester = topology.getTester();
    StreamCounter<Tuple> counter = tester.splHandler(hws,
            new StreamCounter<Tuple>());
    StreamCollector<LinkedList<Tuple>, Tuple> collector = tester
            .splHandler(hws, StreamCollector.newLinkedListCollector());

    StreamsContextFactory
            .getStreamsContext(StreamsContext.Type.STANDALONE_TESTER)
            .submit(topology).get();

    assertEquals(3, counter.getTupleCount());
    assertEquals("Hello", collector.getTuples().get(0).getString(0));
    assertEquals("World!", collector.getTuples().get(1).getString(0));
    assertEquals("Test!!", collector.getTuples().get(2).getString(0));
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:24,代码来源:SimpleStandaloneTest.java

示例15: setIndexNameAttribute

import com.ibm.streams.operator.Tuple; //导入依赖的package包/类
@Parameter(
		optional=true,
		description="Specifies the attribute providing the index names."
		)
public void setIndexNameAttribute(TupleAttribute<Tuple, String> indexNameAttribute) throws IOException {
	this.indexNameAttribute = indexNameAttribute;
}
 
开发者ID:IBMStreams,项目名称:streamsx.elasticsearch,代码行数:8,代码来源:ElasticsearchRestIndex.java


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