diff --git a/src/connectors/mysql_connector.py b/src/connectors/mysql_connector.py index 0a9f6af..0250493 100644 --- a/src/connectors/mysql_connector.py +++ b/src/connectors/mysql_connector.py @@ -308,10 +308,25 @@ class MySQLConnector: yield current_group return else: - # More rows might exist - yield the last group only if key changed - # If not, it will be continued/merged in next iteration - if current_group: - yield current_group + # More rows might exist after this batch + # Check if the last row in this batch has same key as current_group + # If yes, DON'T yield yet - the group might continue in next batch + # If no, yield because we know the group is complete + if rows: + last_row = rows[-1] + last_row_key = ( + last_row.get("UnitName"), + last_row.get("ToolNameID"), + last_row.get("EventDate"), + last_row.get("EventTime") + ) + + # If last row has different key than current group, current group is complete + if last_row_key != current_key and current_group: + yield current_group + current_group = [] + current_key = None + # else: same key as current_group, so continue in next iteration # Update last_key for next iteration if current_key: