parser

package
v0.23.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 29 Imported by: 6

README

Generated Documentation and Embedded Help Texts

Many parts of the parser package include special consideration for generation or other production of user-facing documentation. This includes interactive help messages, generated documentation of the set of available functions, or diagrams of the various expressions.

Generated documentation is produced and maintained at compile time, while the interactive, contextual help is returned at runtime.

We equip the generated parser with the ability to report contextual help in two circumstances:

  • when the user explicitly requests help with the HELPTOKEN (current syntax: standalone "??")
  • when the user makes a grammatical mistake (e.g. INSERT sometable INTO(x, y) ...)

We use the docgen tool to produce the generated documentation files that are then included in the broader (handwritten) published documentation.

Help texts embedded in the grammar

The help is embedded in the grammar using special markers in yacc comments, for example:

// %Help: HELPKEY - shortdescription
// %Category: SomeCat
// %Text: whatever until next %marker at start of line, or non-comment.
// %SeeAlso: whatever until next %marker at start of line, or non-comment.
// %End (optional)

The "HELPKEY" becomes the map key in the generated Go map.

These texts are extracted automatically by help.awk and converted into a Go data structure in help_messages.go.

Support in the parser

Primary mechanism - LALR error recovery

The primary mechanism is leveraging error recovery in LALR parsers using the special error token [1] [2]: when an unexpected token is encountered, the LALR parser will pop tokens on the stack until the prefix matches a grammar rule with the special "error" token (if any). If such a rule exists, its action is used to reduce and the erroneous tokens are discarded.

This mechanism is used both when the user makes a mistake, and when the user inserts the HELPTOKEN in the middle of a statement. When present in the middle of a statement, HELPTOKEN is considered an error and triggers the error recovery.

We use this for contextual help by providing error rules that generate a contextual help text during LALR error recovery.

For example:

backup_stmt:
  BACKUP targets TO string_or_placeholder opt_as_of_clause opt_incremental opt_with_options
  {
    $$.val = &Backup{Targets: $2.targetList(), To: $4.expr(), IncrementalFrom: $6.exprs(), AsOf: $5.asOfClause(), Options: $7.kvOptions()}
  }
| BACKUP error { return helpWith(sqllex, `BACKUP`) }

In this example, the grammar specifies that if the BACKUP keyword is followed by some input tokens such that the first (valid) grammar rule doesn't apply, the parser will "recover from the error" by backtracking up until the point it only sees BACKUP on the stack followed by non-parsable tokens, at which points it takes the error rule and executes its action.

The action is return helpWith(...). What this does is:

  • halts parsing (the generated parser executes all actions in a big loop; a return interrupts this loop);
  • makes the parser return with an error (the helpWith function returns non-zero);
  • extends the parsing error message with a help text; this help text can subsequently be exploited in a client to display the help message in a friendly manner.
Code generation

Since the pattern "{ return helpWith(sqllex, ...) }" is common, we also implement a shorthand syntax based on comments, for example:

backup_stmt:
   ...
| BACKUP error // SHOW HELP: BACKUP

The special comment syntax "SHOW HELP: XXXX" is substituted by means of an auxiliary script (replace_help_rules.awk) into the form explained above.

Secondary mechanism - explicit help token

The mechanism described above works both when the user make a grammatical error and when they place the HELPTOKEN in the middle of a statement, rendering it invalid.

However for contextual help this is not sufficient: what happens if the user requests HELPTOKEN at a position in the grammar where everything before is a complete, valid SQL input?

For example: DELETE FROM foo ?

When encountering this input, the LALR parser will see DELETE FROM foo first, then reduce using the DELETE action because everything up to this point is a valid DELETE statement. When the HELPTOKEN is encountered, the statement has already been completed and the LALR parser doesn't 'know' any more that it was in the context of a DELETE statement.

If we try to place an error-based recovery rule at the top-level:

stmt:
  alter_stmt
| backup_stmt
| ...
| delete_stmt
| ...
| error { ??? }

This wouldn't work: the code inside the error action cannot "observe" the tokens observed so far and there would be no way to know whether the error should be about DELETE, or instead about ALTER, BACKUP, etc.

So in order to handle HELPTOKEN after a valid statement, we must place it in a rule where the context is still available, that is before the statement's grammar rule is reduced.

Where would that be? Suppose we had a simple statement rule:

somesimplestmt:
  SIMPLE DO SOMETHING { $$ = reduce(...) }
| SIMPLE error { help ... }

We could extend with:

somesimplestmt:
  SIMPLE DO SOMETHING { $$ = reduce(...) }
| SIMPLE DO SOMETHING HELPTOKEN { help ... }
| SIMPLE error { help ... }

(the alternative also works:

somesimplestmt:
  SIMPLE DO SOMETHING { $$ = reduce(...) }
| SIMPLE DO SOMETHING error { help ... }
| SIMPLE error { help ... }

)

That is all fine and dandy, but in SQL we have statements with many alternate forms, for example:

alter_rename_table_stmt:
  ALTER TABLE relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name { ... }

To add complementary handling of the help token at the end of valid statements we could, but would hate to, duplicate all the rules:

alter_rename_table_stmt:
  ALTER TABLE relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE relation_expr RENAME TO qualified_name HELPTOKEN { help ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name HELPTOKEN { help ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name HELPTOKEN { help ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name HELPTOKEN { help ... }

This duplication is horrendous (not to mention hard to maintain), so instead we should attempt to factor the help token in a context where it is still known that we are dealing just with that statement.

The following works:

alter_rename_table_stmt:
  real_alter_rename_table_stmt { $$ = $1 }
| real_alter_rename_table_stmt HELPTOKEN { help ... }

real_alter_rename_table_stmt:
  ALTER TABLE relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name { ... }

Or does it? Without anything else, yacc complains with a "shift/reduce conflict". The reason is coming from the ambiguity: when the parsing stack contains everything sufficient to match a real_alter_rename_table_stmt, there is a choice between reducing the simple form alter_rename_table_stmt: real_alter_rename_table_stmt, or shifting into the more complex form alter_rename_table_stmt: real_alter_rename_table_stmt HELPTOKEN.

This is another form of the textbook situation when yacc is used to parse if-else statements in a programming language: the rule stmt: IF cond THEN body | IF cond THEN body ELSE body is ambiguous (and yields a shift/reduce conflict) for exactly the same reason.

The solution here is also straight out of a textbook: one simply informs yacc of the relative priority between the two candidate rules. In this case, when faced with a neutral choice, we encourage yacc to shift. The particular mechanism is to tell yacc that one rule has a higher priority than another.

It just so happens however that the yacc language only allows us to set relative priorities of tokens, not rules. And here we have a problem, of the two rules that need to be prioritized, only one has a token to work with (the one with HELPTOKEN). Which token should we prioritize for the other?

Conveniently yacc knows about this trouble and offers us an awkward, but working solution: we can tell it "use for this rule the same priority level as an existing token, even though the token is not part of the rule". The syntax for this is rule %prec TOKEN.

We can then use this as follows:

alter_rename_table_stmt:
  real_alter_rename_table_stmt           %prec LOWTOKEN { $$ = $1 }
| real_alter_rename_table_stmt HELPTOKEN %prec HIGHTOKEN { help ... }

We could create two new pseudo-tokens for this (called LOWTOKEN and HIGHTOKEN) however conveniently we can also reuse otherwise valid tokens that have known relative priorities. We settled in our case on VALUES (low priority) and UMINUS (high priority).

Code generation

With the latter mechanism presented above the pattern

rule:
  somerule           %prec VALUES
| somerule HELPTOKEN %prec UMINUS { help ...}`

becomes super common, so we automate it with the following special syntax:

rule:
  somerule // EXTEND WITH HELP: XXX

And the code replacement in replace_help_rules.awk expands this to the form above automatically.

Generated Documentation

Documentation of the SQL functions and operators is generated by the docgen utility, using make generate PKG=./docs/.... The markdown-formatted files are kept in docs/generated/sql and should be re-generated whenever the functions/operators they document change, and indeed if regenerating produces a diff, a CI failure is expected.

References

  1. https://www.gnu.org/software/bison/manual/html_node/Error-Recovery.html
  2. http://stackoverflow.com/questions/9796608/error-handling-in-yacc

Documentation

Overview

Package parser contains exposes a SQL parser for cockroach.

Index

Constants

View Source
const ABORT = 57363
View Source
const ABSOLUTE = 57364
View Source
const ACCESS = 57365
View Source
const ACTION = 57366
View Source
const ADD = 57367
View Source
const ADMIN = 57368
View Source
const AFTER = 57369
View Source
const AGGREGATE = 57370
View Source
const ALL = 57371
View Source
const ALTER = 57372
View Source
const ALWAYS = 57373
View Source
const ANALYSE = 57374
View Source
const ANALYZE = 57375
View Source
const AND = 57376
View Source
const AND_AND = 57377
View Source
const ANNOTATE_TYPE = 57379
View Source
const ANY = 57378
View Source
const ARRAY = 57380
View Source
const AS = 57381
View Source
const ASC = 57382
View Source
const ASENSITIVE = 57385
View Source
const ASYMMETRIC = 57386
View Source
const AS_JSON = 57383
View Source
const AS_LA = 58018
View Source
const AT = 57387
View Source
const ATOMIC = 57388
View Source
const ATTRIBUTE = 57389
View Source
const AT_AT = 57384
View Source
const AUTHORIZATION = 57390
View Source
const AUTOMATIC = 57391
View Source
const AVAILABILITY = 57392
View Source
const BACKUP = 57393
View Source
const BACKUPS = 57394
View Source
const BACKWARD = 57395
View Source
const BATCH = 57396
View Source
const BCONST = 57348
View Source
const BEFORE = 57397
View Source
const BEGIN = 57398
View Source
const BETWEEN = 57399
View Source
const BIGINT = 57400
View Source
const BIGSERIAL = 57401
View Source
const BINARY = 57402
View Source
const BIT = 57403
View Source
const BITCONST = 57349
View Source
const BOOLEAN = 57405
View Source
const BOTH = 57406
View Source
const BOX2D = 57407
View Source
const BUCKET_COUNT = 57404
View Source
const BUNDLE = 57408
View Source
const BY = 57409
View Source
const CACHE = 57410
View Source
const CALL = 57411
View Source
const CALLED = 57412
View Source
const CANCEL = 57413
View Source
const CANCELQUERY = 57414
View Source
const CAPABILITIES = 57415
View Source
const CAPABILITY = 57416
View Source
const CASCADE = 57417
View Source
const CASE = 57418
View Source
const CAST = 57419
View Source
const CBRT = 57420
View Source
const CHANGEFEED = 57421
View Source
const CHAR = 57422
View Source
const CHARACTER = 57423
View Source
const CHARACTERISTICS = 57424
View Source
const CHECK = 57425
View Source
const CHECK_FILES = 57426
View Source
const CLOSE = 57427
View Source
const CLUSTER = 57428
View Source
const CLUSTERS = 57429
View Source
const CLUSTER_ALL = 58026
View Source
const COALESCE = 57430
View Source
const COLLATE = 57431
View Source
const COLLATION = 57432
View Source
const COLUMN = 57433
View Source
const COLUMNS = 57434
View Source
const COMMENT = 57435
View Source
const COMMENTS = 57436
View Source
const COMMIT = 57437
View Source
const COMMITTED = 57438
View Source
const COMPACT = 57439
View Source
const COMPLETE = 57440
View Source
const COMPLETIONS = 57441
View Source
const CONCAT = 57442
View Source
const CONCURRENTLY = 57443
View Source
const CONFIGURATION = 57444
View Source
const CONFIGURATIONS = 57445
View Source
const CONFIGURE = 57446
View Source
const CONFLICT = 57447
View Source
const CONNECTION = 57448
View Source
const CONNECTIONS = 57449
View Source
const CONSTRAINT = 57450
View Source
const CONSTRAINTS = 57451
View Source
const CONTAINED_BY = 58028
View Source
const CONTAINS = 57452
View Source
const CONTROLCHANGEFEED = 57453
View Source
const CONTROLJOB = 57454
View Source
const CONVERSION = 57455
View Source
const CONVERT = 57456
View Source
const COPY = 57457
View Source
const COST = 57458
View Source
const COVERING = 57459
View Source
const CREATE = 57460
View Source
const CREATEDB = 57461
View Source
const CREATELOGIN = 57462
View Source
const CREATEROLE = 57463
View Source
const CROSS = 57464
View Source
const CSV = 57465
View Source
const CUBE = 57466
View Source
const CURRENT = 57467
View Source
const CURRENT_CATALOG = 57468
View Source
const CURRENT_DATE = 57469
View Source
const CURRENT_ROLE = 57471
View Source
const CURRENT_SCHEMA = 57470
View Source
const CURRENT_TIME = 57472
View Source
const CURRENT_TIMESTAMP = 57473
View Source
const CURRENT_USER = 57474
View Source
const CURSOR = 57475
View Source
const CYCLE = 57476
View Source
const DATA = 57477
View Source
const DATABASE = 57478
View Source
const DATABASES = 57479
View Source
const DATE = 57480
View Source
const DAY = 57481
View Source
const DEALLOCATE = 57490
View Source
const DEBUG_DUMP_METADATA_SST = 57485
View Source
const DEBUG_IDS = 57482
View Source
const DEBUG_PAUSE_ON = 57483
View Source
const DEC = 57484
View Source
const DECIMAL = 57486
View Source
const DECLARE = 57491
View Source
const DEFAULT = 57487
View Source
const DEFAULTS = 57488
View Source
const DEFERRABLE = 57492
View Source
const DEFERRED = 57493
View Source
const DEFINER = 57489
View Source
const DELETE = 57494
View Source
const DELIMITER = 57495
View Source
const DEPENDS = 57496
View Source
const DESC = 57497
View Source
const DESTINATION = 57498
View Source
const DETACHED = 57499
View Source
const DETAILS = 57500
View Source
const DISCARD = 57501
View Source
const DISTINCT = 57502
View Source
const DO = 57503
View Source
const DOMAIN = 57504
View Source
const DOT_DOT = 57355
View Source
const DOUBLE = 57505
View Source
const DROP = 57506
View Source
const ELSE = 57507
View Source
const ENCODING = 57508
View Source
const ENCRYPTED = 57509
View Source
const ENCRYPTION_INFO_DIR = 57510
View Source
const ENCRYPTION_PASSPHRASE = 57511
View Source
const END = 57512
View Source
const ENUM = 57513
View Source
const ENUMS = 57514
View Source
const ERROR = 57362
View Source
const ESCAPE = 57515
View Source
const EXCEPT = 57516
View Source
const EXCLUDE = 57517
View Source
const EXCLUDING = 57518
View Source
const EXECUTE = 57520
View Source
const EXECUTION = 57521
View Source
const EXISTS = 57519
View Source
const EXPERIMENTAL = 57522
View Source
const EXPERIMENTAL_AUDIT = 57525
View Source
const EXPERIMENTAL_FINGERPRINTS = 57523
View Source
const EXPERIMENTAL_RELOCATE = 57526
View Source
const EXPERIMENTAL_REPLICA = 57524
View Source
const EXPIRATION = 57527
View Source
const EXPLAIN = 57528
View Source
const EXPORT = 57529
View Source
const EXTENSION = 57530
View Source
const EXTERNAL = 57531
View Source
const EXTRACT = 57532
View Source
const EXTRACT_DURATION = 57533
View Source
const EXTREMES = 57534
View Source
const FAILURE = 57535
View Source
const FALSE = 57536
View Source
const FAMILY = 57537
View Source
const FCONST = 57351
View Source
const FETCH = 57538
View Source
const FETCHTEXT = 57540
View Source
const FETCHTEXT_PATH = 57542
View Source
const FETCHVAL = 57539
View Source
const FETCHVAL_PATH = 57541
View Source
const FILES = 57543
View Source
const FILTER = 57544
View Source
const FIRST = 57545
View Source
const FLOAT = 57546
View Source
const FLOAT4 = 57547
View Source
const FLOAT8 = 57548
View Source
const FLOORDIV = 57549
View Source
const FOLLOWING = 57550
View Source
const FOR = 57551
View Source
const FORCE = 57552
View Source
const FORCE_INDEX = 57553
View Source
const FORCE_NOT_NULL = 57554
View Source
const FORCE_NULL = 57555
View Source
const FORCE_QUOTE = 57556
View Source
const FORCE_ZIGZAG = 57557
View Source
const FOREIGN = 57558
View Source
const FORMAT = 57559
View Source
const FORWARD = 57560
View Source
const FREEZE = 57561
View Source
const FROM = 57562
View Source
const FULL = 57563
View Source
const FUNCTION = 57564
View Source
const FUNCTIONS = 57565
View Source
const GENERATED = 57566
View Source
const GENERATED_ALWAYS = 58019
View Source
const GENERATED_BY_DEFAULT = 58020
View Source
const GEOGRAPHY = 57567
View Source
const GEOMETRY = 57568
View Source
const GEOMETRYCOLLECTION = 57572
View Source
const GEOMETRYCOLLECTIONM = 57573
View Source
const GEOMETRYCOLLECTIONZ = 57574
View Source
const GEOMETRYCOLLECTIONZM = 57575
View Source
const GEOMETRYM = 57569
View Source
const GEOMETRYZ = 57570
View Source
const GEOMETRYZM = 57571
View Source
const GLOBAL = 57576
View Source
const GOAL = 57577
View Source
const GRANT = 57578
View Source
const GRANTEE = 57579
View Source
const GRANTS = 57580
View Source
const GREATER_EQUALS = 57357
View Source
const GREATEST = 57581
View Source
const GROUP = 57582
View Source
const GROUPING = 57583
View Source
const GROUPS = 57584
View Source
const HASH = 57586
View Source
const HAVING = 57585
View Source
const HEADER = 57587
View Source
const HELPTOKEN = 58032
View Source
const HIGH = 57588
View Source
const HISTOGRAM = 57589
View Source
const HOLD = 57590
View Source
const HOUR = 57591
View Source
const ICONST = 57350
View Source
const IDENT = 57346
View Source
const IDENTITY = 57592
View Source
const IF = 57593
View Source
const IFERROR = 57594
View Source
const IFNULL = 57595
View Source
const IGNORE_FOREIGN_KEYS = 57596
View Source
const ILIKE = 57597
View Source
const IMMEDIATE = 57598
View Source
const IMMUTABLE = 57599
View Source
const IMPORT = 57600
View Source
const IN = 57601
View Source
const INCLUDE = 57602
View Source
const INCLUDE_ALL_SECONDARY_TENANTS = 57604
View Source
const INCLUDE_ALL_VIRTUAL_CLUSTERS = 57605
View Source
const INCLUDING = 57603
View Source
const INCREMENT = 57606
View Source
const INCREMENTAL = 57607
View Source
const INCREMENTAL_LOCATION = 57608
View Source
const INDEX = 57612
View Source
const INDEXES = 57613
View Source
const INDEX_AFTER_ORDER_BY_BEFORE_AT = 57619
View Source
const INDEX_BEFORE_NAME_THEN_PAREN = 57618
View Source
const INDEX_BEFORE_PAREN = 57617
View Source
const INET = 57609
View Source
const INET_CONTAINED_BY_OR_EQUALS = 57610
View Source
const INET_CONTAINS_OR_EQUALS = 57611
View Source
const INHERITS = 57614
View Source
const INITIALLY = 57616
View Source
const INJECT = 57615
View Source
const INNER = 57620
View Source
const INOUT = 57621
View Source
const INPUT = 57622
View Source
const INSENSITIVE = 57623
View Source
const INSERT = 57624
View Source
const INT = 57625
View Source
const INTEGER = 57626
View Source
const INTERSECT = 57627
View Source
const INTERVAL = 57628
View Source
const INTERVAL_SIMPLE = 58030
View Source
const INTO = 57629
View Source
const INTO_DB = 57630
View Source
const INVERTED = 57631
View Source
const INVISIBLE = 57999
View Source
const INVOKER = 57632
View Source
const IS = 57633
View Source
const ISERROR = 57634
View Source
const ISNULL = 57635
View Source
const ISOLATION = 57636
View Source
const JOB = 57637
View Source
const JOBS = 57638
View Source
const JOIN = 57639
View Source
const JSON = 57640
View Source
const JSONB = 57641
View Source
const JSON_ALL_EXISTS = 57643
View Source
const JSON_SOME_EXISTS = 57642
View Source
const KEY = 57644
View Source
const KEYS = 57645
View Source
const KMS = 57646
View Source
const KV = 57647
View Source
const LABEL = 57648
View Source
const LANGUAGE = 57649
View Source
const LAST = 57650
View Source
const LATERAL = 57651
View Source
const LATEST = 57652
View Source
const LC_COLLATE = 57654
View Source
const LC_CTYPE = 57653
View Source
const LEADING = 57655
View Source
const LEAKPROOF = 57658
View Source
const LEASE = 57656
View Source
const LEAST = 57657
View Source
const LEFT = 57659
View Source
const LESS = 57660
View Source
const LESS_EQUALS = 57356
View Source
const LEVEL = 57661
View Source
const LIKE = 57662
View Source
const LIMIT = 57663
View Source
const LINESTRING = 57664
View Source
const LINESTRINGM = 57665
View Source
const LINESTRINGZ = 57666
View Source
const LINESTRINGZM = 57667
View Source
const LIST = 57668
View Source
const LOCAL = 57669
View Source
const LOCALITY = 57670
View Source
const LOCALTIME = 57671
View Source
const LOCALTIMESTAMP = 57672
View Source
const LOCKED = 57673
View Source
const LOGIN = 57674
View Source
const LOOKUP = 57675
View Source
const LOW = 57676
View Source
const LSHIFT = 57677
View Source
const MATCH = 57678
View Source
const MATERIALIZED = 57679
View Source
const MAXVALUE = 57682
View Source
const MERGE = 57680
View Source
const METHOD = 57683
View Source
const MINUTE = 57684
View Source
const MINVALUE = 57681
View Source
const MODIFYCLUSTERSETTING = 57685
View Source
const MODIFYSQLCLUSTERSETTING = 57686
View Source
const MONTH = 57687
View Source
const MOVE = 57688
View Source
const MULTILINESTRING = 57689
View Source
const MULTILINESTRINGM = 57690
View Source
const MULTILINESTRINGZ = 57691
View Source
const MULTILINESTRINGZM = 57692
View Source
const MULTIPOINT = 57693
View Source
const MULTIPOINTM = 57694
View Source
const MULTIPOINTZ = 57695
View Source
const MULTIPOINTZM = 57696
View Source
const MULTIPOLYGON = 57697
View Source
const MULTIPOLYGONM = 57698
View Source
const MULTIPOLYGONZ = 57699
View Source
const MULTIPOLYGONZM = 57700
View Source
const MaxInt = int(MaxUint >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const NAME = 57702
View Source
const NAMES = 57703
View Source
const NAN = 57701
View Source
const NATURAL = 57704
View Source
const NEVER = 57705
View Source
const NEW_DB_NAME = 57706
View Source
const NEW_KMS = 57707
View Source
const NEXT = 57708
View Source
const NO = 57709
View Source
const NOCANCELQUERY = 57710
View Source
const NOCONTROLCHANGEFEED = 57711
View Source
const NOCONTROLJOB = 57712
View Source
const NOCREATEDB = 57713
View Source
const NOCREATELOGIN = 57714
View Source
const NOCREATEROLE = 57715
View Source
const NOLOGIN = 57716
View Source
const NOMODIFYCLUSTERSETTING = 57717
View Source
const NONE = 57723
View Source
const NONVOTERS = 57724
View Source
const NOREPLICATION = 57718
View Source
const NORMAL = 57725
View Source
const NOSQLLOGIN = 57719
View Source
const NOT = 57726
View Source
const NOTHING = 57727
View Source
const NOTHING_AFTER_RETURNING = 57728
View Source
const NOTNULL = 57729
View Source
const NOT_EQUALS = 57358
View Source
const NOT_LA = 58015
View Source
const NOT_REGIMATCH = 57361
View Source
const NOT_REGMATCH = 57359
View Source
const NOVIEWACTIVITY = 57730
View Source
const NOVIEWACTIVITYREDACTED = 57731
View Source
const NOVIEWCLUSTERSETTING = 57732
View Source
const NOWAIT = 57733
View Source
const NO_FULL_SCAN = 57722
View Source
const NO_INDEX_JOIN = 57720
View Source
const NO_ZIGZAG_JOIN = 57721
View Source
const NULL = 57734
View Source
const NULLIF = 57735
View Source
const NULLS = 57736
View Source
const NULLS_LA = 58016
View Source
const NUMERIC = 57737
View Source
const OF = 57738
View Source
const OFF = 57739
View Source
const OFFSET = 57740
View Source
const OID = 57741
View Source
const OIDS = 57742
View Source
const OIDVECTOR = 57743
View Source
const OLD_KMS = 57744
View Source
const ON = 57745
View Source
const ONLY = 57746
View Source
const ON_LA = 58024
View Source
const OPERATOR = 57761
View Source
const OPT = 57747
View Source
const OPTION = 57748
View Source
const OPTIONS = 57749
View Source
const OR = 57750
View Source
const ORDER = 57751
View Source
const ORDINALITY = 57752
View Source
const OTHERS = 57753
View Source
const OUT = 57754
View Source
const OUTER = 57755
View Source
const OVER = 57756
View Source
const OVERLAPS = 57757
View Source
const OVERLAY = 57758
View Source
const OWNED = 57759
View Source
const OWNER = 57760
View Source
const PARALLEL = 57762
View Source
const PARENT = 57763
View Source
const PARTIAL = 57764
View Source
const PARTITION = 57765
View Source
const PARTITIONS = 57766
View Source
const PASSWORD = 57767
View Source
const PAUSE = 57768
View Source
const PAUSED = 57769
View Source
const PHYSICAL = 57770
View Source
const PLACEHOLDER = 57352
View Source
const PLACEMENT = 57771
View Source
const PLACING = 57772
View Source
const PLAN = 57773
View Source
const PLANS = 57774
View Source
const POINT = 57775
View Source
const POINTM = 57776
View Source
const POINTZ = 57777
View Source
const POINTZM = 57778
View Source
const POLYGON = 57779
View Source
const POLYGONM = 57780
View Source
const POLYGONZ = 57781
View Source
const POLYGONZM = 57782
View Source
const POSITION = 57783
View Source
const POSTFIXOP = 58029
View Source
const PRECEDING = 57784
View Source
const PRECISION = 57785
View Source
const PREPARE = 57786
View Source
const PRESERVE = 57787
View Source
const PRIMARY = 57788
View Source
const PRIOR = 57789
View Source
const PRIORITY = 57790
View Source
const PRIVILEGES = 57791
View Source
const PROCEDURAL = 57792
View Source
const PROCEDURE = 57793
View Source
const PROCEDURES = 57794
View Source
const PUBLIC = 57795
View Source
const PUBLICATION = 57796
View Source
const QUERIES = 57797
View Source
const QUERY = 57798
View Source
const QUOTE = 57799
View Source
const RANGE = 57800
View Source
const RANGES = 57801
View Source
const READ = 57802
View Source
const REAL = 57803
View Source
const REASON = 57804
View Source
const REASSIGN = 57805
View Source
const RECURRING = 57807
View Source
const RECURSIVE = 57806
View Source
const REDACT = 57808
View Source
const REF = 57809
View Source
const REFERENCES = 57810
View Source
const REFRESH = 57811
View Source
const REGCLASS = 57812
View Source
const REGIMATCH = 57360
View Source
const REGION = 57813
View Source
const REGIONAL = 57814
View Source
const REGIONS = 57815
View Source
const REGNAMESPACE = 57816
View Source
const REGPROC = 57817
View Source
const REGPROCEDURE = 57818
View Source
const REGROLE = 57819
View Source
const REGTYPE = 57820
View Source
const REINDEX = 57821
View Source
const RELATIVE = 57822
View Source
const RELEASE = 57830
View Source
const RELOCATE = 57823
View Source
const REMOVE_PATH = 57824
View Source
const REMOVE_REGIONS = 57825
View Source
const RENAME = 57826
View Source
const REPEATABLE = 57827
View Source
const REPLACE = 57828
View Source
const REPLICATION = 57829
View Source
const RESET = 57831
View Source
const RESET_ALL = 58021
View Source
const RESTART = 57832
View Source
const RESTORE = 57833
View Source
const RESTRICT = 57834
View Source
const RESTRICTED = 57835
View Source
const RESUME = 57836
View Source
const RETENTION = 57837
View Source
const RETRY = 57841
View Source
const RETURN = 57839
View Source
const RETURNING = 57838
View Source
const RETURNS = 57840
View Source
const REVISION_HISTORY = 57842
View Source
const REVOKE = 57843
View Source
const RIGHT = 57844
View Source
const ROLE = 57845
View Source
const ROLES = 57846
View Source
const ROLE_ALL = 58022
View Source
const ROLLBACK = 57847
View Source
const ROLLUP = 57848
View Source
const ROUTINES = 57849
View Source
const ROW = 57850
View Source
const ROWS = 57851
View Source
const RSHIFT = 57852
View Source
const RULE = 57853
View Source
const RUNNING = 57854
View Source
const SAVEPOINT = 57855
View Source
const SCANS = 57856
View Source
const SCATTER = 57857
View Source
const SCHEDULE = 57858
View Source
const SCHEDULES = 57859
View Source
const SCHEMA = 57861
View Source
const SCHEMAS = 57863
View Source
const SCHEMA_ONLY = 57862
View Source
const SCONST = 57347
View Source
const SCROLL = 57860
View Source
const SCRUB = 57864
View Source
const SEARCH = 57865
View Source
const SECOND = 57866
View Source
const SECONDARY = 57867
View Source
const SECURITY = 57868
View Source
const SELECT = 57869
View Source
const SEQUENCE = 57870
View Source
const SEQUENCES = 57871
View Source
const SERIALIZABLE = 57872
View Source
const SERVER = 57873
View Source
const SERVICE = 57874
View Source
const SESSION = 57875
View Source
const SESSIONS = 57876
View Source
const SESSION_USER = 57877
View Source
const SET = 57878
View Source
const SETOF = 57879
View Source
const SETS = 57880
View Source
const SETTING = 57881
View Source
const SETTINGS = 57882
View Source
const SET_TRACING = 58027
View Source
const SHARE = 57883
View Source
const SHARED = 57884
View Source
const SHOW = 57885
View Source
const SIMILAR = 57886
View Source
const SIMPLE = 57887
View Source
const SIZE = 57888
View Source
const SKIP = 57889
View Source
const SKIP_LOCALITIES_CHECK = 57890
View Source
const SKIP_MISSING_FOREIGN_KEYS = 57891
View Source
const SKIP_MISSING_SEQUENCES = 57892
View Source
const SKIP_MISSING_SEQUENCE_OWNERS = 57893
View Source
const SKIP_MISSING_UDFS = 57895
View Source
const SKIP_MISSING_VIEWS = 57894
View Source
const SMALLINT = 57896
View Source
const SMALLSERIAL = 57897
View Source
const SNAPSHOT = 57898
View Source
const SOME = 57899
View Source
const SPLIT = 57900
View Source
const SQL = 57901
View Source
const SQLLOGIN = 57902
View Source
const SQRT = 57926
View Source
const STABLE = 57903
View Source
const START = 57904
View Source
const STATE = 57905
View Source
const STATEMENTS = 57928
View Source
const STATISTICS = 57906
View Source
const STATUS = 57907
View Source
const STDIN = 57908
View Source
const STDOUT = 57909
View Source
const STOP = 57910
View Source
const STORAGE = 57914
View Source
const STORE = 57915
View Source
const STORED = 57916
View Source
const STORING = 57917
View Source
const STREAM = 57911
View Source
const STRICT = 57912
View Source
const STRING = 57913
View Source
const SUBSCRIPTION = 57927
View Source
const SUBSTRING = 57918
View Source
const SUPER = 57919
View Source
const SUPPORT = 57920
View Source
const SURVIVAL = 57922
View Source
const SURVIVE = 57921
View Source
const SYMMETRIC = 57923
View Source
const SYNTAX = 57924
View Source
const SYSTEM = 57925
View Source
const TABLE = 57929
View Source
const TABLES = 57930
View Source
const TABLESPACE = 57931
View Source
const TEMP = 57932
View Source
const TEMPLATE = 57933
View Source
const TEMPORARY = 57934
View Source
const TENANT = 57935
View Source
const TENANTS = 57937
View Source
const TENANT_ALL = 58025
View Source
const TENANT_NAME = 57936
View Source
const TESTING_RELOCATE = 57938
View Source
const TEXT = 57939
View Source
const THEN = 57940
View Source
const THROTTLING = 57947
View Source
const TIES = 57941
View Source
const TIME = 57942
View Source
const TIMESTAMP = 57944
View Source
const TIMESTAMPTZ = 57945
View Source
const TIMETZ = 57943
View Source
const TO = 57946
View Source
const TRACE = 57949
View Source
const TRACING = 57962
View Source
const TRAILING = 57948
View Source
const TRANSACTION = 57950
View Source
const TRANSACTIONS = 57951
View Source
const TRANSFER = 57952
View Source
const TRANSFORM = 57953
View Source
const TREAT = 57954
View Source
const TRIGGER = 57955
View Source
const TRIM = 57956
View Source
const TRUE = 57957
View Source
const TRUNCATE = 57958
View Source
const TRUSTED = 57959
View Source
const TYPE = 57960
View Source
const TYPEANNOTATE = 57354
View Source
const TYPECAST = 57353
View Source
const TYPES = 57961
View Source
const UMINUS = 58031
View Source
const UNBOUNDED = 57963
View Source
const UNCOMMITTED = 57964
View Source
const UNION = 57965
View Source
const UNIQUE = 57966
View Source
const UNKNOWN = 57967
View Source
const UNLISTEN = 57968
View Source
const UNLOGGED = 57969
View Source
const UNSAFE_RESTORE_INCOMPATIBLE_VERSION = 57970
View Source
const UNSET = 57975
View Source
const UNSPLIT = 57971
View Source
const UNTIL = 57976
View Source
const UPDATE = 57972
View Source
const UPDATES_CLUSTER_MONITORING_METRICS = 57973
View Source
const UPSERT = 57974
View Source
const USE = 57977
View Source
const USER = 57978
View Source
const USERS = 57979
View Source
const USER_ALL = 58023
View Source
const USING = 57980
View Source
const UUID = 57981
View Source
const VALID = 57982
View Source
const VALIDATE = 57983
View Source
const VALUE = 57984
View Source
const VALUES = 57985
View Source
const VARBIT = 57986
View Source
const VARCHAR = 57987
View Source
const VARIADIC = 57988
View Source
const VARYING = 57991
View Source
const VERIFY_BACKUP_TABLE_DATA = 57989
View Source
const VIEW = 57990
View Source
const VIEWACTIVITY = 57992
View Source
const VIEWACTIVITYREDACTED = 57993
View Source
const VIEWCLUSTERMETADATA = 57995
View Source
const VIEWCLUSTERSETTING = 57996
View Source
const VIEWDEBUG = 57994
View Source
const VIRTUAL = 57997
View Source
const VIRTUAL_CLUSTER = 58004
View Source
const VIRTUAL_CLUSTER_NAME = 58003
View Source
const VISIBILITY = 58000
View Source
const VISIBLE = 57998
View Source
const VOLATILE = 58001
View Source
const VOTERS = 58002
View Source
const WHEN = 58005
View Source
const WHERE = 58006
View Source
const WINDOW = 58007
View Source
const WITH = 58008
View Source
const WITHIN = 58009
View Source
const WITHOUT = 58010
View Source
const WITH_LA = 58017
View Source
const WORK = 58011
View Source
const WRITE = 58012
View Source
const YEAR = 58013
View Source
const ZONE = 58014

Variables

View Source
var AllHelp = func(h map[string]HelpMessageBody) string {

	cmds := make(map[string][]string)
	for c, details := range h {
		if details.Category == "" {
			continue
		}
		cmds[details.Category] = append(cmds[details.Category], c)
	}

	// Ensure the result is deterministic.
	var categories []string
	for c, l := range cmds {
		categories = append(categories, c)
		sort.Strings(l)
	}
	sort.Strings(categories)

	// Compile the final help index.
	var buf bytes.Buffer
	w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', 0)
	for _, cat := range categories {
		fmt.Fprintf(w, "%s:\n", cases.Title(language.English, cases.NoLower).String(cat))
		for _, item := range cmds[cat] {
			fmt.Fprintf(w, "\t\t%s\t%s\n", item, h[item].ShortDescription)
		}
		fmt.Fprintln(w)
	}
	_ = w.Flush()
	return buf.String()
}(helpMessages)

AllHelp contains an overview of all statements with help messages. For example, displayed in the CLI shell with \h without additional parameters.

View Source
var HelpMessages = func(h map[string]HelpMessageBody) map[string]HelpMessageBody {
	appendSeeAlso := func(newItem, prevItems string) string {

		if prevItems != "" {
			return newItem + "\n  " + prevItems
		}
		return newItem
	}
	reformatSeeAlso := func(seeAlso string) string {
		return strings.Replace(
			strings.Replace(seeAlso, ", ", "\n  ", -1),
			"WEBDOCS", docs.URLBase, -1)
	}
	srcMsg := h["<SOURCE>"]
	srcMsg.SeeAlso = reformatSeeAlso(strings.TrimSpace(srcMsg.SeeAlso))
	selectMsg := h["<SELECTCLAUSE>"]
	selectMsg.SeeAlso = reformatSeeAlso(strings.TrimSpace(selectMsg.SeeAlso))
	for k, m := range h {
		m = h[k]
		m.ShortDescription = strings.TrimSpace(m.ShortDescription)
		m.Text = strings.TrimSpace(m.Text)
		m.SeeAlso = strings.TrimSpace(m.SeeAlso)

		if strings.Contains(m.Text, "<source>") && k != "<SOURCE>" {
			m.Text = strings.TrimSpace(m.Text) + "\n\n" + strings.TrimSpace(srcMsg.Text)
			m.SeeAlso = appendSeeAlso(srcMsg.SeeAlso, m.SeeAlso)
		}

		if strings.Contains(m.Text, "<selectclause>") && k != "<SELECTCLAUSE>" {
			m.Text = strings.TrimSpace(m.Text) + "\n\n" + strings.TrimSpace(selectMsg.Text)
			m.SeeAlso = appendSeeAlso(selectMsg.SeeAlso, m.SeeAlso)
		}

		if strings.Contains(m.Text, "<tablename>") {
			m.SeeAlso = appendSeeAlso("SHOW TABLES", m.SeeAlso)
		}
		m.SeeAlso = reformatSeeAlso(m.SeeAlso)
		h[k] = m
	}
	return h
}(helpMessages)

HelpMessages is the registry of all help messages, keyed by the top-level statement that they document. The key is intended for use via the \h client-side command.

Functions

func GetTypeFromCastOrCollate

func GetTypeFromCastOrCollate(expr tree.Expr) (tree.ResolvableTypeReference, error)

GetTypeFromCastOrCollate returns the type of the given tree.Expr. The method assumes that the expression is either tree.CastExpr or tree.CollateExpr (which wraps the tree.CastExpr).

func GetTypeFromValidSQLSyntax

func GetTypeFromValidSQLSyntax(sql string) (tree.ResolvableTypeReference, error)

GetTypeFromValidSQLSyntax retrieves a type from its SQL syntax. The caller is responsible for guaranteeing that the type expression is valid SQL (or handling the resulting error). This includes verifying that complex identifiers are enclosed in double quotes, etc.

func GetTypeReferenceFromName

func GetTypeReferenceFromName(typeName tree.Name) (tree.ResolvableTypeReference, error)

GetTypeReferenceFromName turns a type name into a type reference. This supports only “simple” (single-identifier) references to built-in types, when the identifer has already been parsed away from the input SQL syntax.

func NakedIntTypeFromDefaultIntSize

func NakedIntTypeFromDefaultIntSize(defaultIntSize int32) *types.T

NakedIntTypeFromDefaultIntSize given the size in bits or bytes (preferred) of how a "naked" INT type should be parsed returns the corresponding integer type.

func Parse

func Parse(sql string) (statements.Statements, error)

Parse parses a sql statement string and returns a list of Statements.

func ParseExpr

func ParseExpr(sql string) (tree.Expr, error)

ParseExpr parses a SQL scalar expression. The caller is responsible for ensuring that the input is, in fact, a valid SQL scalar expression — the results are undefined if the string contains invalid SQL syntax.

func ParseExprWithInt

func ParseExprWithInt(sql string, nakedIntType *types.T) (tree.Expr, error)

ParseExprWithInt parses a SQL scalar expression, using the given type when INT is used as type name in the SQL syntax. The caller is responsible for ensuring that the input is, in fact, a valid SQL scalar expression — the results are undefined if the string contains invalid SQL syntax.

func ParseExprs

func ParseExprs(sql []string) (tree.Exprs, error)

ParseExprs parses a comma-delimited sequence of SQL scalar expressions. The caller is responsible for ensuring that the input is, in fact, a comma-delimited sequence of SQL scalar expressions — the results are undefined if the string contains invalid SQL syntax.

func ParseOne

func ParseOne(sql string) (statements.Statement[tree.Statement], error)

ParseOne parses a sql statement string, ensuring that it contains only a single statement, and returns that Statement. ParseOne will always interpret the INT and SERIAL types as 64-bit types, since this is used in various internal-execution paths where we might receive bits of SQL from other nodes. In general,earwe expect that all user-generated SQL has been run through the ParseWithInt() function.

func ParseOneWithInt

func ParseOneWithInt(
	sql string, nakedIntType *types.T,
) (statements.Statement[tree.Statement], error)

ParseOneWithInt is similar to ParseOn but interprets the INT and SERIAL types as the provided integer type.

func ParseQualifiedTableName

func ParseQualifiedTableName(sql string) (*tree.TableName, error)

ParseQualifiedTableName parses a possibly qualified table name. The table name must contain one or more name parts, using the full input SQL syntax: each name part containing special characters, or non-lowercase characters, must be enclosed in double quote. The name may not be an invalid table name (the caller is responsible for guaranteeing that only valid table names are provided as input).

func ParseTableName

func ParseTableName(sql string) (*tree.UnresolvedObjectName, error)

ParseTableName parses a table name. The table name must contain one or more name parts, using the full input SQL syntax: each name part containing special characters, or non-lowercase characters, must be enclosed in double quote. The name may not be an invalid table name (the caller is responsible for guaranteeing that only valid table names are provided as input).

func ParseTablePattern

func ParseTablePattern(sql string) (tree.TablePattern, error)

ParseTablePattern parses a table pattern. The table name must contain one or more name parts, using the full input SQL syntax: each name part containing special characters, or non-lowercase characters, must be enclosed in double quote. The name may not be an invalid table name (the caller is responsible for guaranteeing that only valid table names are provided as input). The last part may be '*' to denote a wildcard.

func ParseWithInt

func ParseWithInt(sql string, nakedIntType *types.T) (statements.Statements, error)

ParseWithInt parses a sql statement string and returns a list of Statements. The INT token will result in the specified TInt type.

func PopulateErrorDetails

func PopulateErrorDetails(
	tokID int32, lastTokStr string, lastTokPos int32, lastErr error, lIn string,
) error

PopulateErrorDetails properly wraps the "last error" field in the lexer.

func RunShowSyntax

func RunShowSyntax(
	ctx context.Context,
	stmt string,
	report func(ctx context.Context, field, msg string),
	reportErr func(ctx context.Context, err error),
)

RunShowSyntax analyzes the syntax and reports its structure as data for the client. Even an error is reported as data.

Since errors won't propagate to the client as an error, but as a result, the usual code path to capture and record errors will not be triggered. Instead, the caller can pass a reportErr closure to capture errors instead. May be nil.

func SplitFirstStatement

func SplitFirstStatement(sql string) (pos int, ok bool)

SplitFirstStatement returns the length of the prefix of the string up to and including the first semicolon that separates statements. If there is no including the first semicolon that separates statements. If there is no semicolon, returns ok=false.

Types

type HelpMessage

type HelpMessage struct {
	// Command is set if the message is about a statement.
	Command string
	// Function is set if the message is about a built-in function.
	Function string

	// HelpMessageBody contains the details of the message.
	HelpMessageBody
}

HelpMessage describes a contextual help message.

func (*HelpMessage) Format

func (h *HelpMessage) Format(w io.Writer)

Format prints out details about the message onto the specified output stream.

func (*HelpMessage) String

func (h *HelpMessage) String() string

String implements the fmt.String interface.

type HelpMessageBody

type HelpMessageBody struct {
	Category         string
	ShortDescription string
	Text             string
	SeeAlso          string
}

HelpMessageBody defines the body of a help text. The messages are structured to facilitate future help navigation functionality.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser wraps a scanner, parser and other utilities present in the parser package.

func (*Parser) Parse

func (p *Parser) Parse(sql string) (statements.Statements, error)

Parse parses the sql and returns a list of statements.

func (*Parser) ParseWithInt

func (p *Parser) ParseWithInt(sql string, nakedIntType *types.T) (statements.Statements, error)

ParseWithInt parses a sql statement string and returns a list of Statements. The INT token will result in the specified TInt type.

type TokenString

type TokenString struct {
	TokenID int32
	Str     string
}

TokenString is the unit value returned by Tokens.

func Tokens

func Tokens(sql string) (tokens []TokenString, ok bool)

Tokens decomposes the input into lexical tokens.

func TokensIgnoreErrors

func TokensIgnoreErrors(sql string) (tokens []TokenString)

TokensIgnoreErrors decomposes the input into lexical tokens and ignores errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL