Compare commits
No commits in common. "b1c8a64804785e208642a5bf061f5b0cb800bdad" and "a63b373baec2296f5af98f0095dac5297c3ad100" have entirely different histories.
b1c8a64804
...
a63b373bae
10
README.md
10
README.md
@ -55,7 +55,7 @@ console.log(result)
|
||||
|
||||
**Notice: A rule must start with a/an statement/entity and stop with an entity. You should add a node keywords(keyword is in your parser with format: `RULE_[keyword]`) into stmts/entities before using it.**
|
||||
|
||||
## Rule Chain Operator
|
||||
## Rule Chain Opeator
|
||||
|
||||
You can set a negative number whose abs equals to a ruleIndex. That means exclude this rule.
|
||||
|
||||
@ -75,20 +75,18 @@ select_target_alias: [
|
||||
|
||||
Some node names in dt-sql-parser code are different from their antlr4's definition.
|
||||
|
||||
Example:
|
||||
You can find possible alias in https://github.com/DTStack/dt-sql-parser/blob/main/src/grammar/postgresql/PostgreSqlParser.g4, then add it into `alias` option.
|
||||
|
||||
Example:
|
||||
![alt text](./assets/alias-example.png)
|
||||
|
||||
You can find possible alias in https://github.com/DTStack/dt-sql-parser/blob/main/src/grammar/postgresql/PostgreSqlParser.g4, then add it into `alias` option.
|
||||
|
||||
## Add a preprocessor
|
||||
|
||||
```typescript
|
||||
const myPlugin = new DtSqlParserSemAnalysePlugin({
|
||||
preprocessor: [
|
||||
(sql) => sql.toUpperCase(),
|
||||
...
|
||||
]
|
||||
(sql) => sql.toUpperCase()
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
<script type="module">
|
||||
const { DtSqlParserSemAnalysePlugin } = await import(/* @vite-ignore */import.meta.env.VITE_ENTRY_PATH)
|
||||
const myPlugin = new DtSqlParserSemAnalysePlugin()
|
||||
const sql = 'CREATE TABLE "public"."h1" (c1 int8 not null, c2 int8, c3 int8) with (appendonly = true, orientation = horc) TABLESPACE horc_default DISTRIBUTED BY (|)'
|
||||
const sql = 'SELECT a.| AS c'
|
||||
const caretColumn = sql.indexOf('|') + 1
|
||||
const result = myPlugin.parse(sql.replace('|', ''), { lineNumber: 1, columnNumber: caretColumn })
|
||||
console.log(result)
|
||||
|
13
package-lock.json
generated
13
package-lock.json
generated
@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "dt-sql-parser-semantic-analyse-plugin",
|
||||
"version": "0.0.1-alpha.14",
|
||||
"version": "0.0.1-alpha.7",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "dt-sql-parser-semantic-analyse-plugin",
|
||||
"version": "0.0.1-alpha.14",
|
||||
"version": "0.0.1-alpha.6",
|
||||
"dependencies": {
|
||||
"dt-sql-parser": "npm:dt-sql-parser-oushudb@^4.0.2-5"
|
||||
"dt-sql-parser": "^4.0.0-beta.4.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.0.2",
|
||||
@ -1904,10 +1904,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/dt-sql-parser": {
|
||||
"name": "dt-sql-parser-oushudb",
|
||||
"version": "4.0.2-5",
|
||||
"resolved": "http://npm.oushu.com:14837/dt-sql-parser-oushudb/-/dt-sql-parser-oushudb-4.0.2-5.tgz",
|
||||
"integrity": "sha512-fHu00/+Mk+QtCrS24Uc1vYV3xsy8BxyLyD0Oh4/TJwhBq7U+ZWunjHzcQBMccPyb8JnTYcG/HZ/f5EZ2GqQG4Q==",
|
||||
"version": "4.0.0-beta.4.12",
|
||||
"resolved": "http://npm.oushu.com:14837/dt-sql-parser/-/dt-sql-parser-4.0.0-beta.4.12.tgz",
|
||||
"integrity": "sha512-kfLRecn+dfdZjrKt3Ovm52ryoh9UGF+dCjNzV2pk8XI5kgF7lgQJhPZdRi+2yn1AU/BWQ1/0E6LnvFYbZ7Wr9Q==",
|
||||
"dependencies": {
|
||||
"antlr4-c3": "3.3.7",
|
||||
"antlr4ng": "2.0.11"
|
||||
|
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lava-dt-sql-parser-semantic-analyse-plugin",
|
||||
"version": "0.0.1-alpha.16",
|
||||
"name": "dt-sql-parser-semantic-analyse-plugin",
|
||||
"version": "0.0.1-alpha.8",
|
||||
"description": "an dt-sql-parser plugin with semantic result",
|
||||
"type": "module",
|
||||
"files": [
|
||||
@ -37,11 +37,6 @@
|
||||
"vite-plugin-node-polyfills": "^0.21.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"dt-sql-parser": "npm:lava-oushudb-dt-sql-parser@^4.0.2-10"
|
||||
},
|
||||
"git repository": "https://git.yevpt.com/oushu/lava-dt-sql-parser-semantic-analyse-plugin",
|
||||
"repository": "https://git.yevpt.com/oushu/lava-dt-sql-parser-semantic-analyse-plugin",
|
||||
"volta": {
|
||||
"node": "14.21.3"
|
||||
"dt-sql-parser": "^4.0.0-beta.4.12"
|
||||
}
|
||||
}
|
||||
|
@ -2,104 +2,25 @@ import { PostgreSqlParser } from 'dt-sql-parser/dist/lib/postgresql/PostgreSqlPa
|
||||
|
||||
export const defaultAlias = {
|
||||
selectstmt: 'selectStatement',
|
||||
insertstmt: 'insertStatement',
|
||||
target_el: 'target_label',
|
||||
table_name: 'tableName',
|
||||
view_name: 'viewName',
|
||||
column_name: 'columnName',
|
||||
schema_name: 'schemaName'
|
||||
target_el: 'target_label'
|
||||
}
|
||||
|
||||
export const defaultStmts = [
|
||||
'selectstmt',
|
||||
'insertstmt',
|
||||
'updatestmt',
|
||||
'deletestmt',
|
||||
'altertablestmt',
|
||||
'alterfunctionstmt',
|
||||
'dropstmt',
|
||||
'createfunctionstmt'
|
||||
'simple_select',
|
||||
]
|
||||
|
||||
export const defaultEntities = [
|
||||
'target_el',
|
||||
'colid',
|
||||
'attr_name',
|
||||
'collabel',
|
||||
'table_name',
|
||||
'view_name',
|
||||
'function_with_argtypes',
|
||||
'column_name',
|
||||
'schema_name',
|
||||
'anysconst'
|
||||
'collabel'
|
||||
]
|
||||
|
||||
export const defaultRules: Record<string, number[]> = {
|
||||
select_target: [
|
||||
PostgreSqlParser.RULE_selectstmt,
|
||||
PostgreSqlParser.RULE_simple_select,
|
||||
PostgreSqlParser.RULE_target_el,
|
||||
],
|
||||
select_from_table: [
|
||||
PostgreSqlParser.RULE_selectstmt,
|
||||
PostgreSqlParser.RULE_from_clause,
|
||||
PostgreSqlParser.RULE_table_name
|
||||
],
|
||||
insert_target_table: [
|
||||
PostgreSqlParser.RULE_insertstmt,
|
||||
PostgreSqlParser.RULE_insert_target,
|
||||
PostgreSqlParser.RULE_table_name
|
||||
],
|
||||
update_relation_table: [
|
||||
PostgreSqlParser.RULE_updatestmt,
|
||||
PostgreSqlParser.RULE_relation_expr,
|
||||
PostgreSqlParser.RULE_table_name
|
||||
],
|
||||
delete_relation_table: [
|
||||
PostgreSqlParser.RULE_deletestmt,
|
||||
PostgreSqlParser.RULE_relation_expr,
|
||||
PostgreSqlParser.RULE_table_name
|
||||
],
|
||||
alter_table: [
|
||||
PostgreSqlParser.RULE_altertablestmt,
|
||||
PostgreSqlParser.RULE_relation_expr,
|
||||
PostgreSqlParser.RULE_table_name
|
||||
],
|
||||
alter_view: [
|
||||
PostgreSqlParser.RULE_altertablestmt,
|
||||
PostgreSqlParser.RULE_view_name
|
||||
],
|
||||
alter_function: [
|
||||
PostgreSqlParser.RULE_alterfunctionstmt,
|
||||
PostgreSqlParser.RULE_alterFunctionTypeClause,
|
||||
PostgreSqlParser.RULE_function_with_argtypes
|
||||
],
|
||||
alter_table_drop_column: [
|
||||
PostgreSqlParser.RULE_altertablestmt,
|
||||
PostgreSqlParser.RULE_alter_table_cmds,
|
||||
PostgreSqlParser.RULE_column_name
|
||||
],
|
||||
drop_table: [
|
||||
PostgreSqlParser.RULE_dropstmt,
|
||||
PostgreSqlParser.RULE_table_name_list,
|
||||
PostgreSqlParser.RULE_table_name
|
||||
],
|
||||
drop_view: [
|
||||
PostgreSqlParser.RULE_dropstmt,
|
||||
PostgreSqlParser.RULE_view_nameList,
|
||||
PostgreSqlParser.RULE_view_name
|
||||
],
|
||||
drop_schema: [
|
||||
PostgreSqlParser.RULE_dropstmt,
|
||||
PostgreSqlParser.RULE_schema_name_list,
|
||||
PostgreSqlParser.RULE_schema_name
|
||||
],
|
||||
create_function_sub_content: [
|
||||
PostgreSqlParser.RULE_createfunctionstmt,
|
||||
PostgreSqlParser.RULE_createfunc_opt_list,
|
||||
PostgreSqlParser.RULE_colid,
|
||||
PostgreSqlParser.RULE_anysconst,
|
||||
],
|
||||
// sub entities
|
||||
select_target_colid: [
|
||||
PostgreSqlParser.RULE_target_el,
|
||||
PostgreSqlParser.RULE_function_name,
|
||||
@ -114,37 +35,5 @@ export const defaultRules: Record<string, number[]> = {
|
||||
PostgreSqlParser.RULE_target_el,
|
||||
-PostgreSqlParser.RULE_attr_name,
|
||||
PostgreSqlParser.RULE_collabel
|
||||
],
|
||||
table_name_colid: [
|
||||
PostgreSqlParser.RULE_table_name,
|
||||
PostgreSqlParser.RULE_colid
|
||||
],
|
||||
table_name_attr: [
|
||||
PostgreSqlParser.RULE_table_name,
|
||||
PostgreSqlParser.RULE_attr_name,
|
||||
],
|
||||
view_name_colid: [
|
||||
PostgreSqlParser.RULE_view_name,
|
||||
PostgreSqlParser.RULE_colid
|
||||
],
|
||||
view_name_attr: [
|
||||
PostgreSqlParser.RULE_view_name,
|
||||
PostgreSqlParser.RULE_attr_name,
|
||||
],
|
||||
function_colid: [
|
||||
PostgreSqlParser.RULE_function_with_argtypes,
|
||||
PostgreSqlParser.RULE_colid
|
||||
],
|
||||
function_attr: [
|
||||
PostgreSqlParser.RULE_function_with_argtypes,
|
||||
PostgreSqlParser.RULE_attr_name,
|
||||
],
|
||||
column_name_colid: [
|
||||
PostgreSqlParser.RULE_column_name,
|
||||
PostgreSqlParser.RULE_colid
|
||||
],
|
||||
column_name_attr: [
|
||||
PostgreSqlParser.RULE_column_name,
|
||||
PostgreSqlParser.RULE_attr_name,
|
||||
]
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ export class SQLVisitor extends AbstractParseTreeVisitor<void> implements Postgr
|
||||
if (!beginStmt.relatedEntities[rule]) beginStmt.relatedEntities[rule] = []
|
||||
beginStmt.relatedEntities[rule].push(result)
|
||||
}
|
||||
if (beginStmt && withCaret(ctx)) this.result.nerestCaretEntityList.push(result)
|
||||
if (withCaret(ctx)) this.result.nerestCaretEntityList.push(result)
|
||||
this.entityStack.push(result)
|
||||
isHitRule = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user