def _table_column_max_string(db_hook: MsSqlHook, table: str, column: str): """ Calcula o valor máximo da coluna (column) na tabela (table). Se a coluna for 'dataalteracao' a string retornada é formatada. """ sql = f"SELECT MAX({column}) FROM {table};" max_value = db_hook.get_first(sql)[0] # TODO: Descobrir se é data pelo tipo do BD if column == 'dataalteracao': return max_value.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] else: return str(max_value)
def _build_filter_condition(dest_hook: MsSqlHook, table: str, date_column: str, key_column: str): if date_column: sql = f"SELECT MAX({date_column}) FROM {table}" else: sql = f"SELECT MAX({key_column}) FROM {table}" max_value = dest_hook.get_first(sql)[0] if date_column: max_value = max_value.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] where_condition = f"{date_column} > '{max_value}'" else: max_value = str(max_value) where_condition = f"{key_column} > '{max_value}'" return max_value, where_condition