Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parsing SQL Server SELECT Person1.name sql #29189

Closed
FlyingZC opened this issue Nov 24, 2023 · 10 comments
Closed

Support parsing SQL Server SELECT Person1.name sql #29189

FlyingZC opened this issue Nov 24, 2023 · 10 comments

Comments

@FlyingZC
Copy link
Member

Background

Hi community.
This issue is for #29149.

The ShardingSphere SQL parser engine helps users to parse SQL to create the AST (Abstract Syntax Tree) and visit the AST to get SQLStatement (Java Object). Currently, we are planning to enhance the support for SQL Server SQL parsing in ShardingSphere.

More details:
https://shardingsphere.apache.org/document/current/en/reference/sharding/parse/

Task

This issue is to support more SQL Server sql parsing, as follows:

SELECT
    Person1.name AS PersonName,
    STRING_AGG(Person2.name, '->') WITHIN GROUP (GRAPH PATH) AS Friends
FROM
    Person AS Person1,
    friendOf FOR PATH AS fo,
    Person FOR PATH  AS Person2
WHERE MATCH(SHORTEST_PATH(Person1(-(fo)->Person2)+))
AND Person1.name = 'Jacob'

link

SELECT PersonName, Friends, levels
FROM (
    SELECT
        Person1.name AS PersonName,
        STRING_AGG(Person2.name, '->') WITHIN GROUP (GRAPH PATH) AS Friends,
        LAST_VALUE(Person2.name) WITHIN GROUP (GRAPH PATH) AS LastNode,
        COUNT(Person2.name) WITHIN GROUP (GRAPH PATH) AS levels
    FROM
        Person AS Person1,
        friendOf FOR PATH AS fo,
        Person FOR PATH  AS Person2
    WHERE MATCH(SHORTEST_PATH(Person1(-(fo)->Person2)+))
    AND Person1.name = 'Jacob'
) AS Q
WHERE Q.LastNode = 'Alice'

link

SELECT
    Person1.name AS PersonName,
    STRING_AGG(Person2.name, '->') WITHIN GROUP (GRAPH PATH) AS Friends
FROM
    Person AS Person1,
    friendOf FOR PATH AS fo,
    Person FOR PATH  AS Person2
WHERE MATCH(SHORTEST_PATH(Person1(-(fo)->Person2){1,3}))
AND Person1.name = 'Jacob'

link

SELECT PersonName, Friends
FROM (
    SELECT
        Person1.name AS PersonName,
        STRING_AGG(Person2.name, '->') WITHIN GROUP (GRAPH PATH) AS Friends,
        COUNT(Person2.name) WITHIN GROUP (GRAPH PATH) AS levels
    FROM
        Person AS Person1,
        friendOf FOR PATH AS fo,
        Person FOR PATH  AS Person2
    WHERE MATCH(SHORTEST_PATH(Person1(-(fo)->Person2){1,3}))
    AND Person1.name = 'Jacob'
) Q
WHERE Q.levels = 2

link

SELECT
    Person1.name AS PersonName,
    STRING_AGG(Person2.name, '->') WITHIN GROUP (GRAPH PATH) AS Friends,
    Restaurant.name
FROM
    Person AS Person1,
    friendOf FOR PATH AS fo,
    Person FOR PATH  AS Person2,
    likes,
    Restaurant
WHERE MATCH(SHORTEST_PATH(Person1(-(fo)->Person2){1,3}) AND LAST_NODE(Person2)-(likes)->Restaurant )
AND Person1.name = 'Jacob'
AND Restaurant.name = 'Ginger and Spice'

link

Process

  1. First confirm that this is a correct SQL Server sql syntax, if not please leave a message under the issue and ignore it;
  2. Compare SQL definitions in Official SQL Doc and ShardingSphere SQL Doc;
  3. If there is any difference in ShardingSphere SQL Doc, please correct them by referring to the Official SQL Doc;
  4. Run mvn install the current_file_module;
  5. Check whether there are any exceptions. If indeed, please fix them. (Especially xxxVisitor.class);
  6. Add new corresponding SQL case in SQL Cases and expected parsed result in Expected Statement XML;
  7. Run SQLParserParameterizedTest to make sure no exceptions.

Relevant Skills

  1. Master JAVA language
  2. Have a basic understanding of Antlr g4 file
  3. Be familiar with SQL Server SQLs
Copy link

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

@github-actions github-actions bot added the stale label Dec 24, 2023
@shengdoupi
Copy link
Contributor

@FlyingZC Hi community, I will have a try. Please assign me.

@strongduanmu
Copy link
Member

@shengdoupi Welcome, I just assign this issue to you.

@github-actions github-actions bot removed the stale label Jan 19, 2024
Copy link

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

@github-actions github-actions bot added the stale label Feb 19, 2024
@TherChenYang
Copy link
Collaborator

@FlyingZC Please assign this issue to me.

@shengdoupi
Copy link
Contributor

@FlyingZC Please assign this issue to me.

@TherChenYang Hi, I'm working on this issue now. It takes me a long time since graph related syntax is quite complex for me. Anyway, I believe it can be finished in a week, thank you!

@github-actions github-actions bot removed the stale label Feb 22, 2024
@strongduanmu
Copy link
Member

Ok, looking forward to your good news @shengdoupi

@TherChenYang
Copy link
Collaborator

@FlyingZC Please assign this issue to me.

@TherChenYang Hi, I'm working on this issue now. It takes me a long time since graph related syntax is quite complex for me. Anyway, I believe it can be finished in a week, thank you!

Sorry, I see the issue is in an expired state, so I requested an assignment, look forward to your PR.

@shengdoupi
Copy link
Contributor

@strongduanmu Hi, when I try to submit a PR for this issue, I find the function has been supported in #30288 , I think you can close this issue now.

@strongduanmu
Copy link
Member

@shengdoupi Thank you for your test work, I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants