The error you're encountering suggests that Azure Data Factory (ADF) is treating the variable @counter
as a parameter placeholder (?
) in the SQL query. This issue arises because of how ADF handles parameters in linked services for databases, and the new MySQL connector you updated to might have stricter handling of variable syntax.
- Instead of directly writing the query in the pipeline, encapsulate the logic in a stored procedure in MySQL. Call the stored procedure in the ADF pipeline using a query like: CALL IncrementCounter();
- Rewrite the query to initialize and use the variable inline. This might work better with the ADF's parameter parsing logic. However, if this still causes issues due to ADF's query parsing behavior, proceed with alternative methods.
SELECT (@counter := @counter + 1) AS row_number, col1, col2 FROM your_table, (SELECT @counter := 0) AS init;
- If your MySQL version supports window functions,
ROW_NUMBER()
is a better alternative for large datasets:SELECT ROW_NUMBER() OVER (ORDER BY some_column) AS row_number, col1, col2 FROM your_table;
- Check and Update Connector/Driver Settings
- Workaround with ADF Expressions
- Fetch the data from MySQL without the counter.
- Use an ADF Data Flow or Script Activity to add a counter column in post-processing