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

[DBMON-3057] create Oracle test suite #26

Merged
merged 3 commits into from
Nov 14, 2023
Merged

Conversation

lu-zhengda
Copy link
Collaborator

@lu-zhengda lu-zhengda commented Nov 13, 2023

This PR creates test suite for Oracle DBMS. Similar as the Postgres PR, the goal is to have a comprehensive list of Oracle specific SQL statements that we can leverage to verify the completeness and correctness of the package.

Highlight some test cases to very several Oracle-specific syntax and features:

  • Hierarchical Queries: Using the START WITH ... CONNECT BY clause
  • CTEs
  • PL/SQL Blocks
  • Stored Procedures and Functions
  • Triggers
  • Packages
  • Oracle-specific joins like (+) for outer joins
  • Flashback Queries: Using AS OF clauses
  • Pipelined Functions
  • Oracle-Specific SQL Constructs: Such as DECODE, NVL, DBMS_OUTPUT.PUT_LINE, SYS_REFCURSOR, RAISE_APPLICATION_ERROR, and the use of sequences like NEXTVAL and CURRVAL.
  • Dynamic PL/SQL
  • Bulk Operations: Using BULK COLLECT and FORALL
  • Window Functions and Analytics: window functions like ROW_NUMBER, RANK, DENSE_RANK, etc.
  • LOBs
  • Error Handling and Exception: using RAISE and RAISE_APPLICATION_ERROR.

@lu-zhengda lu-zhengda marked this pull request as ready for review November 13, 2023 22:05
@lu-zhengda lu-zhengda requested a review from a team as a code owner November 13, 2023 22:05
"input": "DECLARE TYPE EmpTabTyp IS TABLE OF employees%ROWTYPE INDEX BY PLS_INTEGER; emp_tab EmpTabTyp; BEGIN SELECT * BULK COLLECT INTO emp_tab FROM employees; FORALL i IN emp_tab.FIRST .. emp_tab.LAST SAVE EXCEPTIONS UPDATE employees SET test = test * 1.05 WHERE employee_id = emp_tab(i).employee_id; END;",
"outputs": [
{
"expected": "DECLARE TYPE EmpTabTyp IS TABLE OF employees % ROWTYPE INDEX BY PLS_INTEGER; emp_tab EmpTabTyp; BEGIN SELECT * BULK COLLECT INTO emp_tab FROM employees; FORALL i IN emp_tab.FIRST . . emp_tab.LAST SAVE EXCEPTIONS UPDATE employees SET test = test * ? WHERE employee_id = emp_tab ( i ) . employee_id; END",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be correct to keep ; in the end. The program wouldn't execute otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. the trailing semicolon is controlled by KeepTrailingSemicolon and disabled by default.

"input": "DELETE FROM orders o WHERE o.customer_id IN (SELECT c.id FROM customers c WHERE NOT EXISTS (SELECT 1 FROM customer_orders co WHERE co.customer_id = c.id AND co.order_date > SYSDATE - 365)) AND EXISTS (SELECT 1 FROM order_items oi WHERE oi.order_id = o.id AND oi.product_id IN (SELECT p.id FROM products p WHERE p.category = 'Obsolete'));",
"outputs": [
{
"expected": "DELETE FROM orders o WHERE o.customer_id IN ( SELECT c.id FROM customers c WHERE NOT EXISTS ( SELECT ? FROM customer_orders co WHERE co.customer_id = c.id AND co.order_date > SYSDATE - ? ) ) AND EXISTS ( SELECT ? FROM order_items oi WHERE oi.order_id = o.id AND oi.product_id IN ( SELECT p.id FROM products p WHERE p.category = ? ) )",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add space before and after parentheses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's controlled by normalizer option RemoveSpaceBetweenParentheses. By default it's disabled and spaces will be added. I do have add test cases to make sure this config option works as expected, for example

"remove_space_between_parentheses": true

@@ -0,0 +1,27 @@
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, the procedure can be invoked with the key word EXEC instead of embedding it winto BEGIN END block.

Copy link
Collaborator Author

@lu-zhengda lu-zhengda Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test case invoke-stored-procedure-with-exec added

@lu-zhengda lu-zhengda merged commit 7c4b73d into main Nov 14, 2023
4 checks passed
@lu-zhengda lu-zhengda deleted the zhengda.lu/test-suite-oracle branch November 14, 2023 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants