use of org.apache.storm.tuple.Fields in project storm by apache.
the class TestPlanCompiler method testCaseStatement.
@Test
public void testCaseStatement() throws Exception {
int EXPECTED_VALUE_SIZE = 5;
String sql = "SELECT CASE WHEN NAME IN ('a', 'abc', 'abcde') THEN UPPER('a') " + "WHEN UPPER(NAME) = 'AB' THEN 'b' ELSE {fn CONCAT(NAME, '#')} END FROM FOO";
TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
final Map<String, ISqlTridentDataSource> data = new HashMap<>();
data.put("FOO", new TestUtils.MockSqlTridentDataSource());
QueryPlanner planner = new QueryPlanner(state.schema());
AbstractTridentProcessor proc = planner.compile(data, sql);
final TridentTopology topo = proc.build();
Fields f = proc.outputStream().getOutputFields();
proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(), f, new TestUtils.MockStateUpdater(), new Fields());
runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
Assert.assertArrayEquals(new Values[] { new Values("A"), new Values("b"), new Values("A"), new Values("abcd#"), new Values("A") }, getCollectedValues().toArray());
}
use of org.apache.storm.tuple.Fields in project storm by apache.
the class TestPlanCompiler method testCompile.
@Test
public void testCompile() throws Exception {
final int EXPECTED_VALUE_SIZE = 2;
String sql = "SELECT ID FROM FOO WHERE ID > 2";
TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
final Map<String, ISqlTridentDataSource> data = new HashMap<>();
data.put("FOO", new TestUtils.MockSqlTridentDataSource());
QueryPlanner planner = new QueryPlanner(state.schema());
AbstractTridentProcessor proc = planner.compile(data, sql);
final TridentTopology topo = proc.build();
Fields f = proc.outputStream().getOutputFields();
proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(), f, new TestUtils.MockStateUpdater(), new Fields());
runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
Assert.assertArrayEquals(new Values[] { new Values(3), new Values(4) }, getCollectedValues().toArray());
}
use of org.apache.storm.tuple.Fields in project storm by apache.
the class TridentTopologySource method getTopology.
public StormTopology getTopology(Config config) {
this.spout = new FixedBatchSpout(new Fields("sentence"), 20, new Values("one two"), new Values("two three"), new Values("three four"), new Values("four five"), new Values("five six"));
TridentTopology trident = new TridentTopology();
trident.newStream("wordcount", spout).name("sentence").parallelismHint(1).shuffle().each(new Fields("sentence"), new Split(), new Fields("word")).parallelismHint(1).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(1);
return trident.build();
}
use of org.apache.storm.tuple.Fields in project storm by apache.
the class Murmur3StreamGrouping method prepare.
/**
* {@inheritDoc}
*/
@Override
public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) {
this.targetTasks = targetTasks;
this.partitionKeyIndexes = new ArrayList<>();
Fields componentOutputFields = context.getComponentOutputFields(stream);
for (String partitionKeyName : partitionKeyNames) {
partitionKeyIndexes.add(componentOutputFields.fieldIndex(partitionKeyName));
}
}
use of org.apache.storm.tuple.Fields in project storm by apache.
the class OpaqueTridentEventCount method buildTopology.
@Override
protected StormTopology buildTopology(EventHubSpout eventHubSpout) {
TridentTopology topology = new TridentTopology();
OpaqueTridentEventHubSpout spout = new OpaqueTridentEventHubSpout(spoutConfig);
TridentState state = topology.newStream("stream-" + spoutConfig.getTopologyName(), spout).parallelismHint(spoutConfig.getPartitionCount()).aggregate(new Count(), new Fields("partial-count")).persistentAggregate(new MemoryMapState.Factory(), new Fields("partial-count"), new Sum(), new Fields("count"));
state.newValuesStream().each(new Fields("count"), new LoggingFilter("got count: ", 10000));
return topology.build();
}
Aggregations