Skip to main content

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.8.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file sql-judge-utils-0.1.8.tar.gz.

File metadata

  • Download URL: sql-judge-utils-0.1.8.tar.gz
  • Upload date:
  • Size: 7.1 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

Hashes for sql-judge-utils-0.1.8.tar.gz
Algorithm Hash digest
SHA256 c331e0ba776cbea05d98124c62a74315379c0436c91e1b952ea67eb381d35b7b
MD5 db0aa987c9e95d97db0a5798a7fd28b9
BLAKE2b-256 66025e7c812fdcc0cfc51459eabcc8279c42c92f2d849128f28a34632dadd079

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page