josh-fell commented on code in PR #23704: URL: https://github.com/apache/airflow/pull/23704#discussion_r879549311
########## airflow/providers/tabular/example_dags/example_tabular.py: ########## @@ -0,0 +1,46 @@ +# 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 datetime import datetime, timedelta + +from airflow import DAG +from airflow.operators.bash import BashOperator +from airflow.providers.tabular.hooks.tabular import TabularHook + +default_args = { + "owner": "airflow", + "depends_on_past": False, + "email": ["[email protected]"], + "email_on_failure": False, + "email_on_retry": False, +} + +bash_command = f""" +echo "Our token: {TabularHook().get_token_macro()}" +echo "Also as an environment variable:" +env | grep TOKEN +""" + +with DAG( + "tabular", default_args=default_args, start_date=datetime(2021, 1, 1), schedule_interval=timedelta(1) Review Comment: Can you add `catchup=False`? This was another example-DAG cleanup effort (yeah, there were several) so beginner users who might use the example DAG won't have headaches with lots of DAG Runs being launched if the `start_date` doesn't change and haven't read up on `catchup`. ########## airflow/providers/tabular/hooks/tabular.py: ########## @@ -0,0 +1,104 @@ +# 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 Any, Dict, Tuple + +import requests +from requests import HTTPError + +from airflow.hooks.base import BaseHook + +DEFAULT_TABULAR_URL = "https://api.tabulardata.io/ws/v1" + +TOKENS_ENDPOINT = "oauth/tokens" + + +class TabularHook(BaseHook): + """ + This hook acts as a base hook for tabular services. It offers the ability to generate temporary, + short-lived session tokens to use within Airflow submitted jobs. + + :param tabular_conn_id: The :ref:`Tabular connection id<howto/connection:tabular>` + which refers to the information to connect to the Tabular OAuth service. + """ + + conn_name_attr = 'tabular_conn_id' + default_conn_name = "tabular_default" + conn_type = "tabular" + hook_name = "Tabular" + + @staticmethod + def get_connection_form_widgets() -> Dict[str, Any]: + """Returns connection widgets to add to connection form""" + from flask_appbuilder.fieldwidgets import BS3TextFieldWidget + from flask_babel import lazy_gettext + from wtforms import StringField + + return { + "extra__tabular__baseUrl": StringField( + lazy_gettext("Tabular Base URL"), widget=BS3TextFieldWidget() + ), + } Review Comment: Rather than creating a new extra field, WDYT about relabeling `host` instead? ########## airflow/providers/tabular/hooks/tabular.py: ########## @@ -0,0 +1,104 @@ +# 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 Any, Dict, Tuple + +import requests +from requests import HTTPError + +from airflow.hooks.base import BaseHook + +DEFAULT_TABULAR_URL = "https://api.tabulardata.io/ws/v1" + +TOKENS_ENDPOINT = "oauth/tokens" + + +class TabularHook(BaseHook): + """ + This hook acts as a base hook for tabular services. It offers the ability to generate temporary, + short-lived session tokens to use within Airflow submitted jobs. + + :param tabular_conn_id: The :ref:`Tabular connection id<howto/connection:tabular>` + which refers to the information to connect to the Tabular OAuth service. + """ + + conn_name_attr = 'tabular_conn_id' + default_conn_name = "tabular_default" + conn_type = "tabular" + hook_name = "Tabular" + + @staticmethod + def get_connection_form_widgets() -> Dict[str, Any]: + """Returns connection widgets to add to connection form""" + from flask_appbuilder.fieldwidgets import BS3TextFieldWidget + from flask_babel import lazy_gettext + from wtforms import StringField + + return { + "extra__tabular__baseUrl": StringField( + lazy_gettext("Tabular Base URL"), widget=BS3TextFieldWidget() + ), + } + + @staticmethod + def get_ui_field_behaviour() -> Dict[str, Any]: + """Returns custom field behaviour""" + return { + "hidden_fields": ["schema", "port", "host"], + "relabeling": { + "login": "Tabular Client ID", + "password": "Tabular Client Secret", Review Comment: Not a strong opinion, but maybe drop the "Tabular" prefix given that the connection type will be set to "Tabular"? ########## airflow/providers/tabular/example_dags/example_tabular.py: ########## @@ -0,0 +1,46 @@ +# 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 datetime import datetime, timedelta + +from airflow import DAG +from airflow.operators.bash import BashOperator +from airflow.providers.tabular.hooks.tabular import TabularHook + +default_args = { + "owner": "airflow", + "depends_on_past": False, + "email": ["[email protected]"], + "email_on_failure": False, + "email_on_retry": False, +} Review Comment: A while ago there was some cleanup done of example DAGs' `default_args` use (e.g. #16872 and others) to remove some less relevant args and move the `default_args` declaration directly to the `DAG()` object. It would be nice to keep the consistency. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
