Skip to content

Commit

Permalink
fix: point
Browse files Browse the repository at this point in the history
  • Loading branch information
Soontao committed Nov 15, 2022
1 parent 3df5422 commit 723e095
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/primitiveLiteral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function int64Value(value: SourceArray, index: number): Lexer.Token {
if (
val >= '0' &&
val <=
(value[start] === 0x2d ? '9223372036854775808' : '9223372036854775807')
(value[start] === 0x2d ? '9223372036854775808' : '9223372036854775807')
) {
return Lexer.tokenize(
value,
Expand Down Expand Up @@ -645,12 +645,14 @@ export function pointData(value: SourceArray, index: number): Lexer.Token {
export function lineStringData(value: SourceArray, index: number): Lexer.Token {
return multiGeoLiteralFactory(value, index, '', positionLiteral);
}

export function ringLiteral(value: SourceArray, index: number): Lexer.Token {
return multiGeoLiteralFactory(value, index, '', positionLiteral);
// Within each ringLiteral, the first and last positionLiteral elements MUST be an exact syntactic match to each other.
// Within the polygonData, the ringLiterals MUST specify their points in appropriate winding order.
// In order of traversal, points to the left side of the ring are interpreted as being in the polygon.
}

export function polygonData(value: SourceArray, index: number): Lexer.Token {
return multiGeoLiteralFactory(value, index, '', ringLiteral);
}
Expand Down Expand Up @@ -682,7 +684,12 @@ export function sridLiteral(value: SourceArray, index: number): Lexer.Token {
return Lexer.tokenize(value, start, index, 'SRID', Lexer.TokenType.Literal);
}
export function pointLiteral(value: SourceArray, index: number): Lexer.Token {
if (!Utils.equals(value, index, 'Point')) {
if (
!(
Utils.equals(value, index, 'Point') ||
Utils.equals(value, index, 'POINT')
)
) {
return;
}
const start = index;
Expand Down Expand Up @@ -1033,13 +1040,8 @@ export function geographyMultiPolygon(
);
}
export function geographyPoint(value: SourceArray, index: number): Lexer.Token {
return geoLiteralFactory(
value,
index,
'Edm.GeographyPoint',
Lexer.geographyPrefix,
fullPointLiteral
);
return geoLiteralFactory(value, index, 'Edm.GeographyPoint', Lexer.geographyPrefix, fullPointLiteral)
|| geoLiteralFactory(value, index, 'Edm.GeographyPoint', Lexer.geographyPrefix, pointLiteral);
}
export function geographyPolygon(
value: SourceArray,
Expand Down
6 changes: 5 additions & 1 deletion test/issue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ describe('Issue Related Test Suite', () => {
});

it('should support parser uri with geography - POLYGON', () => {

const t = defaultParser.odataUri("/Products?$filter=geo.intersects(Location, geography'SRID=12345;POLYGON((-127.89734578345 45.234534534,-127.89734578345 45.234534534,-127.89734578345 45.234534534,-127.89734578345 45.234534534))')");
expect(t).not.toBeUndefined();
});


it('should support parse filter with not full POINT', () => {
defaultParser.filter("geo.distance(location,geography'POINT(-1.702 48.113)') le 200");
});

});
14 changes: 14 additions & 0 deletions test/primitiveLiteral.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ describe('Primitive literals from json', () => {
expect(t).not.toBeUndefined();
});


it('should support geography - POINT', () => {
const t = defaultParser.literal("geography'POINT(-127.89734578345 45.234534534)'");
expect(t.value).toBe('Edm.GeographyPoint');
expect(t).not.toBeUndefined();
});

it('should support geography - FULL POINT', () => {
const t = defaultParser.literal("geography'SRID=12345;POINT(-127.89734578345 45.234534534)'");
expect(t.value).toBe('Edm.GeographyPoint');
expect(t).not.toBeUndefined();
});


});

function getLiteralFunctionName(itemRule) {
Expand Down

0 comments on commit 723e095

Please sign in to comment.