-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add feature processor to convert geojson feature to geoshape field #15
Conversation
f89d8e7
to
415380e
Compare
796a1a1
to
5de6691
Compare
5de6691
to
027dc71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add more detail to the description?
public class Feature { | ||
public static final String TYPE = "Feature"; | ||
private final Map<String, Object> geometry; | ||
private Map<String, Object> properties = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create this object here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it to constructor
|
||
import java.util.Map; | ||
|
||
public class GeoJSONFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be FeatureFactory if it produces a Feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
} | ||
|
||
private static Feature readFeature(Map<String, Object> input) { | ||
Map<String, Object> geometryMap = (Map<String, Object>) input.get(GEOJSON_GEOMETRY_KEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be validated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
|
||
@Override | ||
public IngestDocument execute(IngestDocument ingestDocument) { | ||
Feature feature = GeoJSONFactory.create(ingestDocument.getSourceAndMetadata()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add comments here explaining what is being done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
032d441
to
a0727b7
Compare
*/ | ||
static class FeatureBuilder { | ||
|
||
private Feature feature; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make it final?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
* @return Feature Instance from input | ||
* @throws IllegalArgumentException if invalid input is provided | ||
*/ | ||
public static Feature create(Map<String, Object> input) throws IllegalArgumentException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why IllegalArgumentException is defined in the method signature, it's unchecked exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
if (!(geometry instanceof Map)) { | ||
throw new IllegalArgumentException("key: " + Feature.GEOMETRY_KEY + "is not an instance of type Map"); | ||
} | ||
Map<String, Object> geometryMap = (Map<String, Object>) geometry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: are we sure this is map of <String, Object>? Although I'm sure how to check that properly, effectively you're getting Map<Object,Object>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created new method to convert
0ee11a5
to
273a13d
Compare
70b9b6a
to
c2b99b8
Compare
5c808f8
to
54c7553
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, thank you
* | ||
* @return Feature's type value | ||
*/ | ||
public String getType() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a getter on a public static type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I forgot to remove this method after i made it as public static constant.
Map<String, Object> geometryMap = toStringObjectMap(geometry); | ||
FeatureBuilder featureBuilder = new FeatureBuilder(geometryMap); | ||
Object properties = input.get(Feature.PROPERTIES_KEY); | ||
if (properties == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Why not wrap this in curly braces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
if (properties == null) | ||
return featureBuilder; | ||
|
||
if (!(geometry instanceof Map)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is supposed to be properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste from previous check :( I corrected it now.
Added new Processor of type geojson-feature. Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
54c7553
to
84eb6a0
Compare
Description
Added new Processor of type geojson-feature to intercept GeoJSON Feature and convert into typical OpenSearch document.
Example: A GeoJSON object of type “Feature”, contains geometry object of type “LineString”.
The above feature can be converted to typical document for an index which has "location" as type geo_shape, by FeatureProcessor.
This processor converts Geometry Object into geo_shape field value, removes GeoJSON metadata like type, and convert properties into direct fields.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.