Skip to content

Commit d8b3889

Browse files
committed
Parse tags and display them in snippet region if available
1 parent 4732c09 commit d8b3889

File tree

4 files changed

+111
-20
lines changed

4 files changed

+111
-20
lines changed

redisinsight/ui/src/packages/ri-explain/src/Explain.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
215215
if (data) {
216216
const info = data.data as EntityInfo
217217

218+
if (!info.snippet && info.parentSnippet && info.data?.startsWith(info.parentSnippet)) {
219+
info.data = info.data.substr(info.parentSnippet.length)
220+
info.snippet = info.parentSnippet
221+
}
222+
218223
if (module === ModuleType.Graph) {
219224
info.recordsProduced = info.counter
220225
delete info.counter

redisinsight/ui/src/packages/ri-explain/src/Node.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ interface INodeProps {
1212

1313
export function ExplainNode(props: INodeProps) {
1414
const propData: EntityInfo = (props as any).node.getData()
15-
const { id, type, data, snippet } = propData
15+
const { id, type, data, snippet, subType } = propData
1616
return (
1717
<div className="ExplainContainer" id={`node-${id}`}>
1818
<div className="Main">
1919
<div className="Info">
2020
<div>{data ? data : type}</div>
21-
{type === EntityType.Expr && <div className="Type">text</div> }
21+
{subType && [EntityType.GEO, EntityType.NUMERIC, EntityType.TEXT, EntityType.TAG].includes(subType) && <div className="Type">{subType}</div> }
2222
</div>
2323
</div>
2424
{

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

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ enum TokenType {
99

1010
UNION = 'UNION',
1111
INTERSECT = 'INTERSECT',
12+
TAG_EXPR = 'TAG_EXPR',
1213
NUMERIC = 'NUMERIC',
1314
LBRACE = 'LBRACE',
1415
RBRACE = 'RBRACE',
@@ -46,6 +47,7 @@ const KEYWORDS = {
4647
[TokenType.ILLEGAL.toString()]: TokenType.ILLEGAL,
4748

4849
[TokenType.UNION.toString()]: TokenType.UNION,
50+
[TokenType.TAG_EXPR.toString()]: TokenType.TAG_EXPR,
4951
[TokenType.INTERSECT.toString()]: TokenType.INTERSECT,
5052
[TokenType.NUMERIC.toString()]: TokenType.NUMERIC,
5153

@@ -94,7 +96,7 @@ class Lexer {
9496
ReadIdentifier(): string {
9597
let str = ''
9698

97-
while (this.C !== undefined && isLetter(this.C)) {
99+
while (this.C !== undefined && (isLetter(this.C) || ['@', ':'].includes(this.C))) {
98100
str = str + this.C
99101
this.ReadChar()
100102
}
@@ -138,9 +140,6 @@ class Lexer {
138140
case '-':// TODO: This should be MINUS token
139141
t = new Token(TokenType.IDENTIFIER, this.C)
140142
break
141-
case '@':
142-
t = new Token(TokenType.IDENTIFIER, this.C)
143-
break
144143
case '<':
145144
let lPeekChar = this.PeekChar()
146145
if (lPeekChar !== null && lPeekChar === '=') {
@@ -173,9 +172,17 @@ class Lexer {
173172
t = new Token(TokenType.EOF, '')
174173
break
175174
default:
176-
if (this.C !== undefined && isLetter(this.C)) {
175+
if (this.C !== undefined && (isLetter(this.C) || ['@', ':'].includes(this.C))) {
177176
const literal = this.ReadIdentifier()
178177
let tokenType = KEYWORDS[literal] || TokenType.IDENTIFIER
178+
179+
if (literal.startsWith('TAG:')) {
180+
tokenType = TokenType.TAG_EXPR
181+
} else if (literal.startsWith('@') && literal.endsWith(':UNION')) {
182+
tokenType = TokenType.UNION
183+
} else if (literal.startsWith('@') && literal.endsWith(':INTERSECT')) {
184+
tokenType = TokenType.INTERSECT
185+
}
179186
t = new Token(tokenType, literal)
180187
return t
181188
} else if (this.C !== undefined && isDigit(this.C)) {
@@ -214,13 +221,15 @@ export enum EntityType {
214221
export interface EntityInfo {
215222
id: string
216223
type: EntityType,
224+
subType?: EntityType,
217225
data?: string
218226
snippet?: string
219227
children: EntityInfo[]
220228
time?: string
221229
counter?: string
222230
size?: string
223231
parentId?: string
232+
parentSnippet?: string
224233
level?: number
225234
recordsProduced?: string
226235
}
@@ -257,19 +266,32 @@ export function GetAncestors(info: EntityInfo, searchId: string, a: IAncestors):
257266

258267
class Expr {
259268
Core: string
260-
Type?: string
269+
Type: EntityType
270+
SubType: EntityType
261271
Time?: string
272+
Info?: string
262273

263-
constructor(expr: string) {
274+
constructor(expr: string, subType: EntityType, info: string | undefined = undefined) {
264275
this.Core = expr
276+
this.SubType = subType
277+
this.Info = info
265278
}
266279

267280
toJSON(): EntityInfo {
281+
282+
let snippet: string | undefined;
283+
284+
if (this.SubType === EntityType.TAG && this.Info?.startsWith('TAG:')) {
285+
snippet = this.Info?.substr(4)
286+
}
287+
268288
return {
269289
id: uuidv4(),
270290
// data: 'Expr',
271291
// snippet: this.Core,
272292
type: EntityType.Expr,
293+
subType: this.SubType,
294+
snippet: snippet,
273295
data: this.Core,
274296
children: [],
275297
time: this.Time,
@@ -312,34 +334,54 @@ type ExprTuple2 = SearchExpr[]
312334

313335
class IntersectExpr {
314336
Core: ExprTuple2
337+
Info?: string
315338

316-
constructor(e: ExprTuple2) {
339+
constructor(e: ExprTuple2, info?: string) {
317340
this.Core = e
341+
this.Info = info
318342
}
319343

320344
toJSON(): EntityInfo {
321345
const id = uuidv4()
346+
347+
let snippet: string | undefined;
348+
349+
if (!this.Info?.startsWith('INTERSECT')) {
350+
snippet = this.Info?.substring(0, this.Info.indexOf(':INTERSECT'))
351+
}
352+
322353
return {
323354
id,
324355
type: EntityType.INTERSECT,
325-
children: this.Core.map(x => x.toJSON()).map((d: EntityInfo) => ({...d, parentId: id})),
356+
snippet,
357+
children: this.Core.map(x => x.toJSON()).map((d: EntityInfo) => ({...d, parentId: id, parentSnippet: snippet})),
326358
}
327359
}
328360
}
329361

330362
class UnionExpr {
363+
Info?: string
331364
Core: ExprTuple2
332365

333-
constructor(e: ExprTuple2) {
366+
constructor(e: ExprTuple2, info?: string) {
334367
this.Core = e
368+
this.Info = info
335369
}
336370

337371
toJSON(): EntityInfo {
338372
const id = uuidv4()
373+
374+
let snippet: string | undefined;
375+
376+
if (!this.Info?.startsWith('UNION')) {
377+
snippet = this.Info?.substring(0, this.Info.indexOf(':UNION'))
378+
}
379+
339380
return {
340381
id,
341382
type: EntityType.UNION,
342-
children: this.Core.map(x => x.toJSON()).map((d: EntityInfo) => ({...d, parentId: id}))
383+
snippet,
384+
children: this.Core.map(x => x.toJSON()).map((d: EntityInfo) => ({...d, parentId: id, parentSnippet: snippet}))
343385
}
344386
}
345387
}
@@ -374,6 +416,8 @@ class Parser {
374416
this.CurrentToken = this.PeekToken
375417
this.PeekToken = this.L.NextToken()
376418

419+
console.log("NEXT TOKEN", this.CurrentToken)
420+
377421
if (this.CurrentToken.T === TokenType.EOF) {
378422
throw new Error("Didn't expect EOF token")
379423
}
@@ -383,6 +427,8 @@ class Parser {
383427

384428
assertToken(TokenType.INTERSECT, this.CurrentToken?.T)
385429

430+
let intersectData = this.CurrentToken.Data
431+
386432
this.nextToken()
387433

388434
assertToken(TokenType.LBRACE, this.CurrentToken?.T)
@@ -409,19 +455,23 @@ class Parser {
409455
Exprs.push(this.parseUnionExpr())
410456
} else if (this.CurrentToken.T === TokenType.INTERSECT) {
411457
Exprs.push(this.parseIntersectExpr())
458+
} else if (this.CurrentToken.T === TokenType.TAG_EXPR) {
459+
Exprs.push(this.parseTagExpr())
412460
}
413461

414462
this.nextToken()
415463
}
416464

417-
return new IntersectExpr(Exprs)
465+
return new IntersectExpr(Exprs, intersectData)
418466
}
419467

420468

421469
parseUnionExpr(): UnionExpr {
422470

423471
assertToken(TokenType.UNION, this.CurrentToken?.T)
424472

473+
let unionData = this.CurrentToken.Data
474+
425475
this.nextToken()
426476

427477
assertToken(TokenType.LBRACE, this.CurrentToken.T)
@@ -449,12 +499,14 @@ class Parser {
449499
Exprs.push(this.parseUnionExpr())
450500
} else if (this.CurrentToken.T === TokenType.INTERSECT) {
451501
Exprs.push(this.parseIntersectExpr())
502+
} else if (this.CurrentToken.T === TokenType.TAG_EXPR) {
503+
Exprs.push(this.parseTagExpr())
452504
}
453505

454506
this.nextToken()
455507
}
456508

457-
return new UnionExpr(Exprs)
509+
return new UnionExpr(Exprs, unionData)
458510
}
459511

460512
parseExpr() {
@@ -468,7 +520,40 @@ class Parser {
468520
this.nextToken()
469521
}
470522

471-
return new Expr(str)
523+
return new Expr(str, EntityType.TEXT)
524+
}
525+
526+
parseTagExpr() {
527+
assertToken(TokenType.TAG_EXPR, this.CurrentToken.T)
528+
529+
let tagData = this.CurrentToken.Data
530+
531+
this.nextToken()
532+
533+
assertToken(TokenType.LBRACE, this.CurrentToken.T)
534+
535+
this.nextToken()
536+
537+
assertToken(TokenType.NEW_LINE, this.CurrentToken?.T)
538+
539+
this.nextToken()
540+
541+
assertToken(TokenType.IDENTIFIER, this.CurrentToken?.T)
542+
543+
let identifier = this.CurrentToken.Data
544+
545+
this.nextToken()
546+
547+
assertToken(TokenType.NEW_LINE, this.CurrentToken?.T)
548+
549+
this.nextToken()
550+
551+
assertToken(TokenType.RBRACE, this.CurrentToken?.T)
552+
553+
this.nextToken()
554+
555+
return new Expr(identifier, EntityType.TAG, tagData)
556+
472557
}
473558

474559
parseNumericExpr() {
@@ -489,7 +574,7 @@ class Parser {
489574
let lsign = this.CurrentToken // TODO: Check sign
490575

491576
this.nextToken()
492-
577+
493578
assertToken(TokenType.IDENTIFIER, this.CurrentToken?.T)
494579

495580
let identifier = this.CurrentToken
@@ -524,8 +609,6 @@ class Parser {
524609

525610
return new NumericExpr(left !== 'inf' ? parseFloat(left) : Infinity, lsign, identifier, rsign, right !== 'inf' ? parseFloat(right) : Infinity)
526611
}
527-
528-
529612
}
530613

531614

@@ -540,6 +623,8 @@ function Parse(data: string): SearchExpr {
540623
return p.parseNumericExpr()
541624
} else if (p.CurrentToken.T === TokenType.UNION) {
542625
return p.parseUnionExpr()
626+
} else if (p.CurrentToken.T === TokenType.TAG_EXPR) {
627+
return p.parseTagExpr()
543628
} else {
544629
return p.parseExpr()
545630
}

redisinsight/ui/src/packages/ri-explain/src/styles/styles.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@
205205
display: flex;
206206
justify-content: space-between;
207207
.Type {
208-
color: #CE915B
208+
color: #CE915B;
209+
text-transform: lowercase;
209210
}
210211
}
211212

0 commit comments

Comments
 (0)