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 with sql string or sql file path:
db1.init(sql_string)
# or
db1.initf(sql_file_path)
  • Run query
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.5.tar.gz (6.3 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: sql-judge-utils-0.1.5.tar.gz
  • Upload date:
  • Size: 6.3 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.5.tar.gz
Algorithm Hash digest
SHA256 8b6245c2a6df6fd3db2ba5ab3f7c4631b359bb82fdad47ae52e6b34e21219d2c
MD5 a4d5115838bd2ce0d5e66d3352c2b2d5
BLAKE2b-256 f2ccb90ff04fceba3f12ae61fbc9b60271e50554843d2c58dc36c401d99fe899

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