SQL parser: StrictFragmentValidator refuses GROUP BY GROUPING SETS as Unparseable (ad-hoc SQL rejected)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- sql, typescript
- Ambito
- databases
Direzione di ricerca
Start with the StrictFragmentValidator.ValidateReadOnlyStatement path in the sql-parser package and find where GROUP BY clause parsing handles ROLLUP and CUBE, since those pass. Reproduce with the GROUPING SETS statement from the issue and confirm it returns Unparseable while IsReadOnlyQuery accepts it. Done when the GROUPING SETS statements, including the CTE form, validate as read-only and the ROLLUP and CUBE cases still pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
On MJ 6.2.2, StrictFragmentValidator.ValidateReadOnlyStatement refuses any SQL Server query that uses GROUP BY GROUPING SETS as Unparseable ("the SQL could not be parsed"). The statement is a plain read. ROLLUP, CUBE and GROUPING() all pass, and the token-based IsReadOnlyQuery accepts the same SQL.
Because the strict validator gates ad-hoc SQL in MJServer, a valid read-only report that uses GROUPING SETS can't be run ad hoc.
Repro (@memberjunction/sql-parser 6.2.2, SQLServerDialect)
const { StrictFragmentValidator, IsReadOnlyQuery } = require('@memberjunction/sql-parser');
const { SQLServerDialect } = require('@memberjunction/sql-dialect');
const dialect = new SQLServerDialect();
const sql = "SELECT Region, Stage, COUNT(*) AS n FROM dbo.T GROUP BY GROUPING SETS ((Region, Stage), (Region), ())";
StrictFragmentValidator.ValidateReadOnlyStatement(sql, dialect);
// { IsValid: false, Refusal: 'Unparseable', Reason: 'the SQL could not be parsed' }
IsReadOnlyQuery(sql, dialect);
// { IsReadOnly: true }
| Statement | ValidateReadOnlyStatement |
IsReadOnlyQuery |
|---|---|---|
GROUP BY GROUPING SETS ((a, b), (a), ()) |
Unparseable | read-only |
same inside a WITH CTE query |
Unparseable | read-only |
GROUP BY ROLLUP (a) |
valid | read-only |
GROUP BY CUBE (a, b) |
valid | read-only |
GROUPING(a) with ROLLUP |
valid | read-only |
Where it bites
ResolverBase.assertFullQueryUsesReadableEntityViews runs the strict validator. That check is called from:
AdhocQueryResolver(ad-hoc SQL, including re-running a saved query's SQL from an artifact)GetDataContextDataResolver(data context SQL)TestQuerySQLResolver(transient test SQL)
The resulting error is Invalid ad-hoc SQL: not a safe read-only statement — refusing under uncertainty. Saved queries run through RunQuery aren't affected.
Found on a client deployment: a shared report that uses GROUPING SETS for region subtotals and a grand total failed when re-run ad hoc. The client rewrote it with UNION ALL as a workaround.
Expected
GROUPING SETS (T-SQL, and PostgreSQL, which supports the same syntax) should parse, and the statement should be accepted as read-only like ROLLUP and CUBE. Failing closed on unreadable SQL is right, but this is standard read syntax the parser should know.
- Lingua principale
- TSQL
- Stelle
- 32
- Fork
- 7
- Merge medio
- 1g 16h
- PR unite (30g)
- 504
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MemberJunction/MJ
-
DBAutoDoc: export --state-file writes SQL Server SQL for a PostgreSQL database, ignoring --providerAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
MemberJunction/MJ#7094 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
MemberJunction/MJ#6971 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
MemberJunction/MJ#6947 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MemberJunction/MJ#6800 ·
I maintainer di solito rispondono entro 1 giorno
-
Convention: saved-query discoverability follows Status — Approved is canon, Pending is a draftAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
MemberJunction/MJ#6746 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MemberJunction/MJ
Issue simili
-
flakybot: issue priority: p2 type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
GoogleCloudPlatform/cloud-sql-nodejs-connector#658 ·
I maintainer di solito rispondono entro 1 giorno
-
factory:subtask
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
SUM over a union column should skip an undefined slot, not throw ArrayIndexOutOfBoundsExceptionApertaexpression engine unshaved-yak
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Invalid-MissingHash/Commit/NotAC
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
azerothcore/azerothcore-wotlk#28636 ·
I maintainer di solito rispondono entro 1 giorno
-
bug has-work-around priority: high
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
liberation-data/drivine#908 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno