Skip to content

Enhance QueryGenerator.m to test functions in generated queries; Fix a longstanding issue in reading pastas.zwr

Narayanan Iyer requested to merge nars1/YDBOcto:querygen into master
  • The main changes are to QueryGenerator.m where the generated sql queries now randomly include SQL function invocations in the WHERE clause in places where string/numeric/boolean/integer literals would have been used previously. This increases the test coverage for Octo's implementation of SQL functions.

    The function chosen is a simple one (samevalue). One that returns the single input parameter as the output parameter. Different functions are defined, one for each possible input parameter type.

    These function definitions are done for Octo in tests/fixtures/QueryGenerator.sql and for Postgres in tests/fixtures/postgres-QueryGenerator.sql.

    The TCF018 bats subtest previously used a similar function tests/fixtures/samestr.m and that is now renamed to tests/fixtures/functions.m so the new M file can have a list of other functions too in case the need for more functions arises in the future. This functions.m is now used by the TCF018 bats subtest as well as all subtests in the test_query_generator bats test.

  • While doing these changes, it was noticed that in case a table has only one non-key column (e.g. pastas table), the logic to read the *.zwr file (tests/fixtures/pastas.zwr file in this case) had a bug where it used to not strip out the trailing double quote at the end of the line. For example, a line ^pastas(0)="Fettucine" would be read with the pastaName column value being Fettucine". This is because the start of the column value would be marked as after the =" but the end would be marked as the $PIECE output using | as the delimiter. And when there is just one non-key column, there would be no | occurrence resulting in the trailing " at the end of the line also getting included in the column value resulting in queries incorrectly using pastaName literal values which do not correspond to actual pastaName values resulting in unintended reduction of test coverage in the pastas table case. This is now fixed in tests/fixtures/QueryGenerator.m by first removing the trailing double quote from the line(i) variable before trying to derive the column values. This also simplified the logic in case there were more than one non-key column. That case had logic to remove any double quote whereas it intended to only remove the trailing double quote. That potentially unsafe logic is also now removed and will let us have double quotes in the middle of column values without issues (in case such a situation arises in the future).

Merge request reports