subkanthi commented on a change in pull request #17068: URL: https://github.com/apache/airflow/pull/17068#discussion_r685554071
########## File path: airflow/providers/influxdb/example_dags/example_influxdb.py ########## @@ -0,0 +1,57 @@ +# 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 airflow.models.dag import DAG +from airflow.operators.python import PythonOperator +from airflow.providers.influxdb.hooks.influxdb import InfluxDBHook +from airflow.utils.dates import days_ago + + +def test_influxdb_hook(): Review comment: Fixed. ########## File path: airflow/providers/influxdb/hooks/influxdb.py ########## @@ -0,0 +1,166 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""This module allows to connect to a InfluxDB database.""" + +from typing import List + +import pandas as pd +from influxdb_client import InfluxDBClient +from influxdb_client.client.flux_table import FluxTable +from influxdb_client.client.write.point import Point +from influxdb_client.client.write_api import SYNCHRONOUS + +from airflow.hooks.base import BaseHook +from airflow.models import Connection + + +class InfluxDBHook(BaseHook): + """ + Interact with InfluxDB. + + Performs a connection to InfluxDB and retrieves client. + + :param influxdb_conn_id: Reference to :ref:`Influxdb connection id <howto/connection:influxdb>`. + :type influxdb_conn_id: str + """ + + conn_name_attr = 'influxdb_conn_id' + default_conn_name = 'influxdb_default' + conn_type = 'influxdb' + hook_name = 'Influxdb' + + def __init__(self, conn_id: str = default_conn_name, *args, **kwargs) -> None: + super().__init__(*args, **kwargs) + self.influxdb_conn_id = conn_id + self.connection = kwargs.pop("connection", None) + self.client = None + self.extras = None + self.uri = None + self.org_name = None + + def get_client(self, uri, token, org_name): + return InfluxDBClient(url=uri, token=token, org=org_name) + + def get_uri(self, conn: Connection): + """ + Function to add additional parameters to the URI + based on SSL or other InfluxDB host requirements + + """ + return '{scheme}://{host}:{port}'.format( + scheme='https' if conn.schema is None else f'{conn.schema}', Review comment: Removed f for conn.schema -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
