You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+51
Original file line number
Diff line number
Diff line change
@@ -357,6 +357,57 @@ Call the `getAllEntities` method on the SQL instance, and pass in the sql text a
357
357
358
358
Position is not required, if the position is passed, then in the collected entities, if the entity is located under the statement where the corresponding position is located, then the statement object to which the entity belongs will be marked with `isContainCaret`, which can help you quickly filter out the required entities when combined with the code completion function.
359
359
360
+
### Get semantic context information
361
+
362
+
Call the `getSemanticContextAtCaretPosition` method on the SQL instance, passing in the sql text and the line and column numbers at the specified position, for example:
363
+
364
+
```typescript
365
+
import { HiveSQL } from'dt-sql-parser';
366
+
367
+
consthive=newHiveSQL();
368
+
constsql='SELECT * FROM tb;';
369
+
constpos= { lineNumber:1, column:18 }; // after 'tb;'
Currently, the semantic context information that can be collected is as follows. If there are more requirements, please submit an [issue](https://github.com/DTStack/dt-sql-parser/issues).
386
+
387
+
- `isStatementBeginning` Whether the current input position is the beginning of a statement
388
+
389
+
The **default strategy** for `isStatementBeginning` is `SqlSplitStrategy.STRICT`
390
+
391
+
There are two optional strategies:
392
+
- `SqlSplitStrategy.STRICT` Strict strategy, only the statement delimiter `;` is used as the identifier for the end of the previous statement
393
+
- `SqlSplitStrategy.LOOSE` Loose strategy, based on the syntax parsing tree to split SQL
394
+
395
+
The difference between the two strategies:
396
+
For example, if the input SQL is:
397
+
```sql
398
+
CREATETABLEtb (id INT)
399
+
400
+
SELECT
401
+
```
402
+
In the `SqlSplitStrategy.STRICT` strategy, `isStatementBeginning` is `false`, because the CREATE statement is not terminated by a semicolon.
403
+
404
+
In the `SqlSplitStrategy.LOOSE` strategy, `isStatementBeginning` is `true`, because the syntax parsing tree splits the SQL into two independent statements: CREATE and SELECT.
405
+
406
+
You can set the strategy through the third `options` parameter:
0 commit comments