Search in sources :

Example 76 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class AvroKafkaSpoutTranslator method apply.

@Override
public List<Object> apply(ConsumerRecord<Object, ByteBuffer> consumerRecord) {
    Map<String, Object> keyValues = (Map<String, Object>) deserializer().deserialize(new ByteBufferInputStream(consumerRecord.value()), readerSchemaVersion);
    StreamlineEvent streamlineEvent = StreamlineEventImpl.builder().putAll(keyValues).dataSourceId(dataSourceId).build();
    KafkaTuple kafkaTuple = new KafkaTuple(streamlineEvent);
    kafkaTuple.routedTo(outputStream);
    return kafkaTuple;
}
Also used : KafkaTuple(org.apache.storm.kafka.spout.KafkaTuple) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 77 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class StreamlineEventSerializerTest method runPrimitiveTest.

private void runPrimitiveTest(Map data, Schema schema, Object expectedValue) {
    StreamlineEvent streamlineEvent = StreamlineEventImpl.builder().fieldsAndValues(data).dataSourceId("dataSourceId").build();
    Assert.assertEquals(expectedValue, StreamlineEventSerializer.getAvroRecord(streamlineEvent, schema));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent)

Example 78 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class StreamlineEventSerializerTest method testRecordWithFixed.

@Test
public void testRecordWithFixed() {
    List<Schema.Field> fields = new ArrayList<>();
    Map<String, Object> data = new HashMap<>();
    for (int i = 0; i < PRIMITIVE_VALUES.length; ++i) {
        Schema.Field field = new Schema.Field(NAMES[i], Schema.create(SCHEMA_TYPES[i]), null, null);
        fields.add(field);
        data.put(NAMES[i], PRIMITIVE_VALUES[i]);
    }
    // add fixed to test case
    fields.add(new Schema.Field("fixed", Schema.createFixed("fixedSchema", null, null, 10), null, null));
    data.put("fixed", "bytes".getBytes());
    // add array to test case
    fields.add(new Schema.Field("array", Schema.createArray(Schema.create(Schema.Type.INT)), null, null));
    List<Integer> integerList = new ArrayList<>();
    integerList.add(1);
    integerList.add(2);
    data.put("array", integerList);
    Schema schema = Schema.createRecord(fields);
    GenericRecord expected = new GenericData.Record(schema);
    for (int i = 0; i < PRIMITIVE_VALUES.length; ++i) {
        expected.put(NAMES[i], PRIMITIVE_VALUES[i]);
    }
    expected.put("fixed", new GenericData.Fixed(Schema.createFixed("fixedSchema", null, null, 10), "bytes".getBytes()));
    expected.put("array", new GenericData.Array<Integer>(Schema.createArray(Schema.create(Schema.Type.INT)), integerList));
    StreamlineEvent streamlineEvent = StreamlineEventImpl.builder().fieldsAndValues(data).dataSourceId("dataSourceId").build();
    Assert.assertEquals(expected, StreamlineEventSerializer.getAvroRecord(streamlineEvent, schema));
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) GenericData(org.apache.avro.generic.GenericData) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Example 79 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class TestRealtimeJoinBolt method makeStreamLineEventStream.

// NOTE: Streamline Specific
private static ArrayList<Tuple> makeStreamLineEventStream(String streamName, String[] fieldNames, Object[][] records) {
    MockTopologyContext mockContext = new MockTopologyContext(new String[] { StreamlineEvent.STREAMLINE_EVENT });
    ArrayList<Tuple> result = new ArrayList<>(records.length);
    // convert each record into a HashMap using fieldNames as keys
    for (Object[] record : records) {
        HashMap<String, Object> recordMap = new HashMap<>(fieldNames.length);
        for (int i = 0; i < fieldNames.length; i++) {
            recordMap.put(fieldNames[i], record[i]);
        }
        StreamlineEvent streamLineEvent = StreamlineEventImpl.builder().fieldsAndValues(recordMap).dataSourceId("multiple sources").build();
        ArrayList<Object> tupleValues = new ArrayList<>(1);
        tupleValues.add(streamLineEvent);
        TupleImpl tuple = new TupleImpl(mockContext, tupleValues, 0, streamName);
        result.add(tuple);
    }
    return result;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent)

Example 80 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class WindowRulesBoltTest method testCountBasedWindowWithGroupbyUnordered.

@Test
public void testCountBasedWindowWithGroupbyUnordered() throws Exception {
    String rulesJson = readFile("/window-rule-groupby-unordered.json");
    RulesProcessor rulesProcessor = Utils.createObjectFromJson(rulesJson, RulesProcessor.class);
    Window windowConfig = rulesProcessor.getRules().get(0).getWindow();
    WindowRulesBolt wb = new WindowRulesBolt(rulesJson, RuleProcessorRuntime.ScriptType.SQL);
    wb.withWindowConfig(windowConfig);
    WindowedBoltExecutor wbe = new WindowedBoltExecutor(wb);
    Map<String, Object> conf = wb.getComponentConfiguration();
    wbe.prepare(conf, mockContext, mockCollector);
    wbe.execute(getNextTuple(10));
    wbe.execute(getNextTuple(15));
    wbe.execute(getNextTuple(11));
    wbe.execute(getNextTuple(16));
    new Verifications() {

        {
            String streamId;
            Collection<Tuple> anchors;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchors = withCapture(), withCapture(tuples));
            Assert.assertEquals(2, tuples.size());
            Map<String, Object> fieldsAndValues = ((StreamlineEvent) tuples.get(0).get(0));
            Assert.assertEquals(2, fieldsAndValues.get("deptid"));
            Assert.assertEquals(110, fieldsAndValues.get("salary_MAX"));
            fieldsAndValues = ((StreamlineEvent) tuples.get(1).get(0));
            Assert.assertEquals(3, fieldsAndValues.get("deptid"));
            Assert.assertEquals(160, fieldsAndValues.get("salary_MAX"));
        }
    };
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Verifications(mockit.Verifications) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) WindowedBoltExecutor(org.apache.storm.topology.WindowedBoltExecutor) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)97 Test (org.junit.Test)47 HashMap (java.util.HashMap)41 Values (org.apache.storm.tuple.Values)25 ArrayList (java.util.ArrayList)19 Tuple (org.apache.storm.tuple.Tuple)14 Result (com.hortonworks.streamline.streams.Result)13 Expectations (mockit.Expectations)9 TupleImpl (org.apache.storm.tuple.TupleImpl)9 Map (java.util.Map)8 Verifications (mockit.Verifications)8 TransformRuntime (com.hortonworks.streamline.streams.runtime.TransformRuntime)7 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)6 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)6 List (java.util.List)5 IdPreservedStreamlineEvent (com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent)4 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)4 Fields (org.apache.storm.tuple.Fields)4 EventCorrelationInjector (com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector)3 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)3