Add resource group keywords, constants and functions - #33
Merged
Merged
Conversation
Covers CREATE/ALTER/DROP RESOURCE GROUP, the SET/UNSET RESOURCE GROUP
clauses on ALTER USER, ALTER GROUP and ALTER SERVICE ACCOUNT, and the
WITH (...) policy parameters.
keywords: mapping, priority, resource, unset
constants: cpu_weight, max_active_queries, max_queued_queries,
memory_limit, queue_timeout, unlimited
functions: current_resource_group (scalar), resource_groups (table valued)
unlimited also completes SET MEMORY LIMIT UNLIMITED, which was missing
its constant.
Six entries were out of order. Sorting only, no tokens added or removed: atomic before attach commitLag before compression_level lateral before latest partition before partition_by reindex before release statistics_enabled before storage constants.ts and functions.ts were already sorted. functions.ts is left untouched: its tableValuedFunctions array is split by comments into CURSOR and STANDARD subsections that are each sorted internally, and flattening them would break that grouping.
emrberk
approved these changes
Sep 16, 2026
emrberk
added a commit
that referenced
this pull request
Sep 18, 2026
PR #33 added memory_limit, cpu_weight, max_active_queries, max_queued_queries, queue_timeout, mapping, priority, resource and unset as tokens without adding them to IDENTIFIER_KEYWORD_NAMES, so they could no longer be used as column names. memory_limit is a column of query_activity(), which the Web Console queries. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
emrberk
added a commit
that referenced
this pull request
Sep 21, 2026
* add sql formatter and fix parser gaps * remove unlimited from keywords * mark resource group words as non-reserved keywords PR #33 added memory_limit, cpu_weight, max_active_queries, max_queued_queries, queue_timeout, mapping, priority, resource and unset as tokens without adding them to IDENTIFIER_KEYWORD_NAMES, so they could no longer be used as column names. memory_limit is a column of query_activity(), which the Web Console queries. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * formatter: indent query bodies, positional blocks, DECLARE lists, width 50 - Indent the query one level after AS in CREATE statements and after the INSERT target. - Open a block for a parenthesis that follows FROM, JOIN, a comma in the FROM list, or AS in a WITH item or CREATE, so implicit-select subqueries break into lines; a single plain item stays inline. - Drop gaps at the start of a line in the printer, which keeps blocks that begin with a comment or unknown text idempotent. - DECLARE with two or more variables always breaks, one per line. - ATTACH/DETACH/DROP/CONVERT PARTITION LIST keep LIST in the clause head. - Default maxLineWidth is 50; fixtures pin width 80 unless they set it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * formatter: check the phrase table against the grammar, add capitalize Two changes that both come from the same idea: the grammar is the source of truth, so the formatter should read it rather than repeat it. Grammar drift test. The phrase table that drives layout is hand-written while QuestDB syntax arrives through the parser, so the two drift apart silently and an unknown clause stays inline instead of starting a line. tests/formatter/grammar-drift.test.ts reads the grammar through Chevrotain and fails when a statement rule can start a part with a keyword sequence the formatter neither breaks on nor lists as inline by design, and when a phrase in the table no longer exists in the grammar. It found six gaps, fixed here with fixtures: - LATEST BY, the legacy form of LATEST ON, was not a clause - UPDATE ... FROM t JOIN u did not break its joins - ALTER TABLE SUSPEND WAL, REBASE WAL and the storage policy actions stayed inline while ADD COLUMN started a line - ALTER MATERIALIZED VIEW DROP EXPIRE stayed inline - EXPIRE ROWS was not a CREATE option - UNPIVOT was in the table but never in the grammar Capitalize option. format(sql, { capitalize: true }) uppercases the keywords. Casing cannot be decided from the word alone, since QuestDB has about 60 reserved keywords and 350 non-reserved ones, and the non-reserved group holds most type and option words, which are also the most common column names. So it parses the statement and reads the answer off the tree: a word the grammar consumed through its identifier rule names a table, view or column and keeps its case, every other keyword is raised, and SQL that does not parse keeps the case it was written in. Layout stays the same either way and needs no lists. The corpus test formats every parseable query this way and requires that the words the grammar read as names come back with their exact case. maxLineWidth is renamed to maxWidth. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * formatter: measure the shape of the cost, not the clock The 5,000-line budget failed on CI at 98 ms against 80 ms, while the same script measures 22 ms locally and 23 ms on the commit before the formatter changes, so nothing had slowed down. The budget was four times a local median taken before the corpus grew, and this file runs beside suites that saturate a shared runner. Assert how the cost grows instead, which no machine speed can move: ten times the script must cost less than twenty five times the work, and four times the nesting less than twelve times. Measured today those are 7.5 to 9.4 times and 2.4 times. A loose ceiling still catches a hang. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the grammar tokens for QuestDB Enterprise resource groups, which are
currently absent from the parser, so
CREATE RESOURCE GROUPgets nohighlighting and
resource_groups()is not offered in autocomplete.Two commits, the second unrelated to the feature and separated deliberately.
1. Resource group tokens
keywords.tsmapping,priority,resource,unsetconstants.tscpu_weight,max_active_queries,max_queued_queries,memory_limit,queue_timeout,unlimitedfunctions.tscurrent_resource_group(scalar),resource_groups(table valued)Covers
CREATE/ALTER/DROP RESOURCE GROUP, theSET/UNSET RESOURCE GROUPclauses on
ALTER USER,ALTER GROUPandALTER SERVICE ACCOUNT, and theWITH (...)policy parameters.The policy parameter names go in
constants.tsalongside the existingparameter-shaped entries such as
max_identifier_length,search_path,transaction_isolation,skip_columnandskip_row.unlimitedalso completesSET MEMORY LIMIT UNLIMITED, which shipped withoutits constant. That makes #27 redundant: its other half, the
memorykeyword,is already on master, which is presumably why it now conflicts. Suggest closing
#27 in favour of this.
2. Alphabetical order in
keywords.tsSix pre-existing entries were out of order. Sorting only, nothing added or
removed:
constants.tswas already sorted.functions.tsis deliberately untouched:its
tableValuedFunctionsarray is split by comments into CURSOR and STANDARDsubsections, each sorted internally, and flattening them would break the
grouping the suggestion builder relies on for gating
pg_-prefixed entries.Verification
tsc --noEmitcleanyarn test: 9 files, 7000 tests passing, including the ~1,800 documentationqueries in
docs-parse,docs-roundtripanddocs-autocompletecounts and set membership checked before and after the reorder
Documented on the QuestDB docs side in the resource groups branch.