Skip to content

Commit

Permalink
Merge pull request #12 from partiql/cow-jan
Browse files Browse the repository at this point in the history
GitHub Action and Encoding logic.
  • Loading branch information
yliuuuu authored Jan 23, 2024
2 parents 4014486 + 3d683e1 commit abdc163
Show file tree
Hide file tree
Showing 26 changed files with 204 additions and 16,835 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/pr_wasm_to_website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: pr wasm to website

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- name: Install WASM
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Build WASM
run: make build

- name: Copy WASM
run: |
# the auto generated gitignore will ignore all the wasm build file.
rm pkg-web/.gitignore
git config --global user.email "[email protected]"
git config --global user.name "PartiQL Team"
git add pkg-web
git commit -m "commit wasm files"
git fetch
git checkout react-website
git checkout main -- pkg-web
git add pkg-web
git commit -m "wasm update"
- name: pr
uses: peter-evans/create-pull-request@v5
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ partiql-logical-planner = { version = "0.3.*"}
partiql-eval = { version = "0.3.*"}
partiql-value = { version = "0.3.*", features=["serde"] }
partiql-logical = { version = "0.3.*", features=["serde"] }
ion-rs = "0.18"
base64 = "0.21"

serde_json = "1.*"
wasm-bindgen = "0.2"
js-sys = "0.3.67"

[dev-dependencies]
wasm-bindgen-test = "0.3"

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
build:
wasm-pack --version && \
wasm-pack build --target web --out-dir pkg-web/ && \
wasm-pack build --target nodejs --out-dir pkg-node/ && \
npm i
wasm-pack build --target web --out-dir pkg-web/

container-build:
docker build . -t partiql-team/partiql-playground
wasm-pack --version && \
wasm-pack build --target nodejs --out-dir pkg-node/ && \
docker build -f docker/Dockerfile . -t partiql-team/partiql-playground

container-run:
docker run -d -p 8000:8000 partiql-team/partiql-playground
148 changes: 55 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
# PartiQL Playground (Proof of Concept)

PartiQL Playground provides the functionality to execute PartiQL in a web environment. It also provides
REST API endpoints for the same functionality.
PartiQL Playground provides the functionality to execute PartiQL in a web environment.

_Please note, at this stage, the code as is in this package is considered experimental and should not be used for production._

## Features
- Ability to `parse`, `explain`, and `evaluate` given query statements.
- Ability to share sessions with session import and export.
- Ability to run both as a docker container and standalone server.
- Expose `/parse`, `/explain`, and `/eval` REST APIs.
```bash
:raised_hands: Checkout the [playground](https://partiql.org/playground.html#/evaluate) now :raised_hands:.

## Development
This Branch contains Rust Code for WASM generation.

`PartiQL Playground` uses [WebAssembly (Wasm)](https://webassembly.org/) for integrating the front-end with PartiQL Rust back-end.

Upon merging pull request, the GitHub action will automatically create a new pull request towards `react-website` branch.

The `React Website` branch contains code for the experimental web application.

To run test:
```
```

## Build and run the website application (Locally)
1. Checkout main branch and develop
2. Build the package using `make`
```commandline
make build
```
3. Port the wasm files to `react wesbite` branch
```commandline
git checkout -b temp
make buid
rm pkg-web/.gitignore
git add .
git commit -m "adding pkg-web to git"
git checkout react-website
git checkout temp -- pkg-web
git add pkg-web
git commit -m "wasm update"
```

4. Build the `react website branch`
```commandline
npm i
npm run serve
```

## Docker Build
```commandline
make container-build
make container-run
```

### Restful API
```commandline
# Example for parsing `SELECT * FROM {'a': 1}` statement
curl -H 'Content-Type: application/json; charset=UTF-8' \
-H "Accept: application/json" \
Expand All @@ -30,97 +72,17 @@ curl -H 'Content-Type: application/json; charset=UTF-8' \
# Example for evaluating `SELECT * FROM env` statement
curl -H 'Content-Type: application/json; charset=UTF-8' \
-H "Accept: application/json" \
--data '{"query": "SELECT * FROM env", "env": "{\"a\": 1, \"b\": 2}"}' \
--data '{"query": "SELECT * FROM env", "env": "{'\''env'\'' : <<{'\''a'\'': 1,'\''b'\'': 2 }>>}"}' \
-X POST http://localhost:8000/eval
"{\"Bag\":[{\"Tuple\":{\"attrs\":[\"a\",\"b\"],\"vals\":[{\"Integer\":1},{\"Integer\":2}]}}]}"%
"{\"Ok\":{\"Bag\":[{\"Tuple\":{\"attrs\":[\"a\",\"b\"],\"vals\":[{\"Integer\":1},{\"Integer\":2}]}}]}}"%
```

## TODO
- Logical Plan visualization
- More readable error reporting
- More structured and rigorous UI testing
- Better UX for query execution (E.g. using keyboard shortcuts)

## Local Usage
For local usage follow the below steps.

1. Ensure `wasm-pack` is installed on your machine by running the following command; if not, install it from [here](https://rustwasm.github.io/wasm-pack/installer/):
```bash
wasm-pack --version
# Sample output
wasm-pack 0.10.2
```
2. Ensure `npm` is intalled on your machine; see [here](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) for more details:
```bash
npm --version
# Sample output
8.13.2
```
3. Build the package using `make`:
```
make build
```
4. Start the node server from `partiql-playground` package's root directory:
```bash
node src/server.ts
```
5. Using your browser go to `http://localhost:8000/`

## Run via docker container

1. Ensure `docker` is installed on your machine, by running the following:
```bash
docker --version
# Example output
Docker version 20.10.17, build 100c701
```
2. Build the package:
```bash
make build
```
3. Build the container:
```bash
make container-build
```
4. Run the container:
```bash
make container-run
```
5. Confirm it's running:
```bash
docker ps
# Example output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d666bba30c2 partiql-team/partiql-playground "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 0.0.0.0:8000->8000/tcp, 8080/tcp infallible_goldberg

# Ensure `connected` is in the curl output
curl -v http://localhost:8000 2>&1 |grep -i connected
# Example output
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (127.0.0.1) port 8000 (#0)
```
## Development
`PartiQL Playground` uses [WebAssembly (Wasm)](https://webassembly.org/) for integrating the front-end with PartiQL Rust back-end.
Considering this, please install the `wasm-pack` by following the instructions [here](https://github.com/rustwasm/wasm-pack#-prerequisities).
Upon any changes to the package's Rust dependencies (E.g. `partiql-parser`) or the wasm code under `./src/lib` of this package, you need to rebuild the Wasm package using the following command from the root of this package:
```bash
wasm-pack build --target web
```
_Please note, as the package is experimental at this stage, all HTML code and assets reside in this package, but this doesn't necessarily mean that it'll be the case in the future._

## Dependencies
| Package | License |
|------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| [ace Editor](https://ace.c9.io/) | [BSD License](https://github.com/ajaxorg/ace/blob/master/LICENSE) |
| [body-parser](https://github.com/expressjs/body-parser) | [MIT License](https://github.com/expressjs/body-parser/blob/master/LICENSE) |
| [bootstrap](https://getbootstrap.com/) | [MIT License](https://github.com/twbs/bootstrap/blob/main/LICENSE) |
| [D3.js](https://d3js.org/) | [ISC License](https://github.com/d3/d3/blob/main/LICENSE) |
| [jquery](https://jquery.com) | [MIT License](https://github.com/jquery/jquery/blob/main/LICENSE.txt) |
| [jquery.json-viewer](https://www.npmjs.com/package/jquery.json-viewer) | [MIT License](https://github.com/abodelot/jquery.json-viewer/blob/master/LICENSE) |
| [node](https://nodejs.org/en/) | [MIT License](https://github.com/nodejs/node/blob/main/LICENSE) |
| [popper.js](https://github.com/floating-ui/floating-ui) | [MIT License](https://github.com/floating-ui/floating-ui/blob/master/LICENSE) |
| [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) | [Apache License Version 2.0](https://github.com/rustwasm/wasm-bindgen/blob/main/LICENSE-APACHE) |
| [wasm-pack](https://github.com/rustwasm/wasm-pack) | [Apache License Version 2.0](https://github.com/rustwasm/wasm-pack/blob/master/LICENSE-APACHE) |
| [wasm-pack](https://github.com/rustwasm/wasm-pack) | [Apache License Version 2.0](https://github.com/rustwasm/wasm-pack/blob/master/LICENSE-APACHE) |
| [node](https://nodejs.org/en/) | [MIT License](https://github.com/nodejs/node/blob/main/LICENSE) |
| [body-parser](https://github.com/expressjs/body-parser) | [MIT License](https://github.com/expressjs/body-parser/blob/master/LICENSE) |
File renamed without changes.
6 changes: 4 additions & 2 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM node:18
# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY ./docker/package*.json ./
COPY ./pkg-node ./

RUN npm install
# If you are building your code for production
Expand All @@ -15,4 +17,4 @@ COPY . .

EXPOSE 8080

CMD [ "node", "src/server.ts" ]
CMD [ "node", "docker/server.ts" ]
5 changes: 2 additions & 3 deletions package.json → docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"homepage": "https://github.com/partiql-lang-rust/partiql-playground#readme",
"dependencies": {
"body-parser": "^1.20.0",
"express": "^4.18.1",
"serve-favicon": "^2.5.0"
"express": "^4.18.1"
}
}
}
15 changes: 2 additions & 13 deletions src/server.ts → docker/server.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
const express = require('express');
const bodyParser = require("body-parser");
const favicon = require('serve-favicon');
const router = express.Router();
const partiql = require('../pkg-node/partiql_playground');

const app = express();
const port = 8000;


app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

app.use(favicon(__dirname + '/favicon.ico'));
app.use('/js', express.static('src/js'));
app.use('/css', express.static('src/css'));
app.use('/ace-builds', express.static('src/ace-builds'));
app.use('/pkg-web', express.static('pkg-web'));

app.get('/', (req, res) => {
res.sendFile('index.html', {root: __dirname});
});

router.post('/parse', (req, res) => {
res.status(200)
.json(JSON.stringify(JSON
Expand All @@ -40,7 +29,7 @@ router.post('/explain', (req, res) => {
router.post('/eval', (req, res) => {
res.status(200)
.json(JSON.stringify(JSON
.parse(partiql.eval_as_json(req.body.query, `{'env': ${req.body.env}}`))
.parse(partiql.eval_as_json(req.body.query, req.body.env))
));
});

Expand Down
Loading

0 comments on commit abdc163

Please sign in to comment.