Package: pypreql
PreQLpypreql is an experimental implementation of thePreQL.The preql language spec itself will be linked from the above repo.Pypreql can be run locally to parse and execute preql [.preql] models.ExamplesExamples can be found in thepublic model repository.
This is a good place to start for a basic understanding of the language.DialectsThe POC supports alpha syntax forBigquerySQL ServerDuckDBSetting Up Your EnvironmentRecommend that you work in a virtual environment with requirements from both requirements.txt and requirements-test.txt installed. The latter is necessary to run
tests (surprise).Pypreql is python 3.10+Running TestsThe tests are implemented primarily in pytest. To run all tests you are strongly suggested to have docker installed, though you can manually configured the required
data warehouse in an express edition of SQL server if docker is not possible. Guidance for the non-docker path is not provided. Docker is
STRONGLY RECOMMENDED.A portion of the tests are dependent on having access to an AdventureWOrks2019DW example database
in Microsoft SQL Server that can be downloaded via this [link]https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorksDW2019.bak.The tests will treat this as database server a pytest fixture, starting a docker image if the tests detect a sql server is not already running. Before
you run tests you must build this docker image. From the root of this repository run the following to fetch the database data and build a docker image
containing it/bin/bash./docker/build_image.shIf you are using windows download the AdventureWorks2019DW database backup from the link above and place it in the ./docker path.
From the root of the repo rundockerbuild--no-cache./docker/-tpyreql-test-sqlserverTo run the test suite, from the root of the repository runpython-mpytest./testsBasic ExampleBigquery, similar tothe quickstartfrompreqlimportDialects,Environmentenvironment=Environment()environment.parse('''key name string;key gender string;key state string;key year int;key name_count int;auto name_count.sum <- sum(name_count);datasource usa_names(name:name,number:name_count,year:year,gender:gender,state:state)address bigquery-public-data.usa_names.usa_1910_2013;''')executor=Dialects.BIGQUERY.default_executor(environment=environment)results=executor.execute_text('''SELECTname,name_count.sumORDER BYname_count.sum descLIMIT 10;''')# multiple queries can result from one text batchforrowinresults:# get results for first queryanswers=row.fetchall()forxinanswers:print(x)Developingimportconcepts.internet_salesasinternet_sales;importconcepts.customerascustomer;importconcepts.datesasdates;importconcepts.sales_territoryassales_territory;selectcustomer.first_name,customer.last_name,internet_sales.total_order_quantity,internet_sales.total_sales_amountorderbyinternet_sales.total_sales_amountdesclimit100;selectdates.order_date,customer.first_name,internet_sales.total_order_quantity,internet_sales.total_sales_amountorderbyinternet_sales.total_sales_amountdesclimit100;selectinternet_sales.order_number,internet_sales.order_line_number,internet_sales.total_sales_amount,sales_territory.region,customer.first_nameorderbyinternet_sales.order_numberdesclimit5;importconcepts.internet_salesasinternet_sales;importconcepts.customerascustomer;importconcepts.datesasdates;importconcepts.sales_territoryassales_territory;selectcustomer.first_name,customer.last_name,internet_sales.total_order_quantity,internet_sales.total_sales_amountorderbyinternet_sales.total_sales_amountdesclimit100;selectdates.order_date,customer.first_name,internet_sales.total_order_quantity,internet_sales.total_sales_amountorderbyinternet_sales.total_sales_amountdesclimit100;selectinternet_sales.order_number,internet_sales.order_line_number,internet_sales.total_sales_amount,sales_territory.region,customer.first_nameorderbyinternet_sales.order_numberdesclimit5;ContributingSimilar in spacesingleorigin