datacamp / sqlwhat

https://sqlwhat.readthedocs.io
GNU Affero General Public License v3.0
3 stars 8 forks source link

Fs check query #127

Closed filipsch closed 5 years ago

filipsch commented 5 years ago

@richierocks these changes would include a new function in sqlwhat, called check_query(), that allows you to run arbitrary sql statements after rerunning the student query, so you can verify whether UPDATEs, INSERTs etc happened correctly. Let me know what you think, if you have an opinion. The docs in sqlwhat/checks/check_funcs.py are most interesting for you.

filipsch commented 5 years ago

@richierocks, @hermansje and I have worked on an improved version. Basically, this is how you would now check whether running a query returns the same table after executing the student/solution code (that would contain INSERT statements, for example):

Ex().check_query('SELECT COUNT(*) FROM company').has_equal_value()

What this does, as mentioned before:

  1. Run the solution submission + the query passed in check_query() in a transaction and fetch the result.
  2. Run the student's submission + the query passed in check_query() in a transaction and fetch the result.
  3. Create a 'child state' with this 'solution result' and 'student result' that you can chain off of with check_column() (if you want to further zoom in), has_equal_value() etc.
  4. has_equal_value() will then compare these results.

Thus, in a sense, check_query() is 'overriding' the query result that the student's submission and solution generated and that is stored in Ex().

Looks good?

richierocks commented 5 years ago

One thing to note is that is you want to check arbitrary expressions, the syntax is pretty different across languages.

R:

ex() %>% check_expr('some code') %>% check_result() %>% check_equal()

Shell:

Ex().has_expr_output(expr='some command', output='some output')

SQL:

Ex().check_query('SELECT something').has_equal_value()

@hermansje figuring out how to synchronize the check syntax across the *what packages would be a good long term project.

klmedeiros commented 5 years ago

I'd like to second what @richierocks has said above. As someone who frequently switches back and forth between languages writing SCTs, it gets difficult with the inconsistency in function names.

filipsch commented 5 years ago

@klmedeiros @richierocks I understand your concerns, and @hermansje and I talked about it at length. Before I go, I will make sure to list out exactly which functions are used where and how, and Jeroen can then think about how things can be made more consistent.

However, some thoughts:

klmedeiros commented 5 years ago

@filipsch Thank you for the context in your response, that's very helpful for me!