Skip to content

Commit cd3626c

Browse files
author
zhaoge
committed
Merge branch 'next' into feat/emptyColumn
2 parents 3101b0e + ff81038 commit cd3626c

6 files changed

Lines changed: 52 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [4.5.0-beta.0](https://github.com/DTStack/dt-sql-parser/compare/v4.4.1...v4.5.0-beta.0) (2025-12-30)
6+
7+
8+
### Features
9+
10+
* support query result and derived table entity collecting ([#434](https://github.com/DTStack/dt-sql-parser/issues/434)) ([a176253](https://github.com/DTStack/dt-sql-parser/commit/a176253799b514fcd169c82f2706c2fe2810d85c))
11+
12+
### [4.4.1](https://github.com/DTStack/dt-sql-parser/compare/v4.4.0...v4.4.1) (2025-12-22)
13+
14+
### Bug Fixes
15+
16+
* **trino:** add selectItem rule to candidates for column suggestions ([81a361f](https://github.com/DTStack/dt-sql-parser/commit/81a361fb8e45e81c8826cba212f0007443bf12b5))
17+
518
## [4.4.0](https://github.com/DTStack/dt-sql-parser/compare/v4.4.0-beta.0...v4.4.0) (2025-11-26)
619

720
## [4.4.0-beta.0](https://github.com/DTStack/dt-sql-parser/compare/v4.3.1...v4.4.0-beta.0) (2025-11-18)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dt-sql-parser",
3-
"version": "4.4.0",
3+
"version": "4.5.0-beta.0",
44
"authors": "DTStack Corporation",
55
"description": "SQL Parsers for BigData, built with antlr4",
66
"keywords": [

src/parser/common/basicSQL.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1+
import { CandidatesCollection, CodeCompletionCore } from 'antlr4-c3';
12
import {
2-
Lexer,
3-
Token,
3+
ANTLRErrorListener,
4+
CharStream,
45
CharStreams,
56
CommonTokenStream,
6-
CharStream,
7+
Lexer,
8+
Parser,
79
ParserRuleContext,
8-
ParseTreeWalker,
910
ParseTreeListener,
11+
ParseTreeWalker,
1012
PredictionMode,
11-
ANTLRErrorListener,
12-
Parser,
13+
Token,
1314
} from 'antlr4ng';
14-
import { CandidatesCollection, CodeCompletionCore } from 'antlr4-c3';
15+
1516
import { SQLParserBase } from '../../lib/SQLParserBase';
17+
import type { EntityCollector } from './entityCollector';
18+
import { EntityContext } from './entityCollector';
19+
import { ErrorStrategy } from './errorStrategy';
1620
import { findCaretTokenIndex } from './findCaretTokenIndex';
17-
import { ctxToText, tokenToWord, WordRange, TextSlice } from './textAndWord';
21+
import { ErrorListener, ParseError } from './parseErrorListener';
22+
import SemanticContextCollector from './semanticContextCollector';
23+
import type { SplitListener } from './splitListener';
24+
import { ctxToText, TextSlice, tokenToWord, WordRange } from './textAndWord';
1825
import {
1926
CaretPosition,
2027
LOCALE_TYPE,
2128
SemanticCollectOptions,
2229
Suggestions,
2330
SyntaxSuggestion,
2431
} from './types';
25-
import { ParseError, ErrorListener } from './parseErrorListener';
26-
import { ErrorStrategy } from './errorStrategy';
27-
import type { SplitListener } from './splitListener';
28-
import type { EntityCollector } from './entityCollector';
29-
import { EntityContext } from './entityCollector';
30-
import SemanticContextCollector from './semanticContextCollector';
3132

3233
export const SQL_SPLIT_SYMBOL_TEXT = ';';
3334

src/parser/trino/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlPa
136136
}
137137
case TrinoSqlParser.RULE_columnName: {
138138
if (
139+
candidateRule.ruleList.includes(TrinoSqlParser.RULE_selectItem) ||
139140
candidateRule.ruleList.includes(TrinoSqlParser.RULE_groupBy) ||
140141
candidateRule.ruleList.includes(TrinoSqlParser.RULE_sortItem) ||
141142
candidateRule.ruleList.includes(TrinoSqlParser.RULE_whereClause) ||

test/parser/trino/suggestion/fixtures/syntaxSuggestion.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ SELECT * FROM users CROSS JOIN UNNEST(friends) WITH ordinality;
6161
SELECT FROM tb1;
6262

6363
SELECT age FROM tb1;
64+
65+
SELECT a. FROM tb1 a;

test/parser/trino/suggestion/syntaxSuggestion.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { TrinoSQL } from 'src/parser/trino';
43
import { CaretPosition, EntityContextType } from 'src/parser/common/types';
4+
import { TrinoSQL } from 'src/parser/trino';
55
import { commentOtherLine } from 'test/helper';
66

77
const syntaxSql = fs.readFileSync(
@@ -598,6 +598,25 @@ describe('Trino SQL Syntax Suggestion', () => {
598598
).toEqual([['age'], ['age']]);
599599
});
600600

601+
test('Select alias column', () => {
602+
const pos: CaretPosition = {
603+
lineNumber: 65,
604+
column: 10,
605+
};
606+
const syntaxes = trino.getSuggestionAtCaretPosition(
607+
commentOtherLine(syntaxSql, pos.lineNumber),
608+
pos
609+
)?.syntax;
610+
611+
const wordRangesArr = syntaxes?.map((syn) => syn.wordRanges);
612+
613+
expect(wordRangesArr).not.toBeUndefined();
614+
expect(wordRangesArr.length).toBe(1);
615+
expect(
616+
wordRangesArr.map((wordRanges) => wordRanges.map((wordRange) => wordRange.text))
617+
).toEqual([['a', '.']]);
618+
});
619+
601620
test('Syntax suggestion after a comment', () => {
602621
const sql = `-- the comment\nSELECT * FROM db.`;
603622
const pos: CaretPosition = {

0 commit comments

Comments
 (0)