Skip to content

feat: add Oracle PL/SQL support (.pkb/.pks/.pls/.plb)#1994

Open
ezadEzanee wants to merge 1 commit into
Graphify-Labs:v8from
ezadEzanee:feat/plsql-support
Open

feat: add Oracle PL/SQL support (.pkb/.pks/.pls/.plb)#1994
ezadEzanee wants to merge 1 commit into
Graphify-Labs:v8from
ezadEzanee:feat/plsql-support

Conversation

@ezadEzanee

Copy link
Copy Markdown

Summary

Adds Oracle PL/SQL language support to graphify's detection, registration, and extraction pipeline, enabling graphify to parse and extract knowledge from PL/SQL source files (.pkb, .pks, .pls, .plb).

Changes

1. graphify/detect.py — File classification

Added .pkb, .pks, .pls, .plb to CODE_EXTENSIONS so PL/SQL files are classified as code and processed by the extractor pipeline.

2. graphify/extract.py — Extension routing

  • Route all four PL/SQL extensions to extract_sql in the _DISPATCH table
  • Register them in _EXTRA_FOR_EXTENSION as requiring the [sql] optional dependency

3. graphify/extractors/sql.py — PL/SQL-aware SQL extractor

The SQL extractor now supports both tree-sitter-sql (standard SQL) and tree-sitter-plsql (Oracle PL/SQL), with graceful fallback:

  • Grammar detection: tries tree_sitter_plsql first, falls back to tree_sitter_sql
  • PL/SQL object extraction: creates package, package body, function, procedure, cursor, and type definition nodes
  • SQL statement analysis: extracts table references from sql_statement_select, sql_statement_insert, sql_statement_update, sql_statement_delete, and sql_statement_merge
  • CREATE TABLE support: handles PL/SQL grammar's table_element > table_column_definition / table_constraint structure, including FOREIGN KEY REFERENCES
  • Regex fallback: recovers packages, procedures, functions, cursors, and types from SQL*Plus extracts that lack CREATE OR REPLACE headers
  • FROM/JOIN/INTO references: extracts read edges from table references within PL/SQL blocks

Example

With tree-sitter-plsql installed, graphify will now extract packages, procedures, functions, table operations, and cross-references from files like:

CREATE OR REPLACE PACKAGE BODY emp_mgmt AS
  PROCEDURE hire_employee(p_emp_id NUMBER) IS
  BEGIN
    INSERT INTO employees VALUES (p_emp_id, ...);
  END;
END emp_mgmt;

Dependencies

The [sql] optional dependency in pyproject.toml will need tree-sitter-plsql added once published to PyPI.

Add support for Oracle PL/SQL (.pkb, .pks, .pls, .plb) files across
detection, extraction, and file routing:

- detect.py: add .pkb, .pks, .pls, .plb to CODE_EXTENSIONS so PL/SQL
  files are classified as code
- extract.py: route .pkb/.pks/.pls/.plb extensions to extract_sql and
  declare them as requiring the optional [sql] dependency
- extractors/sql.py: support tree-sitter-plsql grammar with automatic
  fallback to tree-sitter-sql:
  * PL/SQL-specific node types: create_package, create_package_body,
    function_declaration/definition, procedure_declaration/definition,
    cursor_definition, type_definition_*, exception_declaration
  * SQL statement extraction: table references from sql_statement_select,
    sql_statement_insert/update/delete/merge
  * CREATE TABLE support for PL/SQL grammar (identifier-based names,
    table_element > table_column_definition / table_constraint)
  * Regex fallback for SQL*Plus extracts without CREATE OR REPLACE headers
  * FROM/JOIN/INTO table reference extraction within PL/SQL blocks
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.

1 participant