-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: yongheng.liu <yongheng.liu@kyligence.io> GitOrigin-RevId: a2c5389a60f68482a60eb40c67b1542d827c187e
- Loading branch information
1 parent
9c3a5a2
commit abc01d4
Showing
24 changed files
with
780 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. |
136 changes: 136 additions & 0 deletions
136
airflow/providers/apache/kylin/example_dags/example_kylin_dag.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# | ||
# 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. | ||
|
||
""" | ||
This is an example DAG which uses the KylinCubeOperator. | ||
The tasks below include kylin build, refresh, merge operation. | ||
""" | ||
from airflow import DAG | ||
from airflow.operators.python import PythonOperator | ||
from airflow.providers.apache.kylin.operators.kylin_cube import KylinCubeOperator | ||
from airflow.utils.dates import days_ago | ||
|
||
args = { | ||
'owner': 'airflow', | ||
'start_date': days_ago(1), | ||
} | ||
|
||
dag = DAG( | ||
dag_id='example_kylin_operator', | ||
default_args=args, | ||
schedule_interval=None, | ||
tags=['example'] | ||
) | ||
|
||
|
||
def gen_build_time(**kwargs): | ||
""" | ||
gen build time and push to xcom | ||
:param kwargs: | ||
:return: | ||
""" | ||
ti = kwargs['ti'] | ||
ti.xcom_push(key='date_start', value='1325347200000') | ||
ti.xcom_push(key='date_end', value='1325433600000') | ||
|
||
|
||
gen_build_time_task = PythonOperator( | ||
python_callable=gen_build_time, | ||
task_id='gen_build_time', | ||
dag=dag | ||
) | ||
|
||
build_task1 = KylinCubeOperator( | ||
task_id="kylin_build_1", | ||
kylin_conn_id='kylin_default', | ||
project='learn_kylin', | ||
cube='kylin_sales_cube', | ||
command='build', | ||
start_time="{{ task_instance.xcom_pull(task_ids='gen_build_time',key='date_start') }}", | ||
end_time="{{ task_instance.xcom_pull(task_ids='gen_build_time',key='date_end') }}", | ||
is_track_job=True, | ||
dag=dag, | ||
) | ||
|
||
build_task2 = KylinCubeOperator( | ||
task_id="kylin_build_2", | ||
kylin_conn_id='kylin_default', | ||
project='learn_kylin', | ||
cube='kylin_sales_cube', | ||
command='build', | ||
start_time='1325433600000', | ||
end_time='1325520000000', | ||
is_track_job=True, | ||
dag=dag, | ||
) | ||
|
||
refresh_task1 = KylinCubeOperator( | ||
task_id="kylin_refresh_1", | ||
kylin_conn_id='kylin_default', | ||
project='learn_kylin', | ||
cube='kylin_sales_cube', | ||
command='refresh', | ||
start_time='1325347200000', | ||
end_time='1325433600000', | ||
is_track_job=True, | ||
dag=dag, | ||
) | ||
|
||
merge_task = KylinCubeOperator( | ||
task_id="kylin_merge", | ||
kylin_conn_id='kylin_default', | ||
project='learn_kylin', | ||
cube='kylin_sales_cube', | ||
command='merge', | ||
start_time='1325347200000', | ||
end_time='1325520000000', | ||
is_track_job=True, | ||
dag=dag, | ||
) | ||
|
||
disable_task = KylinCubeOperator( | ||
task_id="kylin_disable", | ||
kylin_conn_id='kylin_default', | ||
project='learn_kylin', | ||
cube='kylin_sales_cube', | ||
command='disable', | ||
dag=dag, | ||
) | ||
|
||
purge_task = KylinCubeOperator( | ||
task_id="kylin_purge", | ||
kylin_conn_id='kylin_default', | ||
project='learn_kylin', | ||
cube='kylin_sales_cube', | ||
command='purge', | ||
dag=dag, | ||
) | ||
|
||
build_task3 = KylinCubeOperator( | ||
task_id="kylin_build_3", | ||
kylin_conn_id='kylin_default', | ||
project='learn_kylin', | ||
cube='kylin_sales_cube', | ||
command='build', | ||
start_time='1325433600000', | ||
end_time='1325520000000', | ||
dag=dag, | ||
) | ||
|
||
gen_build_time_task >> build_task1 >> build_task2 >> refresh_task1 >> merge_task | ||
merge_task >> disable_task >> purge_task >> build_task3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# 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 typing import Optional | ||
|
||
from kylinpy import exceptions, kylinpy | ||
|
||
from airflow.exceptions import AirflowException | ||
from airflow.hooks.base_hook import BaseHook | ||
|
||
|
||
class KylinHook(BaseHook): | ||
""" | ||
:param kylin_conn_id: The connection id as configured in Airflow administration. | ||
:type kylin_conn_id: str | ||
:param project: porject name | ||
:type project: Optional[str] | ||
:param dsn: dsn | ||
:type dsn: Optional[str] | ||
""" | ||
def __init__(self, | ||
kylin_conn_id: Optional[str] = 'kylin_default', | ||
project: Optional[str] = None, | ||
dsn: Optional[str] = None | ||
): | ||
super().__init__() | ||
self.kylin_conn_id = kylin_conn_id | ||
self.project = project | ||
self.dsn = dsn | ||
|
||
def get_conn(self): | ||
conn = self.get_connection(self.kylin_conn_id) | ||
if self.dsn: | ||
return kylinpy.create_kylin(self.dsn) | ||
else: | ||
self.project = self.project if self.project else conn.schema | ||
return kylinpy.Kylin(conn.host, username=conn.login, | ||
password=conn.password, port=conn.port, | ||
project=self.project, **conn.extra_dejson) | ||
|
||
def cube_run(self, datasource_name, op, **op_args): | ||
""" | ||
run CubeSource command whitch in CubeSource.support_invoke_command | ||
:param datasource_name: | ||
:param op: command | ||
:param op_args: command args | ||
:return: response | ||
""" | ||
cube_source = self.get_conn().get_datasource(datasource_name) | ||
try: | ||
response = cube_source.invoke_command(op, **op_args) | ||
return response | ||
except exceptions.KylinError as err: | ||
raise AirflowException("Cube operation {} error , Message: {}".format(op, err)) | ||
|
||
def get_job_status(self, job_id): | ||
""" | ||
get job status | ||
:param job_id: kylin job id | ||
:return: job status | ||
""" | ||
return self.get_conn().get_job(job_id).status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. |
Oops, something went wrong.