মূল বিষয়বস্তুতে যান

Run dbt Core on Spark (Kubernetes)

This guide explains how to set up dbt Coreসাথে অ্যাপাচি স্পার্ক running on a Kubernetes cluster. Using Ilum as the execution engine, you can run scalable data transformation pipelines directly on your data lake.

You have two primary ways to connect dbt to Spark on Ilum:

Thrift Server vs. Spark Connect

বৈশিষ্ট্য Method 1: Spark Thrift Server (Legacy)Method 2: Spark Connect (Modern)
ProtocolJDBC/ODBC (via HiveDriver)gRPC (via Spark Connect)
Connection Typeপদ্ধতি: মিতব্যয়িতা পদ্ধতি: সেশন
স্থাপত্য Requires a dedicated Thrift Server podConnects directly to Spark Driver
PerformanceHigher latency (row-based serialization)High performance (Arrow-based)
এর জন্য সেরা BI Tools (Tableau, PowerBI), Legacy appsData Engineering, Python/dbt pipelines
New to Spark Connect?

For a deep dive into the architecture, check out our Spark Connect on Kubernetes Guide.


পূর্বশর্ত

Before starting, ensure your development environment is ready:

  • Kubernetes Cluster : You need a running K8s cluster (GKE, EKS, AKS, or Minikube).
  • Tools:
  • Knowledge: Basic understanding of dbt projects and Spark concepts.

How to Configure dbt with Spark on Kubernetes

Choose your preferred connection method:

Step 1: Deploy Spark Thrift Server

Deploy Ilum with the SQL module (acting as a scalable Thrift server) and Hive Metastore enabled:

Helm Install
রেপো যোগ করুন https://charts.ilum.cloud 
Helm installation il and ile/el \
--সেট ilum-Hive-metastore.enabled=true \
--set ilum-core.metastore.enabled=true \
--set ilum-core.metastore.type=hive \
--সেট ilum-sql.enabled=true \
--সেট ilum-core.sql.সক্ষম=সত্য

Step 2: Connect to the Thrift Service

1. Identify the service:

Get Service
কুবেক্টল সেবা পান 

এর নামে "এসকিউএল-থ্রিফ্ট-বাইনারি" দিয়ে পরিষেবাটি সন্ধান করুন।

2. Port-forward:

Port Forward
কুবেক্টল পোর্ট-ফরোয়ার্ড এসভিসি / আইএলইউএম-এসকিউএল-থ্রিফ্ট-বাইনারি 10009: 10009 

এটি থ্রিফ্ট সার্ভারকে এখানে উপলব্ধ করে তোলে লোকালহোস্ট:10009 .

3. Test with Beeline (optional):

Beline -u "jdbc:hive2://localhost:10009/default" 

চালনা:

দেখান  টেবিল ; 

একটি খালি তালিকা বা বিদ্যমান টেবিল আশা করুন।

Configuring and Running dbt

1. Clean Environment (if needed):

Uninstall Conflict
পিপ আনইনস্টল ডিবিটি-স্পার্ক পাইস্পার্ক -ওয়াই 

2. Install dbt and dependencies:

Install dbt-spark
pip install pyspark==3.5.7
পিআইপি ইনস্টল ডিবিটি-কোর
পিপ ইনস্টল "ডিবিটি-স্পার্ক [পাইহাইভ, সেশন]"
pip install --upgrade thrift

3. Verify installation:

Verify dbt
ডিবিটি --সংস্করণ 

Create dbt Project

1. Initialize a dbt project:

Init Project
DBT init ilum_dbt_project 

2. Answer the setup prompts:

Setup Prompts
Which database? 1 (spark)
host: localhost
Desired authentication method: 3 (thrift)
port: 10009
schema: default
threads: 1

This creates the ilum_dbt_project directory and a profiles.yml file in ~/.dbt/.

Configure dbt for Ilum

সম্পাদনা ~/.dbt/profiles.yml to include both Thrift and Spark Connect targets:

~/.dbt/profiles.yml
ilum_dbt_project : 
লক্ষ্য : মিতব্যয়িতা # Default target
আউটপুট :
মিতব্যয়িতা :
টাইপ : স্ফুলিঙ্গ
পদ্ধতি : মিতব্যয়িতা
আয়োজক : লোকালহোস্ট
পোর্ট : 10009
স্কীমা : ডিফল্ট
থ্রেডসমূহ : 1
connect_retries : 5
connect_timeout : 60
connect_args :
ইউআরএল : "jdbc:hive2://localhost:10009/default; পরিবহনমোড = বাইনারি; হাইভ.সার্ভার 2.ট্রান্সপোর্ট.মোড = বাইনারি"
ড্রাইভার : "org.apache.hive.jdbc.HiveDriver"
অথ : "কেউ না"

spark_connect:
টাইপ : স্ফুলিঙ্গ
পদ্ধতি : সুসংবদ্ধ
আয়োজক : লোকালহোস্ট
পোর্ট : 15002
স্কীমা : ডিফল্ট
থ্রেডসমূহ : 1

Switch between targets:

Run dbt
# Use Thrift (default)
dbt run

# Use Spark Connect
dbt run --target spark_connect

# Or set default in dbt_project.yml
# target: spark_connect
  • টেস্ট সংযোগ:

    Debug dbt
    সিডি ilum_dbt_project 
    ডিবিটি ডিবাগ

    থ্রিফ্ট সার্ভারের সাথে একটি সফল সংযোগ নির্দেশ করে কোনও ত্রুটি উপস্থিত না হওয়া নিশ্চিত করুন।

Create a Model to Write Data

  • মডেল তৈরি করুন:

  • মডেল/sample_data.sql

    মডেল/sample_data.sql
    {{ কনফিগারেশন ( বাস্তবায়িত = 'টেবিল' ) }} 

    নির্বাচন
    আইডি ,
    নাম
    থেকে (
    মানসমূহ
    ( 1 , 'অ্যালিস' ) ,
    ( 2 , 'বব' )
    ) হিসেবে t ( আইডি , নাম )
  • রান মডেল:

    Run sample_data
    dbt run --select sample_data

Create a Model to Read Data

  • মডেল তৈরি করুন:

  • মডেল/read_data.sql

    মডেল/read_data.sql
    {{ কনফিগারেশন ( বাস্তবায়িত = 'টেবিল' ) }} 

    নির্বাচন
    আইডি ,
    নাম ,
    দৈর্ঘ্য ( নাম ) হিসেবে name_length
    থেকে {{ রেফ ( 'sample_data' ) }}
  • রান মডেল:

    Run read_data
    dbt run --select read_data

Verify Results

1. Monitor Job in Ilum UI:

  • Access the Ilum UI (URL provided in your Ilum setup, e.g. port-forward)

  • Navigate to the Jobs section

  • Look for the job named ilum-sql-spark-engine

  • Check job status, logs, and execution details to confirm successful processing

    2. Query with Beeline:

    Beline -u "jdbc:hive2://localhost:10009/default" 

    3. Run query:

    নির্বাচন  *  থেকে  ডিফল্ট . read_data ; 

    Expected output:

    +----+-----+------------+ 
    | আইডি | নাম | name_length|
    +----+-----+------------+
    | 1 | অ্যালিস | 5 |
    | 2 | বব | 3 |
    +----+-----+------------+

Troubleshooting dbt-spark Connections

Common issues when connecting dbt to Spark on Kubernetes:

Error: "ThriftTransportException: Could not connect to localhost:10009"

Cause: The port forwarding tunnel is down or the Thrift Server pod is not running. সমাধান :

  1. Check if the Thrift pod is running: kubectl get pods -l app.kubernetes.io/name=ilum-sql
  2. Restart port-forwarding: কুবেক্টল পোর্ট-ফরোয়ার্ড এসভিসি / আইএলইউএম-এসকিউএল-থ্রিফ্ট-বাইনারি 10009: 10009
Error: "grpc._channel._InactiveRpcError: failed to connect to all addresses"

Cause: Your local dbt client cannot reach the Spark Connect gRPC port (15002). সমাধান :

  • Ensure you have port-forwarded the Driver Pod, not the Service (unless using NodePort).
  • Verify you are using পদ্ধতি: সেশন মধ্যে profiles.yml.
Error: "AnalysisException: Table or view not found"

Cause: Hive Metastore connectivity issue. সমাধান :

  • Ensure ilum-core.metastore.enabled=true was set during Helm install.
  • Check if the schema (database) exists in Spark: spark.sql("SHOW DATABASES").show()

অর্কেস্ট্রেশন

For production orchestration using Apache Airflow, see the dedicated guide: Orchestrate dbt with Airflow