SQL parser: StrictFragmentValidator refuses GROUP BY GROUPING SETS as Unparseable (ad-hoc SQL rejected)

Abierto
#6,941 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MemberJunction/MJ

Todos los issues de MemberJunction/MJ

Issues similares

Más issues de Databases

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.