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
There is a Groovy script, gcsvsql that lets you treat csv files as database tables, including joins. With gcsvsql you can do things like:
gcsvsql "select * from people.csv where age > 40"
gcsvsql "select people.name,children.child from people.csv,children.csv where people.name=children.name"
gcsvsql "select avg(score) from people.csv where age < 40"
You can find this script, which is based on the h2 database engine, at Google code here:
http://code.google.com/p/gcsvsql/