shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Support parsing Oracle CREATE OR sql

Open FlyingZC opened this issue 2 years ago • 8 comments

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

FlyingZC avatar Jul 13 '23 06:07 FlyingZC

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[bot] avatar Aug 12 '23 20:08 github-actions[bot]

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

lancelly avatar Oct 02 '23 03:10 lancelly

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

No, do you want to finish this task?

strongduanmu avatar Oct 02 '23 05:10 strongduanmu

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.

lancelly avatar Oct 02 '23 05:10 lancelly

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.

strongduanmu avatar Oct 02 '23 06:10 strongduanmu

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.

lancelly avatar Oct 02 '23 08:10 lancelly

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

strongduanmu avatar Oct 04 '23 01:10 strongduanmu

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[bot] avatar Nov 03 '23 20:11 github-actions[bot]

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 avatar Oct 31 '24 06:10 Yash-cor

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

Yash-cor avatar Oct 31 '24 07:10 Yash-cor