Search in sources :

Example 41 with StreamlineEvent

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

the class StreamlineJdbcMapper method getColumns.

@Override
public List<Column> getColumns(ITuple tuple) {
    StreamlineEvent event = (StreamlineEvent) tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
    List<Column> res = new ArrayList<>();
    if (fieldsToColumns.isEmpty()) {
        initFieldsToColumns();
    }
    for (String field : fields) {
        Column<?> column = getColumn(field);
        String columnName = column.getColumnName();
        Integer columnSqlType = column.getSqlType();
        Object value = Util.getJavaType(columnSqlType).cast(event.get(field));
        res.add(new Column<>(columnName, value, columnSqlType));
    }
    return res;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Column(org.apache.storm.jdbc.common.Column) ArrayList(java.util.ArrayList)

Example 42 with StreamlineEvent

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

the class StreamlineJPMMLModelRunner method extractRawInputs.

/**
 * @return The raw inputs extracted from the tuple for all 'active fields'
 */
@Override
public Map<FieldName, Object> extractRawInputs(Tuple tuple) {
    LOG.debug("Extracting raw inputs from tuple: = [{}]", tuple);
    Object event = tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
    final Map<FieldName, Object> rawInputs = new LinkedHashMap<>();
    if (event instanceof StreamlineEvent) {
        StreamlineEvent streamlineEvent = (StreamlineEvent) event;
        for (FieldName fieldName : getActiveFields()) {
            if (streamlineEvent.containsKey(fieldName.getValue())) {
                rawInputs.put(fieldName, streamlineEvent.get(fieldName.getValue()));
            }
        }
    } else {
        LOG.debug("Not processing invalid input tuple:[{}] with streamline event:[{}]", tuple, event);
    }
    LOG.debug("Raw inputs = [{}]", rawInputs);
    return rawInputs;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) FieldName(org.dmg.pmml.FieldName) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with StreamlineEvent

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

the class DefaultSplitter method splitEvent.

@Override
public List<Result> splitEvent(StreamlineEvent inputEvent, Set<String> outputStreams) {
    List<Result> results = new ArrayList<>();
    String groupId = getGroupId(inputEvent);
    int curPartNo = 0;
    int totalParts = outputStreams.size();
    for (String stream : outputStreams) {
        StreamlineEvent partitionedEvent = createPartitionEvent(inputEvent, groupId, ++curPartNo, stream, totalParts);
        results.add(new Result(stream, Collections.singletonList(partitionedEvent)));
    }
    return results;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Result(com.hortonworks.streamline.streams.Result)

Example 44 with StreamlineEvent

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

the class StreamlineEventImplTest method testGetDataSourceId.

@Test
public void testGetDataSourceId() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("a", "aval");
    map.put("b", "bval");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(map).dataSourceId("1").build();
    assertEquals("1", event.getDataSourceId());
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Test(org.junit.Test)

Example 45 with StreamlineEvent

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

the class StreamlineEventImplTest method testToFromString.

@Test
public void testToFromString() {
    Map<String, Object> map = new HashMap<>();
    map.put("a", "aval");
    map.put("b", "bval");
    StreamlineEventImpl se1 = StreamlineEventImpl.builder().putAll(map).build();
    String s = se1.toString();
    StreamlineEvent se2 = StreamlineEventImpl.fromString(s);
    assertEquals("aval", se2.get("a"));
    assertEquals("bval", se2.get("b"));
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) 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