ContinuumIO/blaze — pull request #527 by mrocklin (2014-08-27 18:13:37+00:00)
Title: [WIP] - Server exprs

Phil and I are playing with Blaze server. Here is a raw query.

```Python
In [1]: from blaze.serve import Server

In [2]: from blaze import *

In [3]: csv = CSV('data/iris/iris.csv')

In [4]: csv.schema
Out[4]: dshape("{ SepalLength : ?float64, SepalWidth : ?float64, PetalLength : ?float64, PetalWidth : ?float64, Species : string }")

In [5]: server = Server({'iris': csv})

In [6]: server.app.run()
```

```Python

In [1]: from blaze import *
t =
In [2]: t = TableSymbol('t', "{ SepalLength : ?float64, SepalWidth : ?float64, PetalLength : ?float64, PetalWidth : ?float64, Species : string }")

In [3]: from blaze.serve.server import to_tree

In [4]: expr = by(t, t.Species, t.PetalWidth.max())

In [5]: tree = to_tree(expr)

In [6]: tree
Out[6]:
{'By': [{'TableSymbol': ['t',
'var * { SepalLength : ?float64, SepalWidth : ?float64, PetalLength : ?float64, PetalWidth : ?float64, Species : string }',
False]},
{'Column': [{'TableSymbol': ['t',
'var * { SepalLength : ?float64, SepalWidth : ?float64, PetalLength : ?float64, PetalWidth : ?float64, Species : string }',
False]},
'Species']},
{'max': [{'Column': [{'TableSymbol': ['t',
'var * { SepalLength : ?float64, SepalWidth : ?float64, PetalLength : ?float64, PetalWidth : ?float64, Species : string }',
False]},
'PetalWidth']}]}]}

In [7]: import requests

In [10]: r = requests.get('http://localhost:5000/compute/iris.json', data = json.dumps({'expr': tree}), headers={'Content-Type': 'application/json'})

In [12]: r.json()
Out[12]:
{u'data': [[u'setosa', 0.6], [u'versicolor', 1.8], [u'virginica', 2.5]],
u'datashape': u'var * { Species : string, PetalWidth_max : ?float64 }',
u'name': u'iris'}
```

Note the format of `tree` above. Note that it's not as complicated as it seems, most of the complexity is in repeated subexpressions (really just the tablesymbol). Still, I think that this is challenging to produce manually without library support (e.g. `to_tree` function and Blaze expressions).