You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by Florian Micklich <mi...@apache.org> on 2022/11/21 17:42:25 UTC

unclear/missleading example code writing own processor on website

Hi all,

I just wondering on the example with the 1 class processor here [1] [2].
I think something is odd or I don't get it.

In the description is mentioned that

Next, we are interested in the fields of the input event stream that contains the latitude and longitude value we would like to compute against the geofence center location as follows:

```
String latitudeFieldName = extractor.mappingPropertyValue("latitude-field");
String longitudeFieldName = extractor.mappingPropertyValue("longitude-field");
``` 

1) Shouldn't it be:
```
String latitudeFieldName = parameters.extractor().mappingPropertyValue("latitude-field");
String longitudeFieldName = parameters.extractor().mappingPropertyValue("longitude-field");

```
2) But this code snippet is missing in "Your controller class should look as follows" example.


3) 
The latitudeFieldName is used in the onEvent Method as

```
float latitude = event.getFieldBySelector(latitudeFieldName).getAsPrimitive().getAsFloat();
float longitude = event.getFieldBySelector(longitudeFieldName).getAsPrimitive().getAsFloat();
```
But the variables can not be resolved. So how to get the example work?
Example Code in ticket [3]

Greeting
Florian

[1] https://streampipes.apache.org/docs/docs/extend-tutorial-data-processors.html
[2] https://github.com/apache/streampipes-website/blob/dev/documentation/docs/06_extend-tutorial-data-processors.md
[3] https://issues.apache.org/jira/browse/STREAMPIPES-643

Re: unclear/missleading example code writing own processor on website

Posted by Florian Micklich <mi...@apache.org>.
Hi,

I found the error.
The two variables were not defined and the mapping method was also missing in the final example.
I added the new class in the jira ticket [1]
Before I adjust the example on the website I would like to start a discussion about the variable names in this example.


For better understanding we should change the variable names depending on the usage.

In the geofence example there are this variables in my fixed version:
 
```
    // VARIABLES FOR INTERNAL NAME USAGE
    private static final String LATITUDE_INTERNAL_NAME = "latitude-key";
    private static final String LONGITUDE_INTERNAL_NAME = "longitude-key";
    private static final String LATITUDE_CENTER = "latitude-center";
    private static final String LONGITUDE_CENTER = "longitude-center";

    // VALUES FROM THE STREAM REQUIREMENTS (HAS TO BE STRING) TO MAP INTO onInvocation
    private String latitudeFieldMapper;
    private String longitudeFieldMapper;

    // VALUES FROM THE USER INPUT PARAMETERS
    private float centerLatitude;
    private float centerLongitude;
    private int radius;

    // THE VARIABLES FROM THE EVENT VALUES ITSELF ARE DEFINED IN THE onEvent method 
```


So we have 5 types of variables usage:

1) store the *internal name* usage -> String  name_INTERNAL_NAME
2) store the *field mapper* usage -> String nameFieldMapper
3) store the *user field* parameter usage -> TYPE name
4) store the event stream variables in the onEvent method usage -> Type name
5) store *runtime names* to add to the stream description in the outputStrategie (this example is missing in the example) -> String NAME_RUNTIME


What do you think?

Greetings
Florian

[1] https://issues.apache.org/jira/browse/STREAMPIPES-643

Am Montag, dem 21.11.2022 um 18:42 +0100 schrieb Florian Micklich:
> Hi all,<br>
> 
> I just wondering on the example with the 1 class processor here [1] [2].<br>
> I think something is odd or I don't get it.<br>
> 
> In the description is mentioned that<br>
> 
> Next, we are interested in the fields of the input event stream that contains the latitude and longitude value we would like to compute against the geofence center location as follows:<br>
> 
> ```<br>
> String latitudeFieldName = extractor.mappingPropertyValue("latitude-field");<br>
> String longitudeFieldName = extractor.mappingPropertyValue("longitude-field");<br>
> ``` <br>
> 
> 1) Shouldn't it be:<br>
> ```<br>
> String latitudeFieldName = parameters.extractor().mappingPropertyValue("latitude-field");<br>
> String longitudeFieldName = parameters.extractor().mappingPropertyValue("longitude-field");<br>
> 
> ```<br>
> 2) But this code snippet is missing in "Your controller class should look as follows" example.<br>
> 
> 
> 3) <br>
> The latitudeFieldName is used in the onEvent Method as<br>
> 
> ```<br>
> float latitude = event.getFieldBySelector(latitudeFieldName).getAsPrimitive().getAsFloat();<br>
> float longitude = event.getFieldBySelector(longitudeFieldName).getAsPrimitive().getAsFloat();<br>
> ```<br>
> But the variables can not be resolved. So how to get the example work?<br>
> Example Code in ticket [3]<br>
> 
> Greeting<br>
> Florian<br>
> 
> [1] [https://streampipes.apache.org/docs/docs/extend-tutorial-data-processors.html](https://streampipes.apache.org/docs/docs/extend-tutorial-data-processors.html)<br>
> [2] [https://github.com/apache/streampipes-website/blob/dev/documentation/docs/06_extend-tutorial-data-processors.md](https://github.com/apache/streampipes-website/blob/dev/documentation/docs/06_extend-tutorial-data-processors.md)<br>
> [3] [https://issues.apache.org/jira/browse/STREAMPIPES-643](https://issues.apache.org/jira/browse/STREAMPIPES-643)<br>