Add type annotations to providers/vertica (#9936)
Co-authored-by: Johan Eklund <jeklund@zynga.com>
This commit is contained in:
Родитель
33f0cd2657
Коммит
867bc44aca
|
@ -31,11 +31,11 @@ class VerticaHook(DbApiHook):
|
|||
default_conn_name = 'vertica_default'
|
||||
supports_autocommit = True
|
||||
|
||||
def get_conn(self):
|
||||
def get_conn(self) -> connect:
|
||||
"""
|
||||
Returns verticaql connection object
|
||||
Return verticaql connection object
|
||||
"""
|
||||
conn = self.get_connection(self.vertica_conn_id) # pylint: disable=no-member
|
||||
conn = self.get_connection(self.vertica_conn_id) # type: ignore # pylint: disable=no-member
|
||||
conn_config = {
|
||||
"user": conn.login,
|
||||
"password": conn.password or '',
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from typing import Any, Dict, List, Union
|
||||
|
||||
from airflow.models import BaseOperator
|
||||
from airflow.providers.vertica.hooks.vertica import VerticaHook
|
||||
from airflow.utils.decorators import apply_defaults
|
||||
|
@ -22,7 +24,7 @@ from airflow.utils.decorators import apply_defaults
|
|||
|
||||
class VerticaOperator(BaseOperator):
|
||||
"""
|
||||
Executes sql code in a specific Vertica database
|
||||
Executes sql code in a specific Vertica database.
|
||||
|
||||
:param vertica_conn_id: reference to a specific Vertica database
|
||||
:type vertica_conn_id: str
|
||||
|
@ -37,12 +39,14 @@ class VerticaOperator(BaseOperator):
|
|||
ui_color = '#b4e0ff'
|
||||
|
||||
@apply_defaults
|
||||
def __init__(self, sql, vertica_conn_id='vertica_default', *args, **kwargs):
|
||||
def __init__(self, sql: Union[str, List[str]],
|
||||
vertica_conn_id: str = 'vertica_default',
|
||||
*args: Any, **kwargs: Any) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.vertica_conn_id = vertica_conn_id
|
||||
self.sql = sql
|
||||
|
||||
def execute(self, context):
|
||||
def execute(self, context: Dict[Any, Any]) -> None:
|
||||
self.log.info('Executing: %s', self.sql)
|
||||
hook = VerticaHook(vertica_conn_id=self.vertica_conn_id)
|
||||
hook.run(sql=self.sql)
|
||||
|
|
Загрузка…
Ссылка в новой задаче