Skip to content

Commit 134586b

Browse files
committed
Fix for brakcets not taken into account
Signed-off-by: worksofliam <[email protected]>
1 parent 103f43f commit 134586b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/language/sql/statement.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ export default class Statement {
330330
if (sqlObj) {
331331
doAdd(sqlObj);
332332
i += sqlObj.tokens.length;
333+
if (sqlObj.isUDTF || sqlObj.fromLateral) {
334+
i += 3; //For the brackets
335+
}
333336
}
334337
}
335338
}
@@ -520,6 +523,7 @@ export default class Statement {
520523
if (sqlObj) {
521524
sqlObj.isUDTF = true;
522525
const blockTokens = this.getBlockAt(sqlObj.tokens[0].range.end);
526+
523527
sqlObj.tokens = blockTokens;
524528
nextIndex = i + 2 + blockTokens.length;
525529
nextToken = this.tokens[nextIndex];
@@ -529,12 +533,11 @@ export default class Statement {
529533
nextToken = undefined;
530534
}
531535
} else if (isLateral) {
532-
console.log(`HI`);
533536
const blockTokens = this.getBlockAt(nextToken.range.end+1);
534-
console.log(blockTokens);
535537
const newStatement = new Statement(blockTokens, {start: nextToken.range.start, end: blockTokens[blockTokens.length-1].range.end});
536538
[sqlObj] = newStatement.getObjectReferences();
537-
539+
540+
sqlObj.fromLateral = true;
538541
nextIndex = i + 2 + blockTokens.length;
539542
nextToken = this.tokens[nextIndex];
540543

src/language/sql/tests/statements.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,24 @@ describe(`Object references`, () => {
996996
].join(`\n`);
997997

998998
const document = new Document(lines);
999+
1000+
expect(document.statements.length).toBe(1);
1001+
1002+
const statement = document.statements[0];
1003+
1004+
expect(statement.type).toBe(StatementType.Select);
1005+
1006+
const refs = statement.getObjectReferences();
1007+
1008+
console.log(refs);
1009+
expect(refs.length).toBe(2);
1010+
expect(refs[0].object.name).toBe(`OBJECT_STATISTICS`);
1011+
expect(refs[0].object.schema).toBe(`QSYS2`);
1012+
expect(refs[0].alias).toBe(`a`);
1013+
1014+
expect(refs[1].object.name).toBe(`OBJECT_STATISTICS`);
1015+
expect(refs[1].object.schema).toBe(`QSYS2`);
1016+
expect(refs[1].alias).toBe(`b`);
9991017
})
10001018
});
10011019

src/language/sql/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface ObjectRef {
8484
alias?: string;
8585

8686
isUDTF?: boolean;
87+
fromLateral?: boolean;
8788

8889
/** only used within create statements */
8990
createType?: string;

0 commit comments

Comments
 (0)