Hive/Spark/Databricks to dbt Model Conversion
Purpose
Transform Hive/Spark/Databricks DDL (views, tables, UDFs) into production-quality dbt models
compatible with Snowflake, maintaining the same business logic and data transformation steps while
following dbt best practices.
When to Use This Skill
Activate this skill when users ask about:
- Converting Hive/Spark/Databricks views or tables to dbt models
- Migrating HiveQL UDFs to dbt
- Translating HiveQL syntax to Snowflake
- Generating schema.yml files with tests and documentation
- Handling Hive-specific syntax conversions (external tables, PARTITIONED BY, LATERAL VIEW, file
formats)
Task Description
You are a database engineer working for a hospital system. You need to convert Hive/Spark/Databricks
DDL to equivalent dbt code compatible with Snowflake, maintaining the same business logic and data
transformation steps while following dbt best practices.
Input Requirements
I will provide you the HiveQL DDL to convert.
Audience
The code will be executed by data engineers who are learning Snowflake and dbt.
Output Requirements
Generate the following:
- One or more dbt models with complete SQL for every column
- A corresponding schema.yml file with appropriate tests and documentation
- A config block with materialization strategy
- Explanation of key changes and architectural decisions
- Inline comments highlighting any syntax that was converted
Conversion Guidelines
General Principles
- Replace procedural logic with declarative SQL where possible
- Break down complex procedures into multiple modular dbt models
- Implement appropriate incremental processing strategies
- Maintain data quality checks through dbt tests
- Use Snowflake SQL functions rather than macros whenever possible
Sample Response Format
-- dbt model: models/[domain]/[target_schema_name]/model_name.sql
{{ config(materialized='view') }}
/* Original Object: [database].[object_name]
Source Platform: Hive/Spark/Databricks
Purpose: [brief description]
Conversion Notes: [key changes]
Description: [SQL logic description] */
WITH source_data AS (
SELECT
-- Hive BIGINT/INT converted to INTEGER
customer_id::INTEGER AS customer_id,
-- STRING converted to VARCHAR
customer_name::VARCHAR(100) AS customer_name,
-- DECIMAL converted to NUMBER
account_balance::NUMBER(18,2) AS account_balance,
-- TIMESTAMP converted to TIMESTAMP_NTZ
created_date::TIMESTAMP_NTZ AS created_date
FROM {{ ref('upstream_model') }}
),
transformed_data AS (
SELECT
customer_id,
UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,
account_balance,
created_date,
CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at
FROM source_data
)
SELECT
customer_id,
customer_name_upper,
account_balance,
created_date,
loaded_at
FROM transformed_data
## models/[domain]/[target_schema_name]/_models.yml
version: 2
models:
- name: model_name
description: "Table description; converted from Hive/Spark/Databricks [Original object name]"
columns:
- name: customer_id
description: "Primary key - unique customer identifier"
tests:
- unique
- not_null
- name: customer_name_upper
description: "Customer name in uppercase"
- name: account_balance
description: "Current account balance; Foreign key to OTHER_TABLE"
tests:
- relationships:
to: ref('OTHER_TABLE')
field: OTHER_TABLE_KEY
- name: created_date
description: "Date the customer record was created"
- name: loaded_at
description: "Timestamp when the record was loaded by dbt"
## dbt_project.yml (excerpt)
models:
my_project:
+materialized: view
domain_name:
+schema: target_schema_name
Specific Translation Rules
dbt Specific Requirements
- If the source is a view, use a view materialization in dbt
- Include appropriate dbt model configuration (materialization type)
- Add documentation blocks for a schema.yml
- Add descriptions for tables and columns
- Include relevant tests
- Define primary keys and relationships
- Assume that upstream objects are models
- Comprehensively provide all the columns in the output
- Break complex procedures into multiple models if needed
- Implement appropriate incremental strategies for large tables
- Use Snowflake SQL functions rather than macros whenever possible
- Always cast columns with explicit precision/scale using
::TYPE syntax (e.g.,
column_name::VARCHAR(100), amount::NUMBER(18,2)) to ensure output matches expected data types
- Always provide explicit column aliases for clarity and documentation
Performance Optimization
- Suggest clustering keys if needed
- Recommend materialization strategy (view vs table)
- Identify potential performance improvements
Hive/Spark to Snowflake Syntax Conversion
- Convert LATERAL VIEW to LATERAL FLATTEN
- Replace PARTITIONED BY with clustering keys
- Convert file format specifications (PARQUET, ORC) to Snowflake staging
- Handle EXTERNAL TABLE references
- Convert Hive UDFs to Snowflake equivalents
- Replace DISTRIBUTE BY/SORT BY with clustering
- Convert ARRAY/MAP/STRUCT types to VARIANT
Key Data Type Mappings
| Hive/Spark |
Snowflake |
Notes |
| TINYINT/SMALLINT/INT/BIGINT |
Same |
|
| FLOAT/DOUBLE |
FLOAT |
|
| DECIMAL |
DECIMAL |
|
| STRING |
VARCHAR |
|
| CHAR/VARCHAR |
Same |
|
| BOOLEAN |
BOOLEAN |
|
| BINARY |
BINARY |
|
| DATE |
DATE |
|
| TIMESTAMP |
TIMESTAMP_NTZ |
|
| ARRAY |
ARRAY |
|
| MAP<K,V> |
VARIANT |
Use OBJECT_CONSTRUCT |
| STRUCT |
VARIANT |
|
Key Syntax Conversions
-- LATERAL VIEW -> LATERAL FLATTEN
SELECT * FROM table LATERAL VIEW EXPLODE(array_col) t AS elem ->
SELECT * FROM table, LATERAL FLATTEN(input => array_col) AS f
-- PARTITIONED BY -> Clustering
CREATE TABLE t (...) PARTITIONED BY (dt STRING) ->
CREATE TABLE t (...) CLUSTER BY (dt)
-- External tables
CREATE EXTERNAL TABLE t LOCATION 's3://...' ->
CREATE EXTERNAL TABLE t WITH LOCATION = @stage/path
-- collect_list/collect_set
collect_list(col) -> ARRAY_AGG(col)
collect_set(col) -> ARRAY_AGG(DISTINCT col)
-- size() -> ARRAY_SIZE()
size(array_col) -> ARRAY_SIZE(array_col)
Common Function Mappings
| Hive/Spark |
Snowflake |
Notes |
collect_list(col) |
ARRAY_AGG(col) |
|
collect_set(col) |
ARRAY_AGG(DISTINCT col) |
|
size(arr) |
ARRAY_SIZE(arr) |
|
explode(arr) |
LATERAL FLATTEN(input => arr) |
|
posexplode(arr) |
LATERAL FLATTEN(input => arr) |
Use f.index |
concat_ws(sep, ...) |
CONCAT_WS(sep, ...) |
Same |
nvl(a, b) |
NVL(a, b) or COALESCE(a, b) |
Same |
coalesce(...) |
COALESCE(...) |
Same |
if(cond, a, b) |
IFF(cond, a, b) |
|
unix_timestamp() |
DATE_PART(epoch_second, CURRENT_TIMESTAMP()) |
|
from_unixtime(ts) |
TO_TIMESTAMP(ts) |
|
to_date(str, fmt) |
TO_DATE(str, fmt) |
Same |
date_format(d, fmt) |
TO_CHAR(d, fmt) |
Format codes differ |
datediff(d1, d2) |
DATEDIFF('day', d2, d1) |
Arg order differs |
regexp_replace(...) |
REGEXP_REPLACE(...) |
Same |
regexp_extract(...) |
REGEXP_SUBSTR(...) |
|
split(str, delim) |
SPLIT(str, delim) |
Same |
get_json_object(j, p) |
GET_PATH(PARSE_JSON(j), p) |
|
Dependencies
- List any upstream dependencies
- Suggest model organization in dbt project
Validation Checklist
- [] Every DDL statement has been accounted for in the dbt models
- [] SQL in models is compatible with Snowflake
- [] Hive-specific syntax converted (external tables, PARTITIONED BY, file formats, LATERAL VIEW)
- [] All business logic preserved
- [] All columns included in output
- [] Data types correctly mapped
- [] Functions translated to Snowflake equivalents
- [] Materialization strategy selected
- [] Tests added
- [] SQL logic description complete
- [] Table descriptions added
- [] Column descriptions added
- [] Dependencies correctly mapped
- [] Incremental logic (if applicable) verified
- [] Inline comments added for converted syntax
Related Skills
- $dbt-migration - For the complete migration workflow (discovery, planning, placeholder models,
testing, deployment)
- $dbt-modeling - For CTE patterns and SQL structure guidance
- $dbt-testing - For implementing comprehensive dbt tests
- $dbt-architecture - For project organization and folder structure
- $dbt-materializations - For choosing materialization strategies (view, table, incremental,
snapshots)
- $dbt-performance - For clustering keys, warehouse sizing, and query optimization
- $dbt-commands - For running dbt commands and model selection syntax
- $dbt-core - For dbt installation, configuration, and package management
- $snowflake-cli - For executing SQL and managing Snowflake objects
Supported Source Database
| Database |
Key Considerations |
| Hive / Spark / Databricks |
External tables, PARTITIONED BY, LATERAL VIEW, file formats (PARQUET, ORC), UDFs |
Translation References
Detailed syntax translation guides are available in the translation-references/ folder.
Copyright Notice: The translation reference documentation in this repository is derived from
Snowflake SnowConvert Documentation
and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.
Reference Index
- Built In Functions
- Data Types
- Ddls Create External Table
- Ddls Create View
- Ddls Readme
- Ddls Select
- Ddls Tables
- Overview (README)
- Subqueries
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: dbt-migration-hive3description: Transform Hive/Spark/Databricks DDL (views, tables, UDFs) into production-quality dbt models Use when this capability is needed.4---56# Hive/Spark/Databricks to dbt Model Conversion78## Purpose910Transform Hive/Spark/Databricks DDL (views, tables, UDFs) into production-quality dbt models11compatible with Snowflake, maintaining the same business logic and data transformation steps while12following dbt best practices.1314## When to Use This Skill1516Activate this skill when users ask about:1718- Converting Hive/Spark/Databricks views or tables to dbt models19- Migrating HiveQL UDFs to dbt20- Translating HiveQL syntax to Snowflake21- Generating schema.yml files with tests and documentation22- Handling Hive-specific syntax conversions (external tables, PARTITIONED BY, LATERAL VIEW, file23 formats)2425---2627## Task Description2829You are a database engineer working for a hospital system. You need to convert Hive/Spark/Databricks30DDL to equivalent dbt code compatible with Snowflake, maintaining the same business logic and data31transformation steps while following dbt best practices.3233## Input Requirements3435I will provide you the HiveQL DDL to convert.3637## Audience3839The code will be executed by data engineers who are learning Snowflake and dbt.4041## Output Requirements4243Generate the following:44451. One or more dbt models with complete SQL for every column462. A corresponding schema.yml file with appropriate tests and documentation473. A config block with materialization strategy484. Explanation of key changes and architectural decisions495. Inline comments highlighting any syntax that was converted5051## Conversion Guidelines5253### General Principles5455- Replace procedural logic with declarative SQL where possible56- Break down complex procedures into multiple modular dbt models57- Implement appropriate incremental processing strategies58- Maintain data quality checks through dbt tests59- Use Snowflake SQL functions rather than macros whenever possible6061### Sample Response Format6263```sql64-- dbt model: models/[domain]/[target_schema_name]/model_name.sql65{{ config(materialized='view') }}6667/* Original Object: [database].[object_name]68 Source Platform: Hive/Spark/Databricks69 Purpose: [brief description]70 Conversion Notes: [key changes]71 Description: [SQL logic description] */7273WITH source_data AS (74 SELECT75 -- Hive BIGINT/INT converted to INTEGER76 customer_id::INTEGER AS customer_id,77 -- STRING converted to VARCHAR78 customer_name::VARCHAR(100) AS customer_name,79 -- DECIMAL converted to NUMBER80 account_balance::NUMBER(18,2) AS account_balance,81 -- TIMESTAMP converted to TIMESTAMP_NTZ82 created_date::TIMESTAMP_NTZ AS created_date83 FROM {{ ref('upstream_model') }}84),8586transformed_data AS (87 SELECT88 customer_id,89 UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,90 account_balance,91 created_date,92 CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at93 FROM source_data94)9596SELECT97 customer_id,98 customer_name_upper,99 account_balance,100 created_date,101 loaded_at102FROM transformed_data103```104105```yaml106## models/[domain]/[target_schema_name]/_models.yml107version: 2108109models:110 - name: model_name111 description: "Table description; converted from Hive/Spark/Databricks [Original object name]"112 columns:113 - name: customer_id114 description: "Primary key - unique customer identifier"115 tests:116 - unique117 - not_null118 - name: customer_name_upper119 description: "Customer name in uppercase"120 - name: account_balance121 description: "Current account balance; Foreign key to OTHER_TABLE"122 tests:123 - relationships:124 to: ref('OTHER_TABLE')125 field: OTHER_TABLE_KEY126 - name: created_date127 description: "Date the customer record was created"128 - name: loaded_at129 description: "Timestamp when the record was loaded by dbt"130```131132```yaml133## dbt_project.yml (excerpt)134models:135 my_project:136 +materialized: view137 domain_name:138 +schema: target_schema_name139```140141### Specific Translation Rules142143#### dbt Specific Requirements144145- If the source is a view, use a view materialization in dbt146- Include appropriate dbt model configuration (materialization type)147- Add documentation blocks for a schema.yml148- Add descriptions for tables and columns149- Include relevant tests150- Define primary keys and relationships151- Assume that upstream objects are models152- Comprehensively provide all the columns in the output153- Break complex procedures into multiple models if needed154- Implement appropriate incremental strategies for large tables155- Use Snowflake SQL functions rather than macros whenever possible156- **Always cast columns with explicit precision/scale** using `::TYPE` syntax (e.g.,157 `column_name::VARCHAR(100)`, `amount::NUMBER(18,2)`) to ensure output matches expected data types158- **Always provide explicit column aliases** for clarity and documentation159160#### Performance Optimization161162- Suggest clustering keys if needed163- Recommend materialization strategy (view vs table)164- Identify potential performance improvements165166#### Hive/Spark to Snowflake Syntax Conversion167168- Convert LATERAL VIEW to LATERAL FLATTEN169- Replace PARTITIONED BY with clustering keys170- Convert file format specifications (PARQUET, ORC) to Snowflake staging171- Handle EXTERNAL TABLE references172- Convert Hive UDFs to Snowflake equivalents173- Replace DISTRIBUTE BY/SORT BY with clustering174- Convert ARRAY/MAP/STRUCT types to VARIANT175176#### Key Data Type Mappings177178| Hive/Spark | Snowflake | Notes |179| --------------------------- | ------------- | -------------------- |180| TINYINT/SMALLINT/INT/BIGINT | Same | |181| FLOAT/DOUBLE | FLOAT | |182| DECIMAL | DECIMAL | |183| STRING | VARCHAR | |184| CHAR/VARCHAR | Same | |185| BOOLEAN | BOOLEAN | |186| BINARY | BINARY | |187| DATE | DATE | |188| TIMESTAMP | TIMESTAMP_NTZ | |189| ARRAY<T> | ARRAY | |190| MAP<K,V> | VARIANT | Use OBJECT_CONSTRUCT |191| STRUCT | VARIANT | |192193#### Key Syntax Conversions194195```sql196-- LATERAL VIEW -> LATERAL FLATTEN197SELECT * FROM table LATERAL VIEW EXPLODE(array_col) t AS elem ->198SELECT * FROM table, LATERAL FLATTEN(input => array_col) AS f199200-- PARTITIONED BY -> Clustering201CREATE TABLE t (...) PARTITIONED BY (dt STRING) ->202CREATE TABLE t (...) CLUSTER BY (dt)203204-- External tables205CREATE EXTERNAL TABLE t LOCATION 's3://...' ->206CREATE EXTERNAL TABLE t WITH LOCATION = @stage/path207208-- collect_list/collect_set209collect_list(col) -> ARRAY_AGG(col)210collect_set(col) -> ARRAY_AGG(DISTINCT col)211212-- size() -> ARRAY_SIZE()213size(array_col) -> ARRAY_SIZE(array_col)214```215216#### Common Function Mappings217218| Hive/Spark | Snowflake | Notes |219| ----------------------- | ---------------------------------------------- | ------------------- |220| `collect_list(col)` | `ARRAY_AGG(col)` | |221| `collect_set(col)` | `ARRAY_AGG(DISTINCT col)` | |222| `size(arr)` | `ARRAY_SIZE(arr)` | |223| `explode(arr)` | `LATERAL FLATTEN(input => arr)` | |224| `posexplode(arr)` | `LATERAL FLATTEN(input => arr)` | Use `f.index` |225| `concat_ws(sep, ...)` | `CONCAT_WS(sep, ...)` | Same |226| `nvl(a, b)` | `NVL(a, b)` or `COALESCE(a, b)` | Same |227| `coalesce(...)` | `COALESCE(...)` | Same |228| `if(cond, a, b)` | `IFF(cond, a, b)` | |229| `unix_timestamp()` | `DATE_PART(epoch_second, CURRENT_TIMESTAMP())` | |230| `from_unixtime(ts)` | `TO_TIMESTAMP(ts)` | |231| `to_date(str, fmt)` | `TO_DATE(str, fmt)` | Same |232| `date_format(d, fmt)` | `TO_CHAR(d, fmt)` | Format codes differ |233| `datediff(d1, d2)` | `DATEDIFF('day', d2, d1)` | Arg order differs |234| `regexp_replace(...)` | `REGEXP_REPLACE(...)` | Same |235| `regexp_extract(...)` | `REGEXP_SUBSTR(...)` | |236| `split(str, delim)` | `SPLIT(str, delim)` | Same |237| `get_json_object(j, p)` | `GET_PATH(PARSE_JSON(j), p)` | |238239#### Dependencies240241- List any upstream dependencies242- Suggest model organization in dbt project243244---245246## Validation Checklist247248- [] Every DDL statement has been accounted for in the dbt models249- [] SQL in models is compatible with Snowflake250- [] Hive-specific syntax converted (external tables, PARTITIONED BY, file formats, LATERAL VIEW)251- [] All business logic preserved252- [] All columns included in output253- [] Data types correctly mapped254- [] Functions translated to Snowflake equivalents255- [] Materialization strategy selected256- [] Tests added257- [] SQL logic description complete258- [] Table descriptions added259- [] Column descriptions added260- [] Dependencies correctly mapped261- [] Incremental logic (if applicable) verified262- [] Inline comments added for converted syntax263264---265266## Related Skills267268- $dbt-migration - For the complete migration workflow (discovery, planning, placeholder models,269 testing, deployment)270- $dbt-modeling - For CTE patterns and SQL structure guidance271- $dbt-testing - For implementing comprehensive dbt tests272- $dbt-architecture - For project organization and folder structure273- $dbt-materializations - For choosing materialization strategies (view, table, incremental,274 snapshots)275- $dbt-performance - For clustering keys, warehouse sizing, and query optimization276- $dbt-commands - For running dbt commands and model selection syntax277- $dbt-core - For dbt installation, configuration, and package management278- $snowflake-cli - For executing SQL and managing Snowflake objects279280---281282## Supported Source Database283284| Database | Key Considerations |285| ----------------------------- | -------------------------------------------------------------------------------- |286| **Hive / Spark / Databricks** | External tables, PARTITIONED BY, LATERAL VIEW, file formats (PARQUET, ORC), UDFs |287288## Translation References289290Detailed syntax translation guides are available in the `translation-references/` folder.291292> **Copyright Notice:** The translation reference documentation in this repository is derived from293> [Snowflake SnowConvert Documentation](https://docs.snowflake.com/en/migrations/snowconvert-docs)294> and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.295296### Reference Index297298- [Built In Functions](translation-references/hive-built-in-functions.md)299- [Data Types](translation-references/hive-data-types.md)300- [Ddls Create External Table](translation-references/hive-ddls-create-external-table.md)301- [Ddls Create View](translation-references/hive-ddls-create-view.md)302- [Ddls Readme](translation-references/hive-ddls-readme.md)303- [Ddls Select](translation-references/hive-ddls-select.md)304- [Ddls Tables](translation-references/hive-ddls-tables.md)305- [Overview (README)](translation-references/hive-readme.md)306- [Subqueries](translation-references/hive-subqueries.md)307308---309> Converted and distributed by [TomeVault](https://tomevault.io/claim/sfc-gh-dflippo) — claim your Tome and manage your conversions.310<!-- tomevault:4.0:skill_md:2026-04-11 -->