apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
19.91k stars 6.73k forks source link

Support parsing Oracle CREATE OR sql #27080

Open FlyingZC opened 1 year ago

FlyingZC commented 1 year ago

Background

Hi community, This issue is for #26878.

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

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

Task

This issue is to support more oracle sql parse, as follows:

CREATE OR REPLACE VIEW sales_view_ref AS
  SELECT country_name country,
         prod_name prod,
         calendar_year year,
         SUM(amount_sold) sale,
         COUNT(amount_sold) cnt
    FROM sales,times,customers,countries,products
    WHERE sales.time_id = times.time_id
      AND sales.prod_id = products.prod_id
      AND sales.cust_id = customers.cust_id
      AND customers.country_id = countries.country_id
      AND ( customers.country_id = 52779
            OR customers.country_id = 52776 )
      AND ( prod_name = 'Standard Mouse'
            OR prod_name = 'Mouse Pad' )
    GROUP BY country_name,prod_name,calendar_year;

SELECT country, prod, year, sale
  FROM sales_view_ref
  ORDER BY country, prod, year;
CREATE PROFILE new_profile
  LIMIT PASSWORD_REUSE_MAX 10
        PASSWORD_REUSE_TIME 30;
CREATE PROFILE clerk LIMIT
    SESSIONS_PER_USER 1
    IDLE_TIME 30
    CONNECT_TIME 600;

CREATE USER jfee
    IDENTIFIED BY password
    DEFAULT TABLESPACE users
    TEMPORARY TABLESPACE temp_ts
    QUOTA 500K ON users
    PROFILE clerk;

CREATE USER dcranney
    IDENTIFIED BY password
    DEFAULT TABLESPACE users
    TEMPORARY TABLESPACE temp_ts
    QUOTA unlimited ON users;

CREATE USER userscott
     IDENTIFIED BY password;
CREATE PROFILE prof LIMIT
 FAILED_LOGIN_ATTEMPTS 10
 PASSWORD_LOCK_TIME 30;
ALTER USER johndoe PROFILE prof;
CREATE PROFILE app_user2 LIMIT
   FAILED_LOGIN_ATTEMPTS 5
   PASSWORD_LIFE_TIME 60
   PASSWORD_REUSE_TIME 60
   PASSWORD_REUSE_MAX 5
   PASSWORD_VERIFY_FUNCTION verify_function
   PASSWORD_LOCK_TIME 1/24
   PASSWORD_GRACE_TIME 10;

Process

  1. First confirm that this is a correct oracle sql syntax, if not please ignore;
  2. Compare SQL definitions in Oficial 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 Statment 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 Oracle SQLs
github-actions[bot] commented 1 year ago

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

lancelly commented 1 year ago

Hi, is there anyone in the community currently working on this issue?

strongduanmu commented 1 year ago

Hi, is there anyone in the community currently working on this issue?

No, do you want to finish this task?

lancelly commented 1 year ago

Hi, is there anyone in the community currently working on this issue?

No, do you want to finish this task?

I think this pr: https://github.com/apache/shardingsphere/pull/28432 has finished the task.

strongduanmu commented 1 year ago

Hi, is there anyone in the community currently working on this issue?

No, do you want to finish this task?

I think this pr: #28432 has finished the task.

Can you test these sqls? If all sqls have been supported, I will close this issue.

lancelly commented 1 year ago

Hi, is there anyone in the community currently working on this issue?

No, do you want to finish this task?

I think this pr: #28432 has finished the task.

Can you test these sqls? If all sqls have been supported, I will close this issue.

Not all SQLs are supported, I only tested the sql of create view as I need it.

strongduanmu commented 1 year ago

If you are interested, you can try to finish this issue. @lancelly

github-actions[bot] commented 12 months ago

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

Yash-cor commented 1 day ago

Hello @strongduanmu these oracle queries are being parsed correctly

Example : CREATE PROFILE app_user2 LIMIT FAILED_LOGIN_ATTEMPTS 5 PASSWORD_LIFE_TIME 60 PASSWORD_REUSE_TIME 60 PASSWORD_REUSE_MAX 5 PASSWORD_VERIFY_FUNCTION verify_function PASSWORD_LOCK_TIME 1/24 PASSWORD_GRACE_TIME 10;

parseTree

Also I will add these test cases to tests -> it -> parsers -> resources -> sql. for Oracle SQL

Yash-cor commented 1 day ago

Could you please assign me with this issue.

Hello @strongduanmu these oracle queries are being parsed correctly

Example : CREATE PROFILE app_user2 LIMIT FAILED_LOGIN_ATTEMPTS 5 PASSWORD_LIFE_TIME 60 PASSWORD_REUSE_TIME 60 PASSWORD_REUSE_MAX 5 PASSWORD_VERIFY_FUNCTION verify_function PASSWORD_LOCK_TIME 1/24 PASSWORD_GRACE_TIME 10;

parseTree

Also I will add these test cases to tests -> it -> parsers -> resources -> sql. for Oracle SQL

Could you please assign me with this issue