I need to apply an SQL query to CSV files (comma-separated text files). My SQL is predefined from another tool, and is not eligible to change. It may contain embedded select
If your SQL is predefined and cannot be changed your best option is to load your CSV into a database and run queries against it.
Apache Derby is a viable option, so are MySQL, which even has a CSV storage engine or PostgreSQL.
Does your SQL use any proprietary functions / extensions? If so, that may limit your choices.