apache / apache/datafusion-sqlparser-rs

parse error with in-column-select-statement

Abierto
#273 3 comentarios 0 reacciones 0 asignados Ver en GitHub
question
Lenguaje dominante
Rust
Estrellas
3.5k
Forks
772
Merge medio
4 d 9 h
PR fusionados (30 d)
17

Descripción

This mssqlserver view can't be parsed

the issue could be related to the in-column-statement, which for example is used at
- InheritDescriptions_actual
- PK_json

```sql
CREATE VIEW [integration].[Schema_Table] AS
SELECT
[Schema_Name] = [T2].[Schema_Name],
[Table_Name] = [T1].[Table_Name],
[AnonStatement] = [T1].[AnonStatement],
[CompressionTypeID] = [T1].[CompressionTypeID],
[Description] = [T1].[Description],
[DoNotExport] = [T1].[DoNotExport],
[DontInheritPK] = [T1].[DontInheritPK],
[FriendlyName] = [T1].[FriendlyName],
[Hashkey] = [T1].[Hashkey],
[HistOfTableID] = [T1].[HistOfTableID],
[HubOfTableID] = [T1].[HubOfTableID],
[InheritDescriptions] = [T1].[InheritDescriptions],
[InheritDescriptions_actual] = ISNULL([T1].[InheritDescriptions], -- Parameter_Name must exist in INTERN.PARAMETERS:
--(SELECT ParameterValue = COALESCE(PV.Param_Value, P.Default_Value, '') FROM INTERN.PARAMETERS P (NOLOCK) LEFT JOIN [CFG].[PARAM_VALUES] PV (NOLOCK) ON PV.Param_Name = P.Param_Name WHERE P.Param_Name = 'DESCRIPTION_INHERIT_TABLES')
--this works also for Custom-Parmeters, existing only in [CFG].[PARAM_VALUES]:
(SELECT ParameterValue = COALESCE(PV.Param_Value, P.Default_Value, '') FROM (SELECT Param_Name FROM INTERN.PARAMETERS (NOLOCK) UNION SELECT Param_Name FROM INTERN.PARAMETERS (NOLOCK)) AS U LEFT JOIN INTERN.PARAMETERS P (NOLOCK) ON P.Param_Name = U.Param_Name LEFT JOIN [CFG].[PARAM_VALUES] PV (NOLOCK) ON PV.Param_Name = U.Param_Name WHERE P.Param_Name = 'DESCRIPTION_INHERIT_TABLES')
),
[InheritFriendlyNames] = [T1].[InheritFriendlyNames],
[InheritFriendlyNames_actual] = ISNULL([T1].[InheritFriendlyNames], -- Parameter_Name must exist in INTERN.PARAMETERS:
--(SELECT ParameterValue = COALESCE(PV.Param_Value, P.Default_Value, '') FROM INTERN.PARAMETERS P (NOLOCK) LEFT JOIN [CFG].[PARAM_VALUES] PV (NOLOCK) ON PV.Param_Name = P.Param_Name WHERE P.Param_Name = 'FRIENDLYNAME_INHERIT_TABLES')
--this works also for Custom-Parmeters, existing only in [CFG].[PARAM_VALUES]:
(SELECT ParameterValue = COALESCE(PV.Param_Value, P.Default_Value, '') FROM (SELECT Param_Name FROM INTERN.PARAMETERS (NOLOCK) UNION SELECT Param_Name FROM INTERN.PARAMETERS (NOLOCK)) AS U LEFT JOIN INTERN.PARAMETERS P (NOLOCK) ON P.Param_Name = U.Param_Name LEFT JOIN [CFG].[PARAM_VALUES] PV (NOLOCK) ON PV.Param_Name = U.Param_Name WHERE P.Param_Name = 'FRIENDLYNAME_INHERIT_TABLES')
),
[InheritReferences] = [T1].[InheritReferences],
[IsInMemory] = [T1].[IsInMemory],
[LinkOfTableID] = [T1].[LinkOfTableID],
[OLAP_DataCategory] = [T1].[OLAP_DataCategory],
[OLAP_IsHidden] = [T1].[OLAP_IsHidden],
[PersistOfTableID] = [T1].[PersistOfTableID],
[Perspective] = [T1].[Perspective],
[SatOfTableID] = [T1].[SatOfTableID],
[SchemaID] = [T1].[SchemaID],
[SchemaName_TableName] = CONCAT(T2.Schema_Name, '.', [T1].[Table_Name]),
[SchemaName_TableName_brackets] = CONCAT('[', T2.Schema_Name, '].[', [T1].[Table_Name], ']'),
[TableID] = [T1].[TableID],
[TableType_Name] = [T3].[Type_Name],
[TableTypeID] = [T1].[TableTypeID],
[PK_json] = --sorted list of PK:
(
SELECT
[PK_Ordinal_Position] AS PK
, [Column_Name] AS C
FROM
[CFG].[COLUMNS] AS cfgc
WHERE
[T1].[TableID] = cfgc.[TableID]
AND NOT [PK_Ordinal_Position] IS NULL
ORDER BY [PK_Ordinal_Position]
FOR JSON AUTO
)
FROM
[CFG].[TABLES] T1 (NOLOCK)
LEFT JOIN [CFG].[SCHEMAS] T2 (NOLOCK) ON
T2.[SchemaID] = T1.[SchemaID]
LEFT JOIN [INTERN].[TABLE_TYPES] T3 (NOLOCK) ON
T3.[TableTypeID] = T1.[TableTypeID]
WHERE
1 = 1
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza reproduciendo la vista MSSQL proporcionada, centrándote en las subconsultas escalares dentro de las columnas y en la expresión PK_json que usa ORDER BY y FOR JSON AUTO. Sigue cómo se analiza este SQL y añade cobertura para el ejemplo; se considera terminado cuando la vista se analiza correctamente sin introducir regresiones en la sintaxis MSSQL relacionada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust, sql
Área
compilers, databases
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.