dungdm93 commented on a change in pull request #14639: URL: https://github.com/apache/airflow/pull/14639#discussion_r591273489
########## File path: airflow/providers/trino/hooks/trino.py ########## @@ -0,0 +1,184 @@ +# +# 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 os +from typing import Any, Dict, Iterable, Optional + +import trino +from trino.transaction import IsolationLevel + +from airflow import AirflowException +from airflow.configuration import conf +from airflow.hooks.dbapi import DbApiHook +from airflow.models import Connection + + +def _boolify(value): + if isinstance(value, bool): + return value + if isinstance(value, str): + if value.lower() == 'false': + return False + elif value.lower() == 'true': + return True + return value + + +class TrinoHook(DbApiHook): + """ + Interact with Trino. + + >>> th = TrinoHook() + >>> sql = "SELECT count(1) AS num FROM airflow.static_babynames" + >>> th.get_records(sql) + [[340698]] + """ + + conn_name_attr = 'trino_conn_id' + default_conn_name = 'trino_default' + conn_type = 'trino' + hook_name = 'Trino' + + @staticmethod + def get_ui_field_behaviour() -> Dict[str, Any]: + """Returns custom field behaviour""" + return { + "hidden_fields": [], + "relabeling": { + 'schema': 'Catalog', + 'login': 'Username', + }, + } + + def get_conn(self) -> Connection: + """Returns a connection object""" + db = self.get_connection(getattr(self, self.conn_name_attr)) Review comment: I see that method return single Connection: https://github.com/apache/airflow/blob/923bde2b917099135adfe470a5453f663131fd5f/airflow/hooks/base.py#L55-L76 If it returns more than once, we should update this method signature as well, right? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
