apache / apache/datafusion-sqlparser-rs

parse error with in-column-select-statement

Aperta
#273 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
Rust
Stelle
3.5k
Fork
772
Merge medio
4g 9h
PR unite (30g)
17

Descrizione

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
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia riproducendo la vista MSSQL fornita, concentrandoti sulle sottoquery scalari nelle colonne e sull'espressione PK_json che usa ORDER BY e FOR JSON AUTO. Traccia il modo in cui viene analizzato questo SQL e aggiungi la copertura per l'esempio; il lavoro è completato quando la vista viene analizzata correttamente senza introdurre regressioni nella sintassi MSSQL correlata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust, sql
Ambito
compilers, databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.