[
https://issues.apache.org/jira/browse/TINKERPOP-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18146993#comment-18146993
]
ASF GitHub Bot commented on TINKERPOP-2558:
-------------------------------------------
GumpacG commented on code in PR #3809:
URL: https://github.com/apache/tinkerpop/pull/3809#discussion_r4622642727
##########
gremlin-js/gremlin-javascript/lib/language/translator/TranslateVisitor.ts:
##########
@@ -268,6 +278,55 @@ export default class TranslateVisitor {
this.appendExplicitNaming(ctx.getText(), 'GType');
}
+ /**
+ * Extracts the name of the type from a `GType` which may be written with
or without the `GType`
+ * prefix and in either the camel case or the upper case form, as in
`lineString` and `LINESTRING`.
+ */
+ protected static extractGTypeName(ctx: any): string {
+ const split: string[] = ctx.getText().split('.');
+ return split[split.length - 1];
+ }
+
+ /**
+ * Determines if a `GType` names a geometry type, which the translators
that have no geometry support use
+ * to reject the type.
+ */
+ protected static isGeometryGType(ctx: any): boolean {
+ return
TranslateVisitor.GEOMETRY_GTYPE_NAMES.has(TranslateVisitor.extractGTypeName(ctx).toUpperCase());
+ }
+
+ /**
+ * Appends `Geometry.fromWkt("...")`, the form the JVM languages use since
they have a WKT reader, with
+ * `Model.GEOGRAPHIC` or the SRID as a second argument where the geometry
carries one. The WKT is written
+ * as the Gremlin spells it, since this translator has no WKT reader of
its own to normalize it through.
+ * WKT holds no quote or backslash, so the text needs no escaping.
+ */
+ protected appendGeometryFromWkt(ctx: any): void {
+ this.sb.push('Geometry.fromWkt("');
+
this.sb.push(TranslateVisitor.removeFirstAndLastCharacters(ctx.stringLiteral().getText()));
+ this.sb.push('"');
+
+ const modelCtx = ctx.traversalModel();
+ if (modelCtx != null) {
+ const modelName: string =
modelCtx.getText().split('.').pop().toUpperCase();
+ // CARTESIAN is the default model and so goes unwritten
Review Comment:
Fixed, a conflicting SRID= prefix and model or SRID is now rejected with
WktReader's message.
##########
gremlin-js/gremlin-javascript/lib/language/translator/JavaTranslateVisitor.ts:
##########
@@ -226,6 +226,10 @@ export default class JavaTranslateVisitor extends
TranslateVisitor {
this.sb.push('))');
}
+ visitGeometryLiteral(ctx: any): void {
+ this.appendGeometryFromWkt(ctx);
Review Comment:
Added more tests.
##########
gremlin-language/src/main/antlr4/Gremlin.g4:
##########
@@ -1113,6 +1113,11 @@ traversalDT
| K_DAY | K_DT DOT K_DAY
;
+traversalModel
Review Comment:
Done as suggested, the three prefixed Model values are generic literals and
a narrower geometryModel rule keeps Geometry(...) to CARTESIAN and GEOGRAPHIC.
> GEO Spatial APIs
> ----------------
>
> Key: TINKERPOP-2558
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2558
> Project: TinkerPop
> Issue Type: Improvement
> Components: process
> Affects Versions: 3.5.0
> Reporter: Jitesh
> Priority: Major
>
> Provide support for Geo based APIs (predicates, objects, etc)
>
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)