You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/11/01 22:27:07 UTC

[GitHub] [airflow] subkanthi opened a new pull request #19356: Add influxdb operator

subkanthi opened a new pull request #19356:
URL: https://github.com/apache/airflow/pull/19356


   Added influxdb operator to enable running queries on influxdb
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-981747707


   `template_fields` should be a list, `["sql"]`, not a string.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r747069636



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.parameters = parameters
+        self.hook = None
+
+    def get_hook(self):
+        """Function to retrieve the InfluxDB Hook."""
+        return InfluxDBHook(conn_id=self.influxdb_conn_id)

Review comment:
       Added to execute.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-967247205


   Fixed all doc errors.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r747077683



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       This is going to need work in updating the hook too, if its OK can I please do it in a separate PR?

##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},
+    tags=['example'],
+    catchup=False,
+)
+
+# [START howto_operator_influxdb]
+
+query_influxdb_task = InfluxDBOperator(
+    task_id='query_influxdb', sql='from(bucket:"test-influx") |> range(start: -10m)', dag=dag
+)
+
+# [END howto_operator_influxdb]
+
+query_influxdb_task

Review comment:
       Removed.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] josh-fell commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
josh-fell commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r740674861



##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},

Review comment:
       Since there is only one task in this pipeline, you should just set the `influxdb_conn_id` arg directly in the operator call rather than in `default_args`.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`

Review comment:
       The operator doc that is referenced in the docstring is missing.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       The docstring is missing information on the `parameters` param. 
   
   Although it looks like the `InfluxDBHook.query()` method doesn't take a `parameters` argument so maybe this parameter is not needed.

##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},
+    tags=['example'],
+    catchup=False,
+)
+
+# [START howto_operator_influxdb]
+
+query_influxdb_task = InfluxDBOperator(
+    task_id='query_influxdb', sql='from(bucket:"test-influx") |> range(start: -10m)', dag=dag
+)
+
+# [END howto_operator_influxdb]
+
+query_influxdb_task

Review comment:
       This line is not needed. The task node will be created when instantiating the operator above.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       WDYT about adding `template_fields`, `template_fields_renderers`, and `template_ext` for the operator? At the very least adding some templating functionality for `sql` would be useful.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.parameters = parameters
+        self.hook = None
+
+    def get_hook(self):
+        """Function to retrieve the InfluxDB Hook."""
+        return InfluxDBHook(conn_id=self.influxdb_conn_id)

Review comment:
       This method seems unnecessary. You could instantiate the hook directly in the `execute()` method and the functionality would not change.

##########
File path: tests/providers/influxdb/operators/test_influxdb.py
##########
@@ -0,0 +1,40 @@
+# 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.
+
+import unittest
+from unittest import mock
+
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2015, 1, 1)
+DEFAULT_DATE_ISO = DEFAULT_DATE.isoformat()
+DEFAULT_DATE_DS = DEFAULT_DATE_ISO[:10]
+TEST_DAG_ID = 'unit_test_dag'

Review comment:
       Are these variables needed for the unit test?




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r757815355



##########
File path: docs/apache-airflow-providers-influxdb/operators/index.rst
##########
@@ -0,0 +1,26 @@
+ .. 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.
+
+
+
+.. _howto/operator:InfluxDBOperator:
+
+InfluxDBOperator
+=============

Review comment:
       Not sure why it shows up in the diff, I had to fix it to build the docs.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r747810764



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`

Review comment:
       Added operator. Thanks




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-981816035


   Right. I was waiting for that one to prepare new release of providers :)


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] josh-fell commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
josh-fell commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r747559493



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       No problem.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r748569737



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,54 @@
+#
+# 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 Dict
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.hook = None

Review comment:
       pycharm grumbles when you create an attribute that isn't defined in init
   
   but if you're suggesting "don't bother creating a hook attr at all", i second the motion




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-981745534


   > Also please fix the templated field issue mentioned above.
   For some reason, I was getting this error, when I set the template_fields='sql', will try to troubleshoot.
   
   `[2021-11-29, 15:29:12 UTC] {standard_task_runner.py:91} ERROR - Failed to execute job 11 for task query_influxdb
   Traceback (most recent call last):
     File "/opt/airflow/airflow/task/task_runner/standard_task_runner.py", line 85, in _start_by_fork
       args.func(args, dag=self.dag)
     File "/opt/airflow/airflow/cli/cli_parser.py", line 48, in command
       return func(*args, **kwargs)
     File "/opt/airflow/airflow/utils/cli.py", line 92, in wrapper
       return f(*args, **kwargs)
     File "/opt/airflow/airflow/cli/commands/task_command.py", line 293, in task_run
       _run_task_by_selected_method(args, dag, ti)
     File "/opt/airflow/airflow/cli/commands/task_command.py", line 107, in _run_task_by_selected_method
       _run_raw_task(args, ti)
     File "/opt/airflow/airflow/cli/commands/task_command.py", line 184, in _run_raw_task
       error_file=args.error_file,
     File "/opt/airflow/airflow/utils/session.py", line 70, in wrapper
       return func(*args, session=session, **kwargs)
     File "/opt/airflow/airflow/models/taskinstance.py", line 1330, in _run_raw_task
       self._execute_task_with_callbacks(context)
     File "/opt/airflow/airflow/models/taskinstance.py", line 1419, in _execute_task_with_callbacks
       self.render_templates(context=context)
     File "/opt/airflow/airflow/models/taskinstance.py", line 2111, in render_templates
       self.task.render_template_fields(context)
     File "/opt/airflow/airflow/models/baseoperator.py", line 1051, in render_template_fields
       self._do_render_template_fields(self, self.template_fields, context, jinja_env, set())
     File "/opt/airflow/airflow/models/baseoperator.py", line 1062, in _do_render_template_fields
       content = getattr(parent, attr_name)
   AttributeError: 'InfluxDBOperator' object has no attribute 's'`


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r747069463



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       Removed.

##########
File path: tests/providers/influxdb/operators/test_influxdb.py
##########
@@ -0,0 +1,40 @@
+# 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.
+
+import unittest
+from unittest import mock
+
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2015, 1, 1)
+DEFAULT_DATE_ISO = DEFAULT_DATE.isoformat()
+DEFAULT_DATE_DS = DEFAULT_DATE_ISO[:10]
+TEST_DAG_ID = 'unit_test_dag'

Review comment:
       Removed.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r757919292



##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_query.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    tags=['example'],
+    catchup=False,
+)
+
+# [START howto_operator_influxdb]

Review comment:
       Thanks, added link just like the airbyte example.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] josh-fell commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
josh-fell commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r740674861



##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},

Review comment:
       Since there is only one task in this pipeline, you should just set the `influxdb_conn_id` arg directly in the operator call rather than in `default_args`.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`

Review comment:
       The operator doc that is referenced in the docstring is missing.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       The docstring is missing information on the `parameters` param. 
   
   Although it looks like the `InfluxDBHook.query()` method doesn't take a `parameters` argument so maybe this parameter is not needed.

##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},
+    tags=['example'],
+    catchup=False,
+)
+
+# [START howto_operator_influxdb]
+
+query_influxdb_task = InfluxDBOperator(
+    task_id='query_influxdb', sql='from(bucket:"test-influx") |> range(start: -10m)', dag=dag
+)
+
+# [END howto_operator_influxdb]
+
+query_influxdb_task

Review comment:
       This line is not needed. The task node will be created when instantiating the operator above.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       WDYT about adding `template_fields`, `template_fields_renderers`, and `template_ext` for the operator? At the very least adding some templating functionality for `sql` would be useful.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.parameters = parameters
+        self.hook = None
+
+    def get_hook(self):
+        """Function to retrieve the InfluxDB Hook."""
+        return InfluxDBHook(conn_id=self.influxdb_conn_id)

Review comment:
       This method seems unnecessary. You could instantiate the hook directly in the `execute()` method and the functionality would not change.

##########
File path: tests/providers/influxdb/operators/test_influxdb.py
##########
@@ -0,0 +1,40 @@
+# 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.
+
+import unittest
+from unittest import mock
+
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2015, 1, 1)
+DEFAULT_DATE_ISO = DEFAULT_DATE.isoformat()
+DEFAULT_DATE_DS = DEFAULT_DATE_ISO[:10]
+TEST_DAG_ID = 'unit_test_dag'

Review comment:
       Are these variables needed for the unit test?




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] josh-fell commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
josh-fell commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r748570846



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,54 @@
+#
+# 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 Dict
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.hook = None

Review comment:
       Yes, I could have been clearer about that. The `self.hook` attr is not necessary here. Thanks for keeping me honest.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi edited a comment on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi edited a comment on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-981745534


   > Also please fix the templated field issue mentioned above.
   
   For some reason, I was getting this error, when I set the template_fields='sql', will try to troubleshoot.
   
   ```
   [2021-11-29, 15:29:12 UTC] {standard_task_runner.py:91} ERROR - Failed to execute job 11 for task query_influxdb
   Traceback (most recent call last):
     File "/opt/airflow/airflow/task/task_runner/standard_task_runner.py", line 85, in _start_by_fork
       args.func(args, dag=self.dag)
     File "/opt/airflow/airflow/cli/cli_parser.py", line 48, in command
       return func(*args, **kwargs)
     File "/opt/airflow/airflow/utils/cli.py", line 92, in wrapper
       return f(*args, **kwargs)
     File "/opt/airflow/airflow/cli/commands/task_command.py", line 293, in task_run
       _run_task_by_selected_method(args, dag, ti)
     File "/opt/airflow/airflow/cli/commands/task_command.py", line 107, in _run_task_by_selected_method
       _run_raw_task(args, ti)
     File "/opt/airflow/airflow/cli/commands/task_command.py", line 184, in _run_raw_task
       error_file=args.error_file,
     File "/opt/airflow/airflow/utils/session.py", line 70, in wrapper
       return func(*args, session=session, **kwargs)
     File "/opt/airflow/airflow/models/taskinstance.py", line 1330, in _run_raw_task
       self._execute_task_with_callbacks(context)
     File "/opt/airflow/airflow/models/taskinstance.py", line 1419, in _execute_task_with_callbacks
       self.render_templates(context=context)
     File "/opt/airflow/airflow/models/taskinstance.py", line 2111, in render_templates
       self.task.render_template_fields(context)
     File "/opt/airflow/airflow/models/baseoperator.py", line 1051, in render_template_fields
       self._do_render_template_fields(self, self.template_fields, context, jinja_env, set())
     File "/opt/airflow/airflow/models/baseoperator.py", line 1062, in _do_render_template_fields
       content = getattr(parent, attr_name)
   AttributeError: 'InfluxDBOperator' object has no attribute 's'
   ```


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi edited a comment on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi edited a comment on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-981751286


   > `template_fields` should be a list, `["sql"]`, not a string.
   
   Yeah, thanks , I thought I saw a string definition somewhere.
           for attr_name in template_fields:
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r758545464



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,54 @@
+#
+# 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 Dict
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,

Review comment:
       Added thanks

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       Added template_fields.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r749034047



##########
File path: docs/apache-airflow-providers-influxdb/operators/index.rst
##########
@@ -0,0 +1,26 @@
+ .. 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.
+
+
+
+.. _howto/operator:InfluxDBOperator:
+
+InfluxDBOperator
+=============

Review comment:
       ```suggestion
   InfluxDBOperator
   ================
   ```
   
   RestructuredText requires the underline to be at least as long as the text.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r747069367



##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},

Review comment:
       Removed.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r757815645



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,54 @@
+#
+# 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 Dict
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.hook = None

Review comment:
       Removed, thanks.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
subkanthi commented on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-981751286


   > `template_fields` should be a list, `["sql"]`, not a string.
   
   Yeah, thanks figured it out, I thought I saw a string definition somewhere.
           for attr_name in template_fields:
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk merged pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #19356:
URL: https://github.com/apache/airflow/pull/19356


   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] josh-fell commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
josh-fell commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r740674861



##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},

Review comment:
       Since there is only one task in this pipeline, you should just set the `influxdb_conn_id` arg directly in the operator call rather than in `default_args`.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`

Review comment:
       The operator doc that is referenced in the docstring is missing.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       The docstring is missing information on the `parameters` param. 
   
   Although it looks like the `InfluxDBHook.query()` method doesn't take a `parameters` argument so maybe this parameter is not needed.

##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_operator.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    default_args={'influxdb_conn_id': 'influxdb_conn_id'},
+    tags=['example'],
+    catchup=False,
+)
+
+# [START howto_operator_influxdb]
+
+query_influxdb_task = InfluxDBOperator(
+    task_id='query_influxdb', sql='from(bucket:"test-influx") |> range(start: -10m)', dag=dag
+)
+
+# [END howto_operator_influxdb]
+
+query_influxdb_task

Review comment:
       This line is not needed. The task node will be created when instantiating the operator above.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,

Review comment:
       WDYT about adding `template_fields`, `template_fields_renderers`, and `template_ext` for the operator? At the very least adding some templating functionality for `sql` would be useful.

##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,60 @@
+#
+# 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 Dict, Iterable, Mapping, Optional, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        parameters: Optional[Union[Mapping, Iterable]] = None,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.parameters = parameters
+        self.hook = None
+
+    def get_hook(self):
+        """Function to retrieve the InfluxDB Hook."""
+        return InfluxDBHook(conn_id=self.influxdb_conn_id)

Review comment:
       This method seems unnecessary. You could instantiate the hook directly in the `execute()` method and the functionality would not change.

##########
File path: tests/providers/influxdb/operators/test_influxdb.py
##########
@@ -0,0 +1,40 @@
+# 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.
+
+import unittest
+from unittest import mock
+
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2015, 1, 1)
+DEFAULT_DATE_ISO = DEFAULT_DATE.isoformat()
+DEFAULT_DATE_DS = DEFAULT_DATE_ISO[:10]
+TEST_DAG_ID = 'unit_test_dag'

Review comment:
       Are these variables needed for the unit test?




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r758443689



##########
File path: tests/providers/influxdb/operators/test_influxdb.py
##########
@@ -0,0 +1,34 @@
+# 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.
+
+import unittest
+from unittest import mock
+
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+
+class TestInfluxDBOperator(unittest.TestCase):
+    @mock.patch('airflow.providers.influxdb.operators.influxdb.InfluxDBHook')
+    def test_influxdb_operator_test(self, mock_hook):
+
+        sql = """
+            from(bucket:"test") |> range(start: -10m)
+            """

Review comment:
       ```suggestion
           sql = """from(bucket:"test") |> range(start: -10m)"""
   ```




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#issuecomment-981764193


   The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk closed pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
potiuk closed pull request #19356:
URL: https://github.com/apache/airflow/pull/19356


   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r748570356



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,54 @@
+#
+# 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 Dict
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,

Review comment:
       `sql` should probably be added as a templated field




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] josh-fell commented on a change in pull request #19356: Add influxdb operator

Posted by GitBox <gi...@apache.org>.
josh-fell commented on a change in pull request #19356:
URL: https://github.com/apache/airflow/pull/19356#discussion_r748548197



##########
File path: airflow/providers/influxdb/operators/influxdb.py
##########
@@ -0,0 +1,54 @@
+#
+# 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 Dict
+
+from airflow.models import BaseOperator
+from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook
+
+
+class InfluxDBOperator(BaseOperator):
+    """
+    Executes sql code in a specific InfluxDB database
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:InfluxDBOperator`
+
+    :param sql: the sql code to be executed. Can receive a str representing a
+        sql statement
+    :type sql: str
+    :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`.
+    :type influxdb_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        sql: str,
+        influxdb_conn_id: str = 'influxdb_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.influxdb_conn_id = influxdb_conn_id
+        self.sql = sql
+        self.hook = None

Review comment:
       ```suggestion
   ```
   This can be removed since the hook object is being instantiated only in the `execute()` method.

##########
File path: airflow/providers/influxdb/example_dags/example_influxdb_query.py
##########
@@ -0,0 +1,39 @@
+# 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
+
+from airflow.models.dag import DAG
+from airflow.providers.influxdb.operators.influxdb import InfluxDBOperator
+
+dag = DAG(
+    'example_influxdb_operator',
+    start_date=datetime(2021, 1, 1),
+    tags=['example'],
+    catchup=False,
+)
+
+# [START howto_operator_influxdb]

Review comment:
       These `# [START/END howto_...]` tags are for including code snippets in docs using the `.. exampleinclude::` directive. This reference should be in the operator doc too to provide some more context for the `InfluxDBOperator`.
   
   Here is an example of how these tags are typically used in operator docs: https://github.com/apache/airflow/blob/main/docs/apache-airflow-providers-airbyte/operators/airbyte.rst




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org