@@ -324,11 +324,16 @@ export default class Statement {
324
324
325
325
}
326
326
327
+ private static readonly BANNED_NAMES = [ `VALUES` ] ;
327
328
getObjectReferences ( ) : ObjectRef [ ] {
328
329
let list : ObjectRef [ ] = [ ] ;
329
330
330
331
const doAdd = ( ref ?: ObjectRef ) => {
331
- if ( ref ) list . push ( ref ) ;
332
+ if ( ref ) {
333
+ if ( ref . object . name && ! Statement . BANNED_NAMES . includes ( ref . object . name . toUpperCase ( ) ) ) {
334
+ list . push ( ref ) ;
335
+ }
336
+ }
332
337
}
333
338
334
339
const basicQueryFinder = ( startIndex : number ) : void => {
@@ -365,6 +370,14 @@ export default class Statement {
365
370
i += 3 ; //For the brackets
366
371
}
367
372
}
373
+ } else if ( currentClause === `from` && tokenIs ( this . tokens [ i ] , `function` ) ) {
374
+ const sqlObj = this . getRefAtToken ( i , { includeParameters : true } ) ;
375
+ if ( sqlObj ) {
376
+ i += sqlObj . tokens . length ;
377
+ if ( sqlObj . isUDTF || sqlObj . fromLateral ) {
378
+ i += 3 ; //For the brackets
379
+ }
380
+ }
368
381
}
369
382
}
370
383
}
@@ -538,18 +551,17 @@ export default class Statement {
538
551
return list ;
539
552
}
540
553
541
- private getRefAtToken ( i : number , options : { withSystemName ?: boolean } = { } ) : ObjectRef | undefined {
554
+ private getRefAtToken ( i : number , options : { withSystemName ?: boolean , includeParameters ?: boolean } = { } ) : ObjectRef | undefined {
542
555
let sqlObj : ObjectRef ;
543
556
544
557
let nextIndex = i ;
545
558
let nextToken = this . tokens [ i ] ;
546
559
547
560
let endIndex = i ;
548
561
549
- const isUDTF = tokenIs ( nextToken , `function` , `TABLE` ) ;
550
- const isLateral = tokenIs ( nextToken , `function` , `LATERAL` ) ;
562
+ const isSubSelect = tokenIs ( nextToken , `function` , `TABLE` ) || tokenIs ( nextToken , `function` , `LATERAL` ) || ( options . includeParameters && tokenIs ( nextToken , `function` ) ) ;
551
563
552
- if ( isUDTF ) {
564
+ if ( isSubSelect ) {
553
565
sqlObj = this . getRefAtToken ( i + 2 ) ;
554
566
if ( sqlObj ) {
555
567
sqlObj . isUDTF = true ;
@@ -563,14 +575,6 @@ export default class Statement {
563
575
nextIndex = - 1 ;
564
576
nextToken = undefined ;
565
577
}
566
- } else if ( isLateral ) {
567
- const blockTokens = this . getBlockAt ( nextToken . range . end + 1 ) ;
568
- const newStatement = new Statement ( blockTokens , { start : nextToken . range . start , end : blockTokens [ blockTokens . length - 1 ] . range . end } ) ;
569
- [ sqlObj ] = newStatement . getObjectReferences ( ) ;
570
-
571
- sqlObj . fromLateral = true ;
572
- nextIndex = i + 2 + blockTokens . length ;
573
- nextToken = this . tokens [ nextIndex ] ;
574
578
575
579
} else {
576
580
if ( nextToken && NameTypes . includes ( nextToken . type ) ) {
@@ -618,7 +622,7 @@ export default class Statement {
618
622
}
619
623
}
620
624
621
- if ( ! isUDTF ) {
625
+ if ( ! isSubSelect && ! sqlObj . isUDTF ) {
622
626
sqlObj . tokens = this . tokens . slice ( i , endIndex + 1 ) ;
623
627
}
624
628
0 commit comments