Lee-W commented on code in PR #69612:
URL: https://github.com/apache/airflow/pull/69612#discussion_r3578009445
##########
providers/apache/hive/src/airflow/providers/apache/hive/sensors/metastore_partition.py:
##########
@@ -58,28 +70,16 @@ def __init__(
self.partition_name = partition_name
self.table = table
self.schema = schema
- self.first_poke = True
- self.conn_id = mysql_conn_id
- # TODO(aoen): We shouldn't be using SqlSensor here but
MetastorePartitionSensor.
- # The problem is the way apply_defaults works isn't compatible with
inheritance.
- # The inheritance model needs to be reworked in order to support
overriding args/
- # kwargs with arguments here, then 'conn_id' and 'sql' can be passed
into the
- # constructor below and apply_defaults will no longer throw an
exception.
- super().__init__(**kwargs)
+ super().__init__(conn_id=mysql_conn_id, sql=_METASTORE_PARTITION_SQL,
**kwargs)
def poke(self, context: Context) -> Any:
- if self.first_poke:
- self.first_poke = False
- if "." in self.table:
- self.schema, self.table = self.table.split(".")
- self.sql = f"""
- SELECT 'X'
- FROM PARTITIONS A0
- LEFT OUTER JOIN TBLS B0 ON A0.TBL_ID = B0.TBL_ID
- LEFT OUTER JOIN DBS C0 ON B0.DB_ID = C0.DB_ID
- WHERE
- B0.TBL_NAME = '{self.table}' AND
- C0.NAME = '{self.schema}' AND
- A0.PART_NAME = '{self.partition_name}';
- """
+ schema = self.schema
+ table = self.table
+ if "." in table:
+ schema, table = table.split(".", maxsplit=1)
Review Comment:
```suggestion
if "." in self.table:
schema, table = self.table.split(".", maxsplit=1)
else:
schema, table = self.schema, self.table
```
##########
providers/apache/hive/src/airflow/providers/apache/hive/sensors/metastore_partition.py:
##########
@@ -58,28 +70,16 @@ def __init__(
self.partition_name = partition_name
self.table = table
self.schema = schema
- self.first_poke = True
- self.conn_id = mysql_conn_id
- # TODO(aoen): We shouldn't be using SqlSensor here but
MetastorePartitionSensor.
- # The problem is the way apply_defaults works isn't compatible with
inheritance.
- # The inheritance model needs to be reworked in order to support
overriding args/
- # kwargs with arguments here, then 'conn_id' and 'sql' can be passed
into the
- # constructor below and apply_defaults will no longer throw an
exception.
- super().__init__(**kwargs)
+ super().__init__(conn_id=mysql_conn_id, sql=_METASTORE_PARTITION_SQL,
**kwargs)
Review Comment:
If someone already use `MetastorePartitionSensor(con_id=...)`, it would
cause an issue.
something like
```suggestion
_kwargs = {"conn_id": mysql_conn_id, sql: _METASTORE_PARTITION_SQL}
if kwargs:
_kwargs |= kwargs
super().__init__(**_kwargs)
```
works better
##########
providers/apache/hive/src/airflow/providers/apache/hive/sensors/metastore_partition.py:
##########
@@ -58,28 +70,16 @@ def __init__(
self.partition_name = partition_name
self.table = table
self.schema = schema
- self.first_poke = True
- self.conn_id = mysql_conn_id
- # TODO(aoen): We shouldn't be using SqlSensor here but
MetastorePartitionSensor.
- # The problem is the way apply_defaults works isn't compatible with
inheritance.
- # The inheritance model needs to be reworked in order to support
overriding args/
- # kwargs with arguments here, then 'conn_id' and 'sql' can be passed
into the
- # constructor below and apply_defaults will no longer throw an
exception.
- super().__init__(**kwargs)
+ super().__init__(conn_id=mysql_conn_id, sql=_METASTORE_PARTITION_SQL,
**kwargs)
def poke(self, context: Context) -> Any:
- if self.first_poke:
- self.first_poke = False
- if "." in self.table:
- self.schema, self.table = self.table.split(".")
- self.sql = f"""
- SELECT 'X'
- FROM PARTITIONS A0
- LEFT OUTER JOIN TBLS B0 ON A0.TBL_ID = B0.TBL_ID
- LEFT OUTER JOIN DBS C0 ON B0.DB_ID = C0.DB_ID
- WHERE
- B0.TBL_NAME = '{self.table}' AND
- C0.NAME = '{self.schema}' AND
- A0.PART_NAME = '{self.partition_name}';
- """
+ schema = self.schema
+ table = self.table
+ if "." in table:
+ schema, table = table.split(".", maxsplit=1)
Review Comment:
also, do we really need `maxsplit=1` here? wouldn't it cause more trouble if
someone passes `a.b.c`
--
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]