Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/parser/trino/trinoErrorListener.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { CodeCompletionCore } from 'antlr4-c3';
import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
import { Parser, Token } from 'antlr4ng';

import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
import { LOCALE_TYPE } from '../common/types';

export class TrinoErrorListener extends ParseErrorListener {
private preferredRules: Set<number>;

private objectNames: Map<number, string> = new Map([
[TrinoSqlParser.RULE_catalogName, 'catalog'],
[TrinoSqlParser.RULE_catalogRef, 'catalog'],
[TrinoSqlParser.RULE_catalogNameCreate, 'catalog'],
[TrinoSqlParser.RULE_tableName, 'table'],
[TrinoSqlParser.RULE_tableRef, 'table'],
[TrinoSqlParser.RULE_tableNameCreate, 'table'],
[TrinoSqlParser.RULE_viewName, 'view'],
[TrinoSqlParser.RULE_viewRef, 'view'],
[TrinoSqlParser.RULE_viewNameCreate, 'view'],
[TrinoSqlParser.RULE_schemaName, 'schema'],
[TrinoSqlParser.RULE_schemaRef, 'schema'],
[TrinoSqlParser.RULE_schemaNameCreate, 'schema'],
[TrinoSqlParser.RULE_functionName, 'function'],
[TrinoSqlParser.RULE_columnName, 'column'],
[TrinoSqlParser.RULE_columnRef, 'column'],
[TrinoSqlParser.RULE_columnNameCreate, 'column'],
]);

Expand Down Expand Up @@ -45,12 +46,12 @@ export class TrinoErrorListener extends ParseErrorListener {
const [ruleType] = candidate;
const name = this.objectNames.get(ruleType);
switch (ruleType) {
case TrinoSqlParser.RULE_catalogName:
case TrinoSqlParser.RULE_schemaName:
case TrinoSqlParser.RULE_tableName:
case TrinoSqlParser.RULE_viewName:
case TrinoSqlParser.RULE_catalogRef:
case TrinoSqlParser.RULE_schemaRef:
case TrinoSqlParser.RULE_tableRef:
case TrinoSqlParser.RULE_viewRef:
case TrinoSqlParser.RULE_functionName:
case TrinoSqlParser.RULE_columnName: {
case TrinoSqlParser.RULE_columnRef: {
result.push(`{existing}${name}`);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions test/parser/mysql/contextCollect/entityCollector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ describe('MySQL entity collector tests', () => {
startIndex: 1057,
startLine: 41,
});

expect(functionEntity.columns).toBeNull();
expect(functionEntity.relatedEntities).toBeNull();
if (isFuncEntityContext(functionEntity)) {
expect(functionEntity.relatedEntities).toBeNull();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('PostgreSql entity collector tests', () => {
endColumn: 2,
});
if (isCommonEntityContext(tableCreateEntity)) {
expect(tableCreateEntity.columns.length).toBe(3);
expect(tableCreateEntity.columns.length).toBe(2);
tableCreateEntity.columns.forEach((columEntity) => {
expect(columEntity.entityContextType).toBe(EntityContextType.COLUMN_CREATE);
expect(columEntity.belongStmt).toBe(tableCreateEntity.belongStmt);
Expand Down
Loading