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


Java MessageStream.filter方法代码示例

本文整理汇总了Java中org.apache.samza.operators.MessageStream.filter方法的典型用法代码示例。如果您正苦于以下问题:Java MessageStream.filter方法的具体用法?Java MessageStream.filter怎么用?Java MessageStream.filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.samza.operators.MessageStream的用法示例。


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

示例1: testBroadcastChain

import org.apache.samza.operators.MessageStream; //导入方法依赖的package包/类
@Test
public void testBroadcastChain() {
  ApplicationRunner mockRunner = mock(ApplicationRunner.class);
  when(mockRunner.getStreamSpec(eq("input"))).thenReturn(new StreamSpec("input", "input-stream", "input-system"));
  StreamGraphImpl streamGraph = new StreamGraphImpl(mockRunner, mock(Config.class));

  MessageStream<Object> inputStream = streamGraph.getInputStream("input");
  inputStream.filter(mock(FilterFunction.class));
  inputStream.map(mock(MapFunction.class));

  TaskContextImpl mockTaskContext = mock(TaskContextImpl.class);
  when(mockTaskContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
  OperatorImplGraph opImplGraph =
      new OperatorImplGraph(streamGraph, mock(Config.class), mockTaskContext, mock(Clock.class));

  InputOperatorImpl inputOpImpl = opImplGraph.getInputOperator(new SystemStream("input-system", "input-stream"));
  assertEquals(2, inputOpImpl.registeredOperators.size());
  assertTrue(inputOpImpl.registeredOperators.stream()
      .anyMatch(opImpl -> ((OperatorImpl) opImpl).getOperatorSpec().getOpCode() == OpCode.FILTER));
  assertTrue(inputOpImpl.registeredOperators.stream()
      .anyMatch(opImpl -> ((OperatorImpl) opImpl).getOperatorSpec().getOpCode() == OpCode.MAP));
}
 
开发者ID:apache,项目名称:samza,代码行数:23,代码来源:TestOperatorImplGraph.java

示例2: testMergeChain

import org.apache.samza.operators.MessageStream; //导入方法依赖的package包/类
@Test
public void testMergeChain() {
  ApplicationRunner mockRunner = mock(ApplicationRunner.class);
  when(mockRunner.getStreamSpec(eq("input"))).thenReturn(new StreamSpec("input", "input-stream", "input-system"));
  StreamGraphImpl streamGraph = new StreamGraphImpl(mockRunner, mock(Config.class));

  MessageStream<Object> inputStream = streamGraph.getInputStream("input");
  MessageStream<Object> stream1 = inputStream.filter(mock(FilterFunction.class));
  MessageStream<Object> stream2 = inputStream.map(mock(MapFunction.class));
  MessageStream<Object> mergedStream = stream1.merge(Collections.singleton(stream2));
  MapFunction mockMapFunction = mock(MapFunction.class);
  mergedStream.map(mockMapFunction);

  TaskContextImpl mockTaskContext = mock(TaskContextImpl.class);
  when(mockTaskContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
  OperatorImplGraph opImplGraph =
      new OperatorImplGraph(streamGraph, mock(Config.class), mockTaskContext, mock(Clock.class));

  // verify that the DAG after merge is only traversed & initialized once
  verify(mockMapFunction, times(1)).init(any(Config.class), any(TaskContextImpl.class));
}
 
开发者ID:apache,项目名称:samza,代码行数:22,代码来源:TestOperatorImplGraph.java

示例3: translate

import org.apache.samza.operators.MessageStream; //导入方法依赖的package包/类
public void translate(final LogicalFilter filter, final TranslatorContext context) {
  MessageStream<SamzaSqlRelMessage> inputStream = context.getMessageStream(filter.getInput().getId());
  Expression expr =
      context.getExpressionCompiler().compile(filter.getInputs(), Collections.singletonList(filter.getCondition()));

  MessageStream<SamzaSqlRelMessage> outputStream = inputStream.filter(message -> {
    Object[] result = new Object[1];
    expr.execute(context.getExecutionContext(), context.getDataContext(), message.getRelFieldValues().toArray(), result);
    if (result.length > 0 && result[0] instanceof Boolean) {
      boolean retVal = (Boolean) result[0];
      log.debug(
          String.format("return value for input %s is %s", Arrays.asList(message.getFieldValues()).toString(), retVal));
      return retVal;
    } else {
      log.error("return value is not boolean");
      return false;
    }
  });

  context.registerMessageStream(filter.getId(), outputStream);
}
 
开发者ID:apache,项目名称:samza,代码行数:22,代码来源:FilterTranslator.java


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