A reusable python package for problem design and judge of quera sql problems
Project description
sql-judge-utils
Utils methods to write python unit tests for version 2 of QUERA sql judge system.
Install
pip install sql-judge-utils # or git+https://github.com/QueraTeam/sql-judge-utils
Database
1. Import one of database classes
- Postgresql:
from sql_judge_utils.postgresql import PostgresqlDatabase as Database
- Mysql:
from sql_judge_utils.mysql import MysqlDatabase as Database
2. Define database instances:
db1 = Database('db1')
db2 = Database('db2')
Optional arguments in database defining:
Option key | Postgresql default | Mysql default |
---|---|---|
host |
'postgresql' |
'mysql' |
port |
'5432' |
'3306' |
username |
'postgres' |
'root' |
password |
None |
None |
⚠️ WARNING: Dont change these properties in QUERA judge tests. These must be same default values
3. Use utils:
- Create database:
db1.create()
- Drop database:
db1.drop()
- Init data (run sql command without fetching results) with sql string or sql file path:
db1.init(sql_string)
# or
db1.initf(sql_file_path)
- Run query with fetching results
col_names, records = db1.run_query(sql_string)
- Compare two result of run_query:
status, message = Database.compare_query_result(col_names_1, records_1, col_names_2, records_2)
- Compare two database instances:
status, message = db1.is_equal(db2)
- Compare two database instances on a table:
status, message = db1.is_equal_on_table(db2, table_name)
SQL parser to find submission queries
from sql_judge_utils.parser import get_queries, get_query
submission_file_path = 'path/to/submission.sql'
queries = get_queries(submission_file_path)
# or
submission_file_path = 'path/to/submission.sql'
query_number = 2
query = get_query(submission_file_path, query_number)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sql-judge-utils-0.1.7.tar.gz
(6.4 kB
view details)
File details
Details for the file sql-judge-utils-0.1.7.tar.gz
.
File metadata
- Download URL: sql-judge-utils-0.1.7.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad99cd690a4ebb1c649cf092414529505e7ff763631eee8a8c216e27ed8bcade |
|
MD5 | 9ede029736bd18ce72feba3984061135 |
|
BLAKE2b-256 | 70c0bbc4b16c067a4c71443405475231e97864b71e8fab722ed75c1d24dcf331 |