SQL parser: StrictFragmentValidator refuses GROUP BY GROUPING SETS as Unparseable (ad-hoc SQL rejected)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- sql, typescript
- Área
- databases
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TSQL
- Estrellas
- 32
- Forks
- 7
- Merge medio
- 1 d 16 h
- PR fusionados (30 d)
- 504
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de MemberJunction/MJ
-
DBAutoDoc: export --state-file writes SQL Server SQL for a PostgreSQL database, ignoring --providerAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
MemberJunction/MJ#7094 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
MemberJunction/MJ#6971 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
MemberJunction/MJ#6947 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
MemberJunction/MJ#6800 ·
Los mantenedores suelen responder en 1 día
-
Convention: saved-query discoverability follows Status — Approved is canon, Pending is a draftAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
MemberJunction/MJ#6746 ·
Los mantenedores suelen responder en 1 día
Todos los issues de MemberJunction/MJ
Issues similares
-
cleanup follow-up
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
flakybot: issue priority: p2 type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
GoogleCloudPlatform/cloud-sql-nodejs-connector#658 ·
Los mantenedores suelen responder en 1 día
-
factory:subtask
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
ConduitIO/conduit-connector-postgres#491 ·
Los mantenedores suelen responder en 1 día
-
SUM over a union column should skip an undefined slot, not throw ArrayIndexOutOfBoundsExceptionAbiertoexpression engine unshaved-yak
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día