dt-sql-parser 4.5.1-beta.2 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -263,6 +263,18 @@ Call the `getAllEntities` method on the SQL instance, pass the SQL content and t
263
263
  [ 'CATALOG', 'FUNCTION', 'TEMPORARY', 'VIEW', 'DATABASE', 'TABLE' ]
264
264
  */
265
265
  ```
266
+
267
+ Use the optional `keywordFilter` to remove unwanted keyword candidates. Return `true` to keep a keyword and `false` to remove it.
268
+
269
+ ```typescript
270
+ const sql = 'SELECT * FROM tb ';
271
+ const pos = { lineNumber: 1, column: sql.length + 1 };
272
+ const excludedKeywords = new Set(['WHERE', 'ORDER BY']);
273
+ const keywords = flink.getSuggestionAtCaretPosition(sql, pos, {
274
+ keywordFilter: (keyword) => !excludedKeywords.has(keyword),
275
+ })?.keywords;
276
+ ```
277
+
266
278
  + **Obtaining information related to grammar completion**
267
279
  ```javascript
268
280
  import { FlinkSQL } from 'dt-sql-parser';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { MySQL, FlinkSQL, SparkSQL, HiveSQL, PostgreSQL, TrinoSQL, ImpalaSQL, Ge
2
2
  export { MySqlParserListener, MySqlParserVisitor, FlinkSqlParserListener, FlinkSqlParserVisitor, SparkSqlParserListener, SparkSqlParserVisitor, HiveSqlParserListener, HiveSqlParserVisitor, PostgreSqlParserListener, PostgreSqlParserVisitor, TrinoSqlListener, TrinoSqlVisitor, ImpalaSqlParserListener, ImpalaSqlParserVisitor, GenericSqlListener, GenericSqlVisitor, } from './lib';
3
3
  export { EntityContextType } from './parser/common/types';
4
4
  export { StmtContextType } from './parser/common/entityCollector';
5
- export type { CaretPosition, Suggestions, SyntaxSuggestion } from './parser/common/types';
5
+ export type { CaretPosition, SuggestionOptions, Suggestions, SyntaxSuggestion, } from './parser/common/types';
6
6
  export type { WordRange, TextSlice } from './parser/common/textAndWord';
7
7
  export type { SyntaxError, ParseError, ErrorListener } from './parser/common/parseErrorListener';
8
8
  export type { GenericSQLOptions } from './parser/generic';
@@ -17,4 +17,13 @@ export declare abstract class SQLParserBase<T = antlr.ParserRuleContext> extends
17
17
  * prediction in non-entity-collecting contexts.
18
18
  */
19
19
  shouldMatchEmpty(ruleName?: string): boolean;
20
+ /**
21
+ * Semantic predicate to check whether the previous token and the next token
22
+ * are adjacent (no whitespace in between).
23
+ *
24
+ * Used to support hyphens inside Hive SET config property names, e.g.
25
+ * `set tez.grouping.max-size = 1`, while still rejecting invalid spacing
26
+ * like `set hive.a - b = 1`.
27
+ */
28
+ isNextTokenAdjacent(): boolean;
20
29
  }
@@ -46,4 +46,19 @@ export class SQLParserBase extends antlr.Parser {
46
46
  // This allows ANTLR to report errors naturally
47
47
  return false;
48
48
  }
49
+ /**
50
+ * Semantic predicate to check whether the previous token and the next token
51
+ * are adjacent (no whitespace in between).
52
+ *
53
+ * Used to support hyphens inside Hive SET config property names, e.g.
54
+ * `set tez.grouping.max-size = 1`, while still rejecting invalid spacing
55
+ * like `set hive.a - b = 1`.
56
+ */
57
+ isNextTokenAdjacent() {
58
+ const previousToken = this.tokenStream.LT(-1);
59
+ const nextToken = this.tokenStream.LT(1);
60
+ return (previousToken !== null &&
61
+ nextToken !== null &&
62
+ previousToken.stop + 1 === nextToken.start);
63
+ }
49
64
  }
@@ -774,30 +774,32 @@ export declare class HiveSqlParser extends SQLParserBase {
774
774
  static readonly RULE_principalIdentifier = 329;
775
775
  static readonly RULE_nonReserved = 330;
776
776
  static readonly RULE_sql11ReservedKeywordsUsedAsFunctionName = 331;
777
- static readonly RULE_configPropertiesItem = 332;
778
- static readonly RULE_resourcePlanDdlStatements = 333;
779
- static readonly RULE_mappingTypes = 334;
780
- static readonly RULE_rpAssign = 335;
781
- static readonly RULE_rpAssignList = 336;
782
- static readonly RULE_rpUnassign = 337;
783
- static readonly RULE_activate = 338;
784
- static readonly RULE_enable = 339;
785
- static readonly RULE_disable = 340;
786
- static readonly RULE_year = 341;
787
- static readonly RULE_month = 342;
788
- static readonly RULE_week = 343;
789
- static readonly RULE_day = 344;
790
- static readonly RULE_hour = 345;
791
- static readonly RULE_minute = 346;
792
- static readonly RULE_second = 347;
793
- static readonly RULE_decimal = 348;
794
- static readonly RULE_emptyColumn = 349;
795
- static readonly RULE_poolPath = 350;
796
- static readonly RULE_poolPathAllowEmpty = 351;
797
- static readonly RULE_triggerAtomExpression = 352;
798
- static readonly RULE_triggerActionExpression = 353;
799
- static readonly RULE_poolAssign = 354;
800
- static readonly RULE_poolAssignList = 355;
777
+ static readonly RULE_configProperty = 332;
778
+ static readonly RULE_configPropertyPart = 333;
779
+ static readonly RULE_configPropertiesItem = 334;
780
+ static readonly RULE_resourcePlanDdlStatements = 335;
781
+ static readonly RULE_mappingTypes = 336;
782
+ static readonly RULE_rpAssign = 337;
783
+ static readonly RULE_rpAssignList = 338;
784
+ static readonly RULE_rpUnassign = 339;
785
+ static readonly RULE_activate = 340;
786
+ static readonly RULE_enable = 341;
787
+ static readonly RULE_disable = 342;
788
+ static readonly RULE_year = 343;
789
+ static readonly RULE_month = 344;
790
+ static readonly RULE_week = 345;
791
+ static readonly RULE_day = 346;
792
+ static readonly RULE_hour = 347;
793
+ static readonly RULE_minute = 348;
794
+ static readonly RULE_second = 349;
795
+ static readonly RULE_decimal = 350;
796
+ static readonly RULE_emptyColumn = 351;
797
+ static readonly RULE_poolPath = 352;
798
+ static readonly RULE_poolPathAllowEmpty = 353;
799
+ static readonly RULE_triggerAtomExpression = 354;
800
+ static readonly RULE_triggerActionExpression = 355;
801
+ static readonly RULE_poolAssign = 356;
802
+ static readonly RULE_poolAssignList = 357;
801
803
  static readonly literalNames: (string | null)[];
802
804
  static readonly symbolicNames: (string | null)[];
803
805
  static readonly ruleNames: string[];
@@ -1140,6 +1142,8 @@ export declare class HiveSqlParser extends SQLParserBase {
1140
1142
  principalIdentifier(): PrincipalIdentifierContext;
1141
1143
  nonReserved(): NonReservedContext;
1142
1144
  sql11ReservedKeywordsUsedAsFunctionName(): Sql11ReservedKeywordsUsedAsFunctionNameContext;
1145
+ configProperty(): ConfigPropertyContext;
1146
+ configPropertyPart(): ConfigPropertyPartContext;
1143
1147
  configPropertiesItem(): ConfigPropertiesItemContext;
1144
1148
  resourcePlanDdlStatements(): ResourcePlanDdlStatementsContext;
1145
1149
  mappingTypes(): MappingTypesContext;
@@ -1168,6 +1172,7 @@ export declare class HiveSqlParser extends SQLParserBase {
1168
1172
  private columnName_sempred;
1169
1173
  private columnNamePathAllowEmpty_sempred;
1170
1174
  private selectItem_sempred;
1175
+ private configPropertyPart_sempred;
1171
1176
  private poolPathAllowEmpty_sempred;
1172
1177
  static readonly _serializedATN: number[];
1173
1178
  private static __ATN;
@@ -1281,13 +1286,8 @@ export declare class ExecStatementContext extends antlr.ParserRuleContext {
1281
1286
  KW_EXECUTE(): antlr.TerminalNode | null;
1282
1287
  constantList(): ConstantListContext | null;
1283
1288
  KW_SET(): antlr.TerminalNode | null;
1284
- configPropertiesItem(): ConfigPropertiesItemContext[];
1285
- configPropertiesItem(i: number): ConfigPropertiesItemContext | null;
1289
+ configProperty(): ConfigPropertyContext | null;
1286
1290
  EQUAL(): antlr.TerminalNode | null;
1287
- DOT(): antlr.TerminalNode[];
1288
- DOT(i: number): antlr.TerminalNode | null;
1289
- COLON(): antlr.TerminalNode[];
1290
- COLON(i: number): antlr.TerminalNode | null;
1291
1291
  get ruleIndex(): number;
1292
1292
  enterRule(listener: HiveSqlParserListener): void;
1293
1293
  exitRule(listener: HiveSqlParserListener): void;
@@ -6182,6 +6182,30 @@ export declare class Sql11ReservedKeywordsUsedAsFunctionNameContext extends antl
6182
6182
  exitRule(listener: HiveSqlParserListener): void;
6183
6183
  accept<Result>(visitor: HiveSqlParserVisitor<Result>): Result | null;
6184
6184
  }
6185
+ export declare class ConfigPropertyContext extends antlr.ParserRuleContext {
6186
+ constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
6187
+ configPropertyPart(): ConfigPropertyPartContext[];
6188
+ configPropertyPart(i: number): ConfigPropertyPartContext | null;
6189
+ DOT(): antlr.TerminalNode[];
6190
+ DOT(i: number): antlr.TerminalNode | null;
6191
+ COLON(): antlr.TerminalNode[];
6192
+ COLON(i: number): antlr.TerminalNode | null;
6193
+ get ruleIndex(): number;
6194
+ enterRule(listener: HiveSqlParserListener): void;
6195
+ exitRule(listener: HiveSqlParserListener): void;
6196
+ accept<Result>(visitor: HiveSqlParserVisitor<Result>): Result | null;
6197
+ }
6198
+ export declare class ConfigPropertyPartContext extends antlr.ParserRuleContext {
6199
+ constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
6200
+ configPropertiesItem(): ConfigPropertiesItemContext[];
6201
+ configPropertiesItem(i: number): ConfigPropertiesItemContext | null;
6202
+ MINUS(): antlr.TerminalNode[];
6203
+ MINUS(i: number): antlr.TerminalNode | null;
6204
+ get ruleIndex(): number;
6205
+ enterRule(listener: HiveSqlParserListener): void;
6206
+ exitRule(listener: HiveSqlParserListener): void;
6207
+ accept<Result>(visitor: HiveSqlParserVisitor<Result>): Result | null;
6208
+ }
6185
6209
  export declare class ConfigPropertiesItemContext extends antlr.ParserRuleContext {
6186
6210
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
6187
6211
  id_(): Id_Context | null;