Skip to content

Commit 32bb07a

Browse files
authored
Merge pull request #1740 from RedisInsight/fe/bugfix/RI-3726_profile_explain-geo-support
Profile/Explain plugin - Add support for Parsing GEO tags in RediSearch
2 parents 9361692 + dbdb2ac commit 32bb07a

File tree

1 file changed

+86
-1
lines changed
  • redisinsight/ui/src/packages/ri-explain/src

1 file changed

+86
-1
lines changed

redisinsight/ui/src/packages/ri-explain/src/parser.ts

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ enum TokenType {
99

1010
UNION = 'UNION',
1111
INTERSECT = 'INTERSECT',
12+
GEO_EXPR = 'GEO_EXPR',
1213
TAG_EXPR = 'TAG_EXPR',
1314
NUMERIC = 'NUMERIC',
1415
LBRACE = 'LBRACE',
@@ -20,6 +21,7 @@ enum TokenType {
2021

2122
PLUS = 'PLUS',
2223
MINUS = 'MINUS',
24+
COMMA = 'COMMA',
2325

2426
LESS = 'LESS',
2527
GREATER = 'GREATER',
@@ -140,6 +142,9 @@ class Lexer {
140142
case '-':// TODO: This should be MINUS token
141143
t = new Token(TokenType.IDENTIFIER, this.C)
142144
break
145+
case ',':
146+
t = new Token(TokenType.COMMA, this.C)
147+
break
143148
case '<':
144149
let lPeekChar = this.PeekChar()
145150
if (lPeekChar !== null && lPeekChar === '=') {
@@ -175,9 +180,10 @@ class Lexer {
175180
if (this.C !== undefined && (isLetter(this.C) || ['@', ':'].includes(this.C))) {
176181
const literal = this.ReadIdentifier()
177182
let tokenType = KEYWORDS[literal] || TokenType.IDENTIFIER
178-
179183
if (literal.startsWith('TAG:')) {
180184
tokenType = TokenType.TAG_EXPR
185+
} else if (literal === 'GEO') {
186+
tokenType = TokenType.GEO_EXPR
181187
} else if (literal.startsWith('@') && literal.endsWith(':UNION')) {
182188
tokenType = TokenType.UNION
183189
} else if (literal.startsWith('@') && literal.endsWith(':INTERSECT')) {
@@ -283,6 +289,11 @@ class Expr {
283289

284290
if (this.SubType === EntityType.TAG && this.Info?.startsWith('TAG:')) {
285291
snippet = this.Info?.substr(4)
292+
} else if (this.SubType === EntityType.GEO) {
293+
snippet = this.Info
294+
if (snippet?.endsWith(':')) {
295+
snippet = snippet?.slice(0, -1)
296+
}
286297
}
287298

288299
return {
@@ -455,6 +466,8 @@ class Parser {
455466
Exprs.push(this.parseIntersectExpr())
456467
} else if (this.CurrentToken.T === TokenType.TAG_EXPR) {
457468
Exprs.push(this.parseTagExpr())
469+
} else if (this.CurrentToken.T === TokenType.GEO_EXPR) {
470+
Exprs.push(this.parseTagExpr())
458471
}
459472

460473
this.nextToken()
@@ -499,6 +512,8 @@ class Parser {
499512
Exprs.push(this.parseIntersectExpr())
500513
} else if (this.CurrentToken.T === TokenType.TAG_EXPR) {
501514
Exprs.push(this.parseTagExpr())
515+
} else if (this.CurrentToken.T === TokenType.GEO_EXPR) {
516+
Exprs.push(this.parseTagExpr())
502517
}
503518

504519
this.nextToken()
@@ -521,6 +536,74 @@ class Parser {
521536
return new Expr(str, EntityType.TEXT)
522537
}
523538

539+
parseGeoExpr() {
540+
assertToken(TokenType.GEO_EXPR, this.CurrentToken.T)
541+
542+
let geoData = this.CurrentToken.Data
543+
544+
this.nextToken()
545+
546+
assertToken(TokenType.IDENTIFIER, this.CurrentToken.T)
547+
548+
let identifierData = this.CurrentToken.Data
549+
550+
this.nextToken()
551+
552+
assertToken(TokenType.LBRACE, this.CurrentToken.T)
553+
554+
this.nextToken()
555+
556+
assertToken(TokenType.NUMBER, this.CurrentToken.T)
557+
558+
let first = this.CurrentToken.Data;
559+
560+
this.nextToken()
561+
562+
assertToken(TokenType.COMMA, this.CurrentToken.T)
563+
564+
this.nextToken()
565+
566+
assertToken(TokenType.NUMBER, this.CurrentToken.T)
567+
568+
let second = this.CurrentToken.Data;
569+
570+
this.nextToken()
571+
572+
assertToken(TokenType.IDENTIFIER, this.CurrentToken.T)
573+
574+
assert(this.CurrentToken.Data === '-', "Expected Identifier to be MINUS")
575+
576+
this.nextToken()
577+
578+
assertToken(TokenType.IDENTIFIER, this.CurrentToken.T)
579+
580+
assert(this.CurrentToken.Data === '-', "Expected Identifier to be MINUS")
581+
582+
this.nextToken()
583+
584+
assertToken(TokenType.GREATER, this.CurrentToken.T)
585+
586+
this.nextToken()
587+
588+
assertToken(TokenType.NUMBER, this.CurrentToken.T)
589+
590+
let third = this.CurrentToken.Data;
591+
592+
this.nextToken()
593+
594+
assertToken(TokenType.IDENTIFIER, this.CurrentToken.T)
595+
596+
let metric = this.CurrentToken.Data;
597+
598+
this.nextToken()
599+
600+
assertToken(TokenType.RBRACE, this.CurrentToken?.T)
601+
602+
this.nextToken()
603+
604+
return new Expr(`${first},${second} --> ${third} ${metric}`, EntityType.GEO, identifierData)
605+
}
606+
524607
parseTagExpr() {
525608
assertToken(TokenType.TAG_EXPR, this.CurrentToken.T)
526609

@@ -627,6 +710,8 @@ function Parse(data: string): SearchExpr {
627710
return p.parseUnionExpr()
628711
} else if (p.CurrentToken.T === TokenType.TAG_EXPR) {
629712
return p.parseTagExpr()
713+
} else if (p.CurrentToken.T === TokenType.GEO_EXPR) {
714+
return p.parseGeoExpr()
630715
} else {
631716
return p.parseExpr()
632717
}

0 commit comments

Comments
 (0)