FlyingZC opened a new issue, #27074:
URL: https://github.com/apache/shardingsphere/issues/27074

   # 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:
   ```sql
   CREATE OR REPLACE VIEW purchaseorder_detail_view AS
     SELECT po.reference, li.*
       FROM purchaseorder p,
            XMLTable('/PurchaseOrder' PASSING p.OBJECT_VALUE
                     COLUMNS
                       reference VARCHAR2(30) PATH 'Reference',
                       lineitem  XMLType      PATH 'LineItems/LineItem') po,
            XMLTable('/LineItem' PASSING po.lineitem
                     COLUMNS
                       itemno      NUMBER(38)    PATH '@ItemNumber',
                       description VARCHAR2(256) PATH 'Description',
                       partno      VARCHAR2(14)  PATH 'Part/@Id',
                       quantity    NUMBER(12, 2) PATH 'Part/@Quantity',
                       unitprice   NUMBER(8, 4)  PATH 'Part/@UnitPrice') li;
   ```
   
   ```sql
   CREATE OR REPLACE VIEW department_xml OF XMLType
     WITH OBJECT ID (substr(
                       XMLCast(
                         XMLQuery('$p/Department/Name'
                                  PASSING OBJECT_VALUE AS "p" RETURNING CONTENT)
                         AS VARCHAR2(30)),
                       1,
                       128))
     AS
     SELECT XMLElement(
              "Department",
              XMLAttributes(d.department_id AS "DepartmentId"),
              XMLForest(d.department_name AS "Name"),
              XMLElement("Location", XMLForest(street_address AS "Address",
                                               city AS "City",
                                               state_province AS "State",
                                               postal_code AS "Zip",
                                               country_name AS "Country")),
              XMLElement(
                "EmployeeList",
                (SELECT XMLAgg(
                          XMLElement(
                             "Employee",
                             XMLAttributes(e.employee_id AS "employeeNumber"),
                             XMLForest(e.first_name AS "FirstName",
                                       e.last_name AS "LastName",
                                       e.email AS "EmailAddress",
                                       e.phone_number AS "PHONE_NUMBER",
                                       e.hire_date AS "StartDate",
                                       j.job_title AS "JobTitle",
                                       e.salary AS "Salary",
                                       m.first_name || ' ' ||
                                       m.last_name AS "Manager"),
                             XMLElement("Commission", e.commission_pct)))
                   FROM hr.employees e, hr.employees m, hr.jobs j
                   WHERE e.department_id = d.department_id
                     AND j.job_id = e.job_id
                     AND m.employee_id = e.manager_id))).extract('/*')
       AS XML
       FROM hr.departments d, hr.countries c, hr.locations l
       WHERE d.location_id = l.location_id
         AND l.country_id  = c.country_id;
   ```
   
   ```sql
   CREATE OR REPLACE VIEW dept_xml OF XMLType
     XMLSCHEMA "http://www.oracle.com/dept.xsd"; ELEMENT "Department"
     WITH OBJECT ID (XMLCast(XMLQuery('/Department/DeptNo'
                                      PASSING OBJECT_VALUE RETURNING CONTENT)
                             AS BINARY_DOUBLE)) AS
     SELECT XMLElement(
       "Department",
       XMLAttributes(
         'http://www.oracle.com/emp.xsd' AS "xmlns" ,
         'http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi",
         'http://www.oracle.com/dept.xsd
          http://www.oracle.com/dept.xsd' AS "xsi:schemaLocation"),
       XMLForest(d.department_id "DeptNo",
                 d.department_name "DeptName",
                 d.location_id "Location"),
       (SELECT XMLagg(
                 XMLElement("Employee",
                            XMLForest(
                              e.employee_id  "EmployeeId",
                              e.last_name "Name",
                              e.job_id "Job",
                              e.manager_id "Manager",
                              to_char(e.hire_date,'YYYY-MM-DD') "Hiredate",
                              e.salary "Salary",
                              e.commission_pct "Commission")))
          FROM employees e
          WHERE e.department_id = d.department_id))
        FROM departments d;
   ```
   
   ```sql
   CREATE OR REPLACE VIEW dept_xml OF XMLType
     XMLSCHEMA "http://www.oracle.com/dept_complex.xsd"; ELEMENT "Department"
     WITH OBJECT ID (XMLCast(XMLQuery('/Department/DEPTNO'
                                      PASSING OBJECT_VALUE RETURNING CONTENT)
                             AS BINARY_DOUBLE)) AS
     SELECT dept_t(d.department_id, d.department_name, d.location_id,
                   cast(MULTISET
                        (SELECT emp_t(e.employee_id, e.last_name, e.job_id,
                                      e.manager_id, e.hire_date,
                                      e.salary, e.commission_pct) 
                           FROM employees e WHERE e.department_id = 
d.department_id) 
                        AS emplist_t))
       FROM departments d;
   ```
   
   ```sql
   CREATE OR REPLACE VIEW dept_xml of XMLType
     XMLSchema "http://www.oracle.com/dept_t.xsd"; element "Department"
     WITH OBJECT ID (XMLCast(XMLQuery('/Department/DEPTNO'
                                      PASSING OBJECT_VALUE RETURNING CONTENT)
                             AS BINARY_DOUBLE)) AS
     SELECT dept_t(d.department_id, d.department_name, d.location_id) 
       FROM departments d;
   
   INSERT INTO dept_xml 
     VALUES (
       XMLType.createXML(
         '<Department 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
            xsi:noNamespaceSchemaLocation="http://www.oracle.com/dept_t.xsd"; >
            <DEPTNO>300</DEPTNO>
            <DNAME>Processing</DNAME>
            <LOC>1700</LOC>
          </Department>'));
   
   UPDATE dept_xml d 
    SET d.OBJECT_VALUE = updateXML(d.OBJECT_VALUE, '/Department/DNAME/text()',  
                                   'Shipping')
      WHERE XMLExists('/Department[DEPTNO=300]' PASSING OBJECT_VALUE);
   ```
   
   # 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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to