apache / apache/datafusion-sqlparser-rs

parse error with in-column-select-statement

Open
#273 3 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Rust
Stars
3.5k
Forks
772
Avg merge
4d 9h
Merged PRs (30d)
17

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the supplied MSSQL view, focusing on the in-column scalar subqueries and the PK_json expression using ORDER BY and FOR JSON AUTO. Trace how this SQL is parsed and add coverage for the example; done means the view parses successfully without regressing related MSSQL syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
compilers, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.