Skip to content

Conversation

KeilorRodriguez
Copy link

Add DECLARE VARIABLE support for Oracle variable declarations (#762 )

Summary

This PR introduces support for Oracle-style variable declarations using the DECLARE VARIABLE syntax in the transpiler. It enhances compatibility with Databricks by mapping Oracle types to their appropriate equivalents and ensures backward compatibility with existing functionality.

Problem Solved

Before:
p_date_start NUMBER;p_date_start AS NUMBER

After:
p_date_start NUMBER;DECLARE VARIABLE p_date_start BIGINT

Implementation Details

  • Added _oracle_variable_declaration_sql() to databricks.py to detect Oracle variable declarations.
  • Integrated the function into the TRANSFORMS dictionary to handle exp.Alias expressions.
  • Expanded Oracle-to-Databricks type mappings for comprehensive coverage.

Oracle Type Mappings

Oracle Type Databricks Type
NUMBER, INTEGER, INT BIGINT
VARCHAR2, VARCHAR, CHAR, NCHAR, NVARCHAR2 STRING
DATE DATE
TIMESTAMP, TIMESTAMPTZ, TIMESTAMPLTZ TIMESTAMP
DECIMAL, NUMERIC DECIMAL
FLOAT, DOUBLE DOUBLE
CLOB, NCLOB STRING
BLOB, RAW BINARY

Testing

  • ✅ Created unit tests in test_oracle_variable_declarations.py
  • ✅ Added functional test files:
    • test_variable_declarations/
    • test_variable_declarations_1.sql
    • test_variable_declarations_1.databricks.sql
  • ✅ All 488 existing transpiler tests pass
  • ✅ All new Oracle variable declaration tests pass

Key Features

  • Smart Detection: Only converts Oracle variable declarations, not regular aliases.
  • Comprehensive Type Mapping: Supports all major Oracle data types.
  • Backward Compatible: No regressions in existing functionality.
  • Well Tested: 12 new test cases plus full test suite coverage.

Closes #762

@KeilorRodriguez KeilorRodriguez requested a review from a team as a code owner July 24, 2025 04:00
@KeilorRodriguez KeilorRodriguez force-pushed the feature/declare-variable-support branch 2 times, most recently from 978d9bb to 7ff73ae Compare July 24, 2025 04:34
@KeilorRodriguez KeilorRodriguez force-pushed the feature/declare-variable-support branch from 7ff73ae to d289868 Compare July 24, 2025 04:41
@KeilorRodriguez KeilorRodriguez changed the title Successfully implemented the DECLARE VARIABLE feature for Oracle variable declarations. Implemented the DECLARE VARIABLE feature for Oracle variable declarations. Jul 24, 2025
@KeilorRodriguez KeilorRodriguez force-pushed the feature/declare-variable-support branch 2 times, most recently from e8c6a78 to 1226d4a Compare July 24, 2025 15:53
@KeilorRodriguez
Copy link
Author

@sundarshankar89 can I get somebody to review this PR?

@KeilorRodriguez KeilorRodriguez force-pushed the feature/declare-variable-support branch from ff649b3 to cb70076 Compare July 24, 2025 16:02
@sundarshankar89
Copy link
Collaborator

@KeilorRodriguez Thanks for the PR, we don't use SQLGLOT extensions for code conversion, I will assign 762 to our developers to fix.

@sundarshankar89
Copy link
Collaborator

sundarshankar89 commented Sep 16, 2025

Closing this PR as we have a ticket to address this.

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.

[FEATURE]: Add DECLARE VARIABLE to variable declarations
2 participants