Databricks Labs Lakebridge

repository·main·Indexed 41 days ago

https://github.com/databrickslabs/lakebridge

An experimental open-source project from Databricks Labs for data lake exploration and bridging. It includes a Lakebridge Analyzer that assigns complexity scores (LOW, MEDIUM, HIGH, VERY HIGH) to SQL objects and ETL jobs from platforms such as Teradata, DataStage, Talend, SSIS, Alteryx, BODS, Pentaho, and SAS to prioritize migration efforts.

Tokens
74.7K
Snippets
165
Records
309
Agent score
51%

What's inside Lakebridge

  1. Available Source Systems for Conversion

    main

    Lakebridge provides specialized conversion guides for migrating logic from various enterprise ETL and data warehouse platforms to Databricks. Currently supported source systems include:

    • Microsoft SSIS: Migrates SQL Server Integration Services to Databricks Notebooks.
    • Amazon Redshift: Migrates Redshift SQL to Databricks SQL using comprehensive transformation rules.
    • IBM DataStage: Migrates DataStage jobs (Parallel, Sequence, and Shared Containers) to Databricks Notebooks using SparkSQL or PySpark.
  2. What is Morpheus and when to use it

    main

    Morpheus is Lakebridge's AST-based SQL transpiler that converts source SQL into Databricks SQL. It provides a strong correctness guarantee: if a file is transpiled without any errors or warnings, it is guaranteed to produce equivalent results on Databricks as the original file did on the source platform.

    Supported Source Dialects:

    • mssql: Microsoft SQL Server, Azure SQL Database, Azure SQL Managed Instance, Amazon RDS for SQL Server
    • snowflake: Snowflake (including dbt repointing)
    • synapse: Azure Synapse Analytics (dedicated SQL pools)

    When NOT to use Morpheus:

    • If your source is an ETL tool (DataStage, SSIS), use BladeBridge.
    • If your source is Oracle, Teradata, or Redshift, use BladeBridge.
    • For any other dialect not listed above, use Switch.
  3. Overview of the Lakebridge Profiler

    main

    The Lakebridge Profiler is an experimental feature designed to extract and analyze metadata from database systems to aid in migration planning. It provides insights into source environments by capturing:

    • Database Metadata Extraction: Schema information, table structures, and object definitions.
    • Performance Analytics: Query execution metrics and resource utilization data.
    • Workload Analysis: Active query profiling and optimization identification.

    Note: The Profiler is currently an Experimental feature. Prerequisites for connection and metrics collection vary by source system.

  4. Overview of the Lakebridge migration workflow

    main

    Lakebridge is a toolkit for managing SQL migrations to Databricks through three primary phases:

    1. Pre-migration Assessment: Analyzing your existing landscape to understand Total Cost of Ownership (TCO) and migration complexity. This involves Profiling (connecting to existing environments to report on workload size and complexity) and Analyzing (scanning SQL code and orchestration to identify potential migration issues).
    2. Conversion: Translating SQL code, orchestration, and ETL code to Databricks SQL using various transpilers.
    3. Post-migration Reconciliation: Ensuring datasets transferred to Databricks match the source system, even in live environments.
  5. Interpret Assessment complexity scores

    main

    The Analyzer classifies SQL objects into four complexity levels. Use these to plan your manual review effort:

    • LOW / MEDIUM: Typically transpile cleanly; no manual review required.
    • HIGH: Should be reviewed after transpilation for any warnings.
    • VERY HIGH: Suggests a need for 2+ manual review passes before deployment.

    Note: For best results with the Analyzer, run the SQL Splitter first if your files contain multiple objects (e.g., stored procedures and tables mixed), so the Analyzer can provide per-object granularity.

  6. Interpret Lakebridge Analyzer complexity scores

    main

    The Lakebridge Analyzer assigns one of four complexity levels to each SQL object or ETL job. These scores are used to prioritize migration effort, estimate timelines, and identify objects requiring manual review.

    LevelMeaningTypical Action
    LOWSimple object; few statements, no loops, no complex constructsTranspile directly; little to no manual review expected
    MEDIUMModerate complexity; some loops, 10–30 statements, limited advanced SQLTranspile; review transpiler warnings before deploying
    HIGHHigh complexity; many loops, 30–50 statements, or advanced constructs (XML, PIVOT)Plan for manual review after transpilation; test thoroughly
    VERY HIGHHighest complexity; heavy loop nesting, 50+ statements, or extreme PIVOT/XML usageAllocate dedicated review time; consider using Switch for intent-aware conversion

    Planning Guidance

    • Review Passes: If >50% of objects are HIGH or VERY HIGH, plan for at least two manual review passes before deployment.
    • Transpilation Tools: LOW and MEDIUM objects typically transpile cleanly with Morpheus or BladeBridge.
    • Switch: HIGH and VERY HIGH objects are strong candidates for Switch, which handles complex business logic that deterministic transpilers may struggle with.
  7. Notebook Conversion Workflow (7-step pipeline)

    main

    For target_type=notebook or target_type=sdp, Switch executes the following sequential steps:

    1. analyze_input_files: Scans input directories and stores metadata/content in a Delta table.
    2. convert_with_llm: Sends content to a Model Serving Endpoint using prompts to generate new code.
    3. Validation:
      • If target is SDP: validate_sdp is called.
      • If target is NOT SDP: validate_python_notebook is called.
    4. fix_syntax_with_llm: Automatically attempts to correct errors found during validation.
    5. split_code_into_cells: Breaks raw Python code into logical notebook cells (imports, functions, etc.).
    6. export_to_notebook: Writes the final .py notebooks to the output directory.
    7. convert_notebook_to_sql (Optional): If sql_output_dir is provided, converts the Python notebooks into SQL notebooks.
  8. Convert Redshift REGEXP_COUNT and DECODE to Databricks SQL

    main

    Redshift-specific string and conditional functions are converted as follows:

    • REGEXP_COUNT(str, pattern) is converted to a combination of LENGTH and REGEXP_REPLACE: LENGTH(str) - LENGTH(REGEXP_REPLACE(str, pattern, '')).
    • DECODE(expr, v1, r1, v2, r2, default) is converted to an inline CASE WHEN expr=v1 THEN r1 WHEN expr=v2 THEN r2 ELSE default END statement.
    • CHARINDEX(substr, str) is converted to INSTR(str, substr) (note that the argument order is swapped).

    Example conversion:

    -- Redshift
    SELECT REGEXP_COUNT(email, '[A-Z]'), DECODE(val, 1, 'A', 2, 'B', 'C');
    
    -- Databricks
    SELECT LENGTH(email) - LENGTH(REGEXP_REPLACE(email, '[A-Z]', '')), CASE WHEN val=1 THEN 'A' WHEN val=2 THEN 'B' ELSE 'C' END;
    -- Redshift
    UPDATE customers
    SET loyalty_points = loyalty_points +
        CASE
            WHEN REGEXP_COUNT(email, '[A-Z]') > 3 THEN 100
            WHEN REGEXP_COUNT(email, '[0-9]') > 2 THEN 50
            ELSE 25
        END,
        status = DECODE(
            REGEXP_COUNT(phone, '[0-9]'),
            10, 'VERIFIED',
            11, 'VERIFIED',
            'PENDING'
        )
    WHERE customer_id IN (
        SELECT DISTINCT o.customer_id
        FROM orders o
        JOIN order_items oi ON o.order_id = oi.order_id
        WHERE o.order_date >= CURRENT_DATE - INTERVAL '30 days'
        AND o.total_amount > 500
    );
    
    -- Databricks
    UPDATE customers
    SET loyalty_points = loyalty_points +
        CASE
            WHEN LENGTH(email) - LENGTH(REGEXP_REPLACE(email, '[A-Z]', '')) > 3 THEN 100
            WHEN LENGTH(email) - LENGTH(REGEXP_REPLACE(email, '[0-9]', '')) > 2 THEN 50
            ELSE 25
        END,
        status = case when LENGTH(phone) - LENGTH(REGEXP_REPLACE(phone, '[0-9]', ''))=10 then 'VERIFIED' when LENGTH(phone) - LENGTH(REGEXP_REPLACE(phone, '[0-9]', ''))=11 then 'VERIFIED' else 'PENDING' END
    WHERE customer_id IN (
        SELECT DISTINCT o.customer_id
        FROM orders o
        JOIN order_items oi ON o.order_id = oi.order_id
        WHERE o.order_date >= CURRENT_DATE - INTERVAL '30 days'
        AND o.total_amount > 500
    );
  9. Configure BladeBridge execution via configuration files

    main

    BladeBridge execution is driven by a configuration file. You use this file to define the parameters for your migration project, including:

    • Input/output directories: Where to find source files and where to save translated code.
    • Source and target technologies: Specifying the origin platform (e.g., Oracle) and the target (Databricks).
    • Custom naming conventions: Controlling how objects are named in the target system.
    • Extension points: Defining converter plugins to extend the engine's capabilities.
  10. Understand the Lakebridge migration phases

    main

    Lakebridge is a toolkit for migrating data workloads to Databricks, organized into three distinct phases. You can use these phases independently depending on your migration stage:

    1. Assessment: Analyze existing SQL or ETL environments to understand complexity and effort.
    2. Transpilation: Convert source SQL or ETL code into Databricks-compatible formats (Databricks SQL, PySpark, or notebooks).
    3. Reconciliation: Validate that the migrated data matches the source to ensure fidelity.

    When to use which:

    • Assess only: For scoping a migration before committing.
    • Transpile only: For migrating code without needing pre-migration analysis or post-migration validation.
    • Reconcile only: For validating row/column fidelity after data has already been migrated.
  11. Select a Lakebridge Reconcile report type

    main

    Choose a report_type based on the level of reconciliation required:

    • schema: Validates that data types between source and target are the same or compatible. Outputs: schema_comparison, schema_difference.
    • row: Reconciles data at the row level using hash value comparison. Use this when there are no join columns. Outputs: missing_in_src, missing_in_tgt.
    • data: Reconciles data at both row and column level using join_columns to identify specific mismatches. Outputs: mismatch_data, missing_in_src, missing_in_tgt, threshold_mismatch, mismatch_columns.
    • all: A combination of data and schema reports.