You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by GitBox <gi...@apache.org> on 2023/01/12 20:45:09 UTC

[GitHub] [streampipes] dominikriemer commented on a diff in pull request #1069: Sp 1065

dominikriemer commented on code in PR #1069:
URL: https://github.com/apache/streampipes/pull/1069#discussion_r1068634454


##########
streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/geojson/GeoJsonParser.java:
##########
@@ -85,66 +85,85 @@ public void parse(InputStream data, EmitBinaryEvent emitBinaryEvent) throws Pars
 
   @Override
   public EventSchema getEventSchema(List<byte[]> oneEvent) {
-    EventSchema resultSchema = new EventSchema();
+    return this.getSchemaAndSample(oneEvent).getEventSchema();
+  }
+
+  @Override
+  public boolean supportsPreview() {
+    return true;
+  }
+
+  @Override
+  public AdapterGuessInfo getSchemaAndSample(List<byte[]> eventSample) throws ParseException {
 
     Feature geoFeature = null;
     try {
-      geoFeature = new ObjectMapper().readValue(oneEvent.get(0), Feature.class);
+      geoFeature = new ObjectMapper().readValue(eventSample.get(0), Feature.class);
 
     } catch (IOException e) {
       logger.error(e.toString());
     }
 
-    for (Map.Entry<String, Object> entry : geoFeature.getProperties().entrySet()) {
-      EventProperty p = JsonEventProperty.getEventProperty(entry.getKey(), entry.getValue());
-      resultSchema.addEventProperty(p);
-    }
-
-    List<EventProperty> eventProperties = parseGeometryField(geoFeature);
-    eventProperties.forEach(eventProperty -> resultSchema.addEventProperty(eventProperty));
-
-    return resultSchema;
+    return this.parseGeometryField(geoFeature);
   }
 
-  private List<EventProperty> parseGeometryField(Feature geoFeature) {
+  private AdapterGuessInfo parseGeometryField(Feature geoFeature) {
+
+    EventSchema resultSchema = new EventSchema();
     List<EventProperty> eventProperties = new LinkedList<>();
+    var sampleValues = new HashMap<String, GuessTypeInfo>();
 
     if (geoFeature.getGeometry() instanceof Point) {
       Point point = (Point) geoFeature.getGeometry();
       eventProperties.add(getEventPropertyGeoJson("longitude", point.getCoordinates().getLongitude(),
           "http://www.w3.org/2003/01/geo/wgs84_pos#long"));
       eventProperties.add(getEventPropertyGeoJson("latitude", point.getCoordinates().getLatitude(),
           "http://www.w3.org/2003/01/geo/wgs84_pos#lat"));
+
+      sampleValues.put("longitude", new GuessTypeInfo("java.lang.Double", point.getCoordinates().getLongitude()));
+      sampleValues.put("latitude", new GuessTypeInfo("java.lang.Double", point.getCoordinates().getLatitude()));
       if (point.getCoordinates().hasAltitude()) {
         eventProperties.add(getEventPropertyGeoJson("altitude", point.getCoordinates().getAltitude(), SO.ALTITUDE));
+        sampleValues.put("altitude", new GuessTypeInfo("java.lang.Double", point.getCoordinates().getAltitude()));
       }
 
     } else if (geoFeature.getGeometry() instanceof LineString) {
       LineString lineString = (LineString) geoFeature.getGeometry();
       eventProperties.add(JsonEventProperty.getEventProperty("coorindatesLineString", lineString.getCoordinates()));
-
+      sampleValues.put("coorindatesLineString", new GuessTypeInfo("java.lang.Double", lineString.getCoordinates()));

Review Comment:
   is this a type and should be named `coordinates`?



##########
streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/geojson/GeoJsonParser.java:
##########
@@ -85,66 +85,85 @@ public void parse(InputStream data, EmitBinaryEvent emitBinaryEvent) throws Pars
 
   @Override
   public EventSchema getEventSchema(List<byte[]> oneEvent) {
-    EventSchema resultSchema = new EventSchema();
+    return this.getSchemaAndSample(oneEvent).getEventSchema();
+  }
+
+  @Override
+  public boolean supportsPreview() {
+    return true;
+  }
+
+  @Override
+  public AdapterGuessInfo getSchemaAndSample(List<byte[]> eventSample) throws ParseException {
 
     Feature geoFeature = null;
     try {
-      geoFeature = new ObjectMapper().readValue(oneEvent.get(0), Feature.class);
+      geoFeature = new ObjectMapper().readValue(eventSample.get(0), Feature.class);
 
     } catch (IOException e) {
       logger.error(e.toString());
     }
 
-    for (Map.Entry<String, Object> entry : geoFeature.getProperties().entrySet()) {
-      EventProperty p = JsonEventProperty.getEventProperty(entry.getKey(), entry.getValue());
-      resultSchema.addEventProperty(p);
-    }
-
-    List<EventProperty> eventProperties = parseGeometryField(geoFeature);
-    eventProperties.forEach(eventProperty -> resultSchema.addEventProperty(eventProperty));
-
-    return resultSchema;
+    return this.parseGeometryField(geoFeature);
   }
 
-  private List<EventProperty> parseGeometryField(Feature geoFeature) {
+  private AdapterGuessInfo parseGeometryField(Feature geoFeature) {
+
+    EventSchema resultSchema = new EventSchema();
     List<EventProperty> eventProperties = new LinkedList<>();
+    var sampleValues = new HashMap<String, GuessTypeInfo>();
 
     if (geoFeature.getGeometry() instanceof Point) {
       Point point = (Point) geoFeature.getGeometry();
       eventProperties.add(getEventPropertyGeoJson("longitude", point.getCoordinates().getLongitude(),
           "http://www.w3.org/2003/01/geo/wgs84_pos#long"));
       eventProperties.add(getEventPropertyGeoJson("latitude", point.getCoordinates().getLatitude(),
           "http://www.w3.org/2003/01/geo/wgs84_pos#lat"));
+
+      sampleValues.put("longitude", new GuessTypeInfo("java.lang.Double", point.getCoordinates().getLongitude()));
+      sampleValues.put("latitude", new GuessTypeInfo("java.lang.Double", point.getCoordinates().getLatitude()));
       if (point.getCoordinates().hasAltitude()) {
         eventProperties.add(getEventPropertyGeoJson("altitude", point.getCoordinates().getAltitude(), SO.ALTITUDE));
+        sampleValues.put("altitude", new GuessTypeInfo("java.lang.Double", point.getCoordinates().getAltitude()));
       }
 
     } else if (geoFeature.getGeometry() instanceof LineString) {
       LineString lineString = (LineString) geoFeature.getGeometry();
       eventProperties.add(JsonEventProperty.getEventProperty("coorindatesLineString", lineString.getCoordinates()));
-
+      sampleValues.put("coorindatesLineString", new GuessTypeInfo("java.lang.Double", lineString.getCoordinates()));
     } else if (geoFeature.getGeometry() instanceof Polygon) {
       Polygon polygon = (Polygon) geoFeature.getGeometry();
       eventProperties.add(JsonEventProperty.getEventProperty("coorindatesPolygon", polygon.getCoordinates()));
-
+      sampleValues.put("coorindatesPolygon", new GuessTypeInfo("java.lang.Double", polygon.getCoordinates()));
     } else if (geoFeature.getGeometry() instanceof MultiPoint) {
       MultiPoint multiPoint = (MultiPoint) geoFeature.getGeometry();
       eventProperties.add(JsonEventProperty.getEventProperty("coorindatesMultiPoint", multiPoint.getCoordinates()));
-
+      sampleValues.put("coorindatesMultiPoint", new GuessTypeInfo("java.lang.Double", multiPoint.getCoordinates()));

Review Comment:
   same for all types



##########
streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml:
##########
@@ -127,6 +127,12 @@
             <groupId>org.apache.plc4x</groupId>
             <artifactId>plc4j-driver-s7</artifactId>
             <scope>runtime</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.fasterxml.woodstox</groupId>
+                    <artifactId>woodstox-core</artifactId>
+                </exclusion>

Review Comment:
   Does this exclusion have any impact on the S7 driver?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org