Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dbt-doris adaptor example #46778

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions extension/dbt-doris/example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

FROM python:3.10.12-bookworm
LABEL authors="davidchen"

USER root

# Define build arguments
ARG DBT_DORIS_HOST
ARG DBT_DORIS_USERNAME
ARG DBT_DORIS_PASSWORD

# set the environment variable of host passwd and username from build args
ENV DBT_DORIS_HOST ${DBT_DORIS_HOST}
ENV DBT_DORIS_USERNAME ${DBT_DORIS_USERNAME}
ENV DBT_DORIS_PASSWORD ${DBT_DORIS_PASSWORD}


# change debian source # if you are in china you can use tsinghua source
RUN sed -i '[email protected]@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources

# install git
RUN apt update && apt install git -y

# install dbt, if you are in china you can use aliyun source
RUN pip install --upgrade pip --index https://mirrors.aliyun.com/pypi/simple/
RUN pip install dbt-doris==0.3.4 --index https://mirrors.aliyun.com/pypi/simple/
RUN pip install dbt-core==1.5.11 --index https://mirrors.aliyun.com/pypi/simple/
# otherwise you can use the default source
#RUN pip install --upgrade pip
#RUN pip install dbt-doris==0.3.4
#RUN pip install dbt-core==1.5.11


# copy dbt project
COPY /dbt /dbt
WORKDIR /dbt

# run dbt debug
RUN dbt debug

# run dbt deps
RUN dbt deps

CMD ["echo", "build success"]

# dbt seeds
RUN dbt seed

# run dbt
CMD ["dbt", "run"]

#CMD ["dbt", "test"]

#ENTRYPOINT ["tail", "-f", "/dev/null"]

736 changes: 736 additions & 0 deletions extension/dbt-doris/example/LICENSE.txt

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions extension/dbt-doris/example/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Here is a basic `ReadMe.md` template for your project:

# Project Name

## Overview

Provide a brief description of your project, its purpose, and its main features.

## Prerequisites

List the software and tools required to run the project:


- Docker

- Python 3.10
- dbt-core==1.5.11
- dbt-doris==0.3.4

## Installation

### Using Docker

1. Clone the repository:
```sh
git clone <repository-url>
cd <repository-directory>
```

2. Build the Docker image:
```sh
docker build -t project-name . --build-arg DBT_DORIS_HOST=<host> --build-arg DBT_DORIS_USERNAME=<username> --build-arg DBT_DORIS_PASSWORD=<password>
```

3. Run the Docker container:
```sh
docker run -e DBT_DORIS_HOST=<host> -e DBT_DORIS_USERNAME=<username> -e DBT_DORIS_PASSWORD=<password> project-name
```

### Without Docker

1. Clone the repository:
```sh
git clone <repository-url>
cd <repository-directory>
```

2. Install the required Python packages:
```sh
pip install -r requirements.txt
```

3. Set environment variables:
```sh
export DBT_DORIS_HOST=<host>
export DBT_DORIS_USERNAME=<username>
export DBT_DORIS_PASSWORD=<password>
```

4. Run dbt commands:
```sh
dbt debug
dbt deps
dbt seed
dbt run
```

## Usage

Provide instructions on how to use the project, including examples and common use cases.

## Contributing

Explain how others can contribute to the project. Include guidelines for submitting issues and pull requests.

## License

Specify the license under which the project is distributed.

## Contact

Provide contact information for the project maintainers.

Feel free to customize this template to better fit your project's needs.
4 changes: 4 additions & 0 deletions extension/dbt-doris/example/dbt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this is a example for dbt-doris adapter

docker file is the execution env prepare for dbt-doris

42 changes: 42 additions & 0 deletions extension/dbt-doris/example/dbt/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: "dbt_testing_example"
version: "1.0.0"
config-version: 2

profile: "dbt_testing_example"

#require-dbt-version: ">=1.7.0"

model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target"
clean-targets:
- "target"
- "dbt_packages"

models:
dbt_testing_example:
+materialized: table
# elementary:
# +schema: "elementary"
10 changes: 10 additions & 0 deletions extension/dbt-doris/example/dbt/macros/calculate_metics_bmi.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% macro calculate_metric_bmi(weight, height, height_unit, weight_unit) %}
case
when {{ height_unit }} = 'cm' and {{ weight_unit }} = 'kg' then
{{ weight }} / ({{ height }} / 100.0) ^ 2
when {{ height_unit }} = 'inch' and {{ weight_unit }} = 'pound' then
{{ weight }} / ({{ height }} * 0.0254) ^ 2
else
null
end
{% endmacro %}
7 changes: 7 additions & 0 deletions extension/dbt-doris/example/dbt/macros/testing_macros.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro ref(model_name) %}
{{ return(dbt_unit_testing.ref(model_name)) }}
{% endmacro %}

{% macro source(source, model_name) %}
{{ return(dbt_unit_testing.source(source, model_name)) }}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{ config(
post_hook='drop table if exists {{ this.schema }}.{{ this.name }}__dbt_tmp' ,

properties = {
"dynamic_partition.time_unit":"DAY",
"dynamic_partition.end":"8",
"dynamic_partition.prefix":"p",
"dynamic_partition.buckets":"4",
"dynamic_partition.create_history_partition":"true",
"dynamic_partition.history_partition_num":"20"
}
)

}}

with

source_height as (

select * from dbt_testing_example.raw_height

),

source_weight as (

select * from dbt_testing_example.raw_weight

),

bmi as (

select
h.user_id,
h.height,
w.weight,
h.date,
h.height_unit,
w.weight_unit,
{{ calculate_metric_bmi('h.height', 'w.weight', 'h.height_unit', 'w.weight_unit') }} as bmi

from source_height h
full outer join source_weight w
on h.user_id = w.user_id
where h.date = w.date

)

select * from bmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

version: 2

models:
- name: stg_sample_bmi
description: "Model for stg_gym_app_bmi table"
config:
enabled: true
engine: "OLAP"
# Unique key definition
keys:
- date
- user_id
# Partition info
partition_by:
- date
partition_type: "range"
# Sort info
sort: 1
sort_type: "ASC"
sort_by:
- date
- user_id
# Distribution info
distribution: "HASH"
distribution_key: "date"
# Cluster info
cluster_by:
- date
- user_id
# Materialized view info
materialized: "table"
# Refresh info
refresh: "FULL"
# column_types
column_types:
date: date
user_id: int
weight: double precision
height: double precision
bmi: double precision
weight_unit: string
height_unit: string

columns:
- name: date
description: "日期"

- name: user_id
description: "用户ID"
tests:
- dbt_expectations.expect_column_values_to_be_between:
min_value: 0
max_value: 1000000
- name: weight
description: "体重"
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: "double precision"
- name: height
description: "身高"
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: "double precision"
- name: bmi
description: "BMI"
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: "double precision"
- name: weight_unit
description: "体重单位"
tests:
- dbt_expectations.expect_column_values_to_be_in_set:
value_set: [ "kg", "pound" ]
- name: height_unit
description: "身高单位"
tests:
- dbt_expectations.expect_column_values_to_be_in_set:
value_set: [ "cm", "inch" ]
29 changes: 29 additions & 0 deletions extension/dbt-doris/example/dbt/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

packages:
- package: dbt-labs/dbt_utils
version: 1.1.1

- package: calogica/dbt_expectations
version: 0.10.3

- git: "https://github.com/EqualExperts/dbt-unit-testing"
revision: v0.4.12

# - package: elementary-data/elementary
# version: 0.14.1
Loading
Loading