Skip to content

Commit

Permalink
feat: Support CREATE TABLE with ENGINE syntax for ClickHouse (#78)
Browse files Browse the repository at this point in the history
* feat: separate clickhouse parser

* refactor: copy create table jison file to the clickhouse parser

* refactor: copy jisonlex

* feat: add engine token

* feat: support engine for create table syntax

* refactor: copy explain jison file to fix tests

* fix: fix test

* feat: add parseClickhouse method

* fix: fix invalid suggestion value

* feat: add engine suggestion

* feat: add test cases

* feat: generated parsers

* feat: support functions for engine declaration

* feat: add engine types to the lexer

* feat: strict engine types

* feat: suggest engine types

* feat: add postgresql into engine suggestions and add test case

* refactor: fixes

* refactor: remove comments
  • Loading branch information
viladimiru authored Aug 11, 2023
1 parent a0f8a0c commit 759b642
Show file tree
Hide file tree
Showing 15 changed files with 8,018 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"postinstall": "if [ -e src/generator ]; then cd src/generator && npm install; fi",
"test": "npm run generate && npm run test_without_generate",
"test_without_generate": "jest src/parsing",
"generate": "cd src/generator && node main.js generic postgresql",
"generate": "cd src/generator && node main.js generic postgresql clickhouse",
"lint": "npm run prettier -- --check",
"fix": "npm run prettier -- --write",
"prettier": "prettier \"**/*.{md,yaml,yml,json}\"",
Expand Down
24 changes: 20 additions & 4 deletions src/parsing/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {genericAutocompleteParser} from './parsers/generic/genericAutocompleteParser';
import {postgresqlAutocompleteParser} from './parsers/postgresql/postgresqlAutocompleteParser';
import {clickhouseAutocompleteParser} from './parsers/clickhouse/clickhouseAutocompleteParser';

export const cursorSymbol = '†';

Expand Down Expand Up @@ -33,6 +34,10 @@ export interface ParseResult {
suggestGroupBys?: unknown;
suggestIdentifiers?: IdentifierSuggestion[];
suggestTemplates?: boolean;
suggestEngines?: {
engines: string[],
functionalEngines: string[]
};
}

export type StatementPart =
Expand Down Expand Up @@ -121,9 +126,7 @@ export function parseGenericSql(queryBeforeCursor: string, queryAfterCursor: str
}

export function parseGenericSqlWithoutCursor(query: string): ParseResult {
// If our finished query is "SELECT * FROM|" and we try to parse it, parser thinks that we still haven't finished writing it and doesn't show some errors.
// In order to truly complete a finished query, we need to add space to it like so "SELECT * FROM |".
return parseGenericSql(query + ' ', '');
return parseGenericSql(getFinishedQuery(query), '');
}

export function parsePostgreSql(queryBeforeCursor: string, queryAfterCursor: string): ParseResult {
Expand All @@ -132,7 +135,20 @@ export function parsePostgreSql(queryBeforeCursor: string, queryAfterCursor: str
}

export function parsePostgreSqlWithoutCursor(query: string): ParseResult {
return parsePostgreSql(getFinishedQuery(query), '');
}

export function parseClickHouse(queryBeforeCursor: string, queryAfterCursor: string): ParseResult {
let parser = clickhouseAutocompleteParser as Parser;
return parser.parseSql(queryBeforeCursor, queryAfterCursor);
}

export function parseClickHouseWithoutCursor(query: string): ParseResult {
return parseClickHouse(getFinishedQuery(query), '');
}

function getFinishedQuery(query: string): string {
// If our finished query is "SELECT * FROM|" and we try to parse it, parser thinks that we still haven't finished writing it and doesn't show some errors.
// In order to truly complete a finished query, we need to add space to it like so "SELECT * FROM |".
return parsePostgreSql(query + ' ', '');
return query + ' ';
}
3,981 changes: 3,981 additions & 0 deletions src/parsing/parsers/clickhouse/clickhouseAutocompleteParser.js

Large diffs are not rendered by default.

Loading

0 comments on commit 759b642

Please sign in to comment.