A Simple Query Tool =================== Informal specification ---------------------- The tool must support some implementation of tables. A table has rows and columns. The rows are numbered and the columns are named. Row-numbering may begin at either 0 or 1. Column-names must be unique within a table. A table cell may contain arbitrary data (optionally including tables.) The tool contains the following functions: 1) table <- rows(table, selection-criterion) A selection-criterion is a boolean expression over the columns of the table. The 'rows' function returns a table whose columns are those of the input table and whose rows are just those of the input table which satisfy the selection criterion. For example, rows(employee, (age<40) and (salary > 20,000) returns a subset of the table containing information for those employees younger than 40 and earning more than 20,000. 2) table <- cols(table, column-list) The 'cols' function returns a table with the same number of rows as the input table, whose columns are those in the column-list. For example, the result of cols(employee, (age, salary)) contains just the two columns age and salary. Together, these two functions can be used to simulate SQL 'select': select age, salary from employee where age < 40 and salary > 20,000 3) table <- order(table,column-list,direction-list) The 'order' table sorts the input table according to the column- list and the direction-list. For example, order(employee, (age, salary), (asc, desc)) sorts the employee table by salary descending within age ascending. This is similar to SQL's 'order by' clause: select * from employee order by age, salary(desc) 4) table <- group(table, key-list, aggregate-list, function-list) The 'group' function aggregates the input table on the key list. For each partition, it applies each element of the function list to the corresponding column in the aggregate list, creating a new field whose name is formed by joining the column-name to the function-name. For example, group(employee, age, salary, avg) returns a table with key age and aggregate field avg_salary, containing the average salary for employees of the same age. The 'group' function should support at least the aggregation functions count, sum, and average. The 'group' function provides us with SQL's 'group by': select avg(salary) from employee group by age The syntax of use will depend on the implementation language. The goal of the exercise is to produce a tool-set which is most useful to the application programmer, not the end-user of the application. Optional additional functions ----------------------------- 5) table <- insert(table, rows) 6) table <- update(table, column-list, row-list, rows) 7) table <- delete(table, selection-criterion)
What is tested: Databaselike data storage
Contributed by Stevan Apter , sa at nsl.com