How to execute SQL against CSV resources

Assuming there is a project containing VIVIDUS-based tests (e.g. VIVIDUS Starter) and the goal is to execute SQL queries against CSV resources to get the various subsets of the data.

  1. Add the required dependencies (CSV and DB plugins, CSV driver) to the project build.gradle

    implementation(group: 'org.vividus', name: 'vividus-plugin-csv', version: '0.3.7')
    implementation(group: 'org.vividus', name: 'vividus-plugin-db', version: '0.3.7')
    implementation(group: 'com.github.simoc', name: 'csvjdbc', version: 'd939a2f344')
  2. Configure connection to the CSV resources

    db.connection.csv-data.driver-class-name=org.relique.jdbc.csv.CsvDriver
    db.connection.csv-data.url=jdbc:relique:csv:classpath:path/to/csv/data

    driver-class-name should be the same for all CSV connections. url includes the mandatory path to CSV resources and may also contain a set of options configuring CSV parsing, e.g.:

    db.connection.csv-data-2.driver-class-name=org.relique.jdbc.csv.CsvDriver
    db.connection.csv-data-2.url=jdbc:relique:csv:classpath:another/path?separator=;&quoteStyle=C
  3. Use the configured connection to execute SQL

    Example 1. Execute SQL against CSV
    When I execute SQL query `
    SELECT * FROM capitals
    ` against `csv-data` and save result to scenario variable `csv-records`
    Then `${csv-records}` matching rows using `country` from `csv-data` is equal to data from:
    |country |capital |population |
    |Belarus |Minsk   |1975000    |

    where capitals is the name of CSV resource (the full resource path is path/to/csv/data/capitals.csv).

    The complete guide on SQL syntax and supported functions can be found in CSV Driver documentation.