skydb/sky — pull request #119 by benbjohnson (2013-08-19 23:03:39+00:00)
Title: Refactor query package

### Overview

I added a SQL-style language to Sky because some of the queries I'm starting to build are becoming a pain to do without it. The `query` package now has an actual AST with expressions and nodes and whatnot. It makes doing the codegen a lot easier.

### Usage

You can use the new parser in two ways. If you continue to use the JSON interface, the `ExpressionParser` will convert your `Condition` expression into an AST expression behind the scenes so you can do more complex expressions (e.g. `price != 23 || (timestamp >= 1000 && timestamp < (2000 + myIntProperty)) || myBoolProperty`).

The other way is to pass the whole SQL-like query like this:

```
$ curl -X POST http://localhost:8585/tables/users/query -d '{
"sessionIdleTime": 7200,
"content": "SELECT count() AS myCount GROUP BY action;"
}'
```

### Syntax

#### Selection

Here are some examples of selections:

```
SELECT count() AS count;
SELECT sum(price) AS totalPrice, min(price) AS min_price GROUP BY country, province INTO "myNamespace";
SELECT count() AS count INTO "myNamespace";
```

Selections have 3 parts: fields (1..*), dimensions (0..*), and namespace (0..1). They always end with a semicolon.

#### Condition

Here some examples of conditions:

```
WHEN action == "signup" THEN
SELECT count() AS count;
END
```

```
WHEN action == "home" THEN
SELECT count() AS count INTO "step0";
WHEN action == "signup" WITHIN 1..1 STEPS THEN
SELECT count() AS count INTO "step1";
END
END
```

### Other Notes

I'd like to figure out a good default value for the selection fields but I haven't added that yet. Also, I don't have expression parsing in the selection fields so they're still pretty dumb (e.g. `SELECT func(field)`).

Can you guys give this branch a try against your tests and see if you have any issues? It's working against all the test cases in Sky.

/cc: @snormore @boourns @orenmazor