|
| 1 | +# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 2 | +# ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ |
| 3 | +# ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ |
| 4 | +# ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ |
| 5 | +# ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ |
| 6 | +# ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ |
| 7 | +# ┃ Copyright (c) 2017, the Perspective Authors. ┃ |
| 8 | +# ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ |
| 9 | +# ┃ This file is part of the Perspective library, distributed under the terms ┃ |
| 10 | +# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ |
| 11 | +# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 12 | + |
| 13 | +from pathlib import Path |
| 14 | + |
| 15 | +import duckdb |
| 16 | +import perspective |
| 17 | +import perspective.handlers.tornado |
| 18 | +import perspective.virtual_servers.duckdb |
| 19 | +import tornado.ioloop |
| 20 | +import tornado.web |
| 21 | +import tornado.websocket |
| 22 | + |
| 23 | +from loguru import logger |
| 24 | +from tornado.web import StaticFileHandler |
| 25 | + |
| 26 | + |
| 27 | +INPUT_FILE = ( |
| 28 | + Path(__file__).parent.resolve() |
| 29 | + / "node_modules" |
| 30 | + / "superstore-arrow" |
| 31 | + / "superstore.parquet" |
| 32 | +) |
| 33 | + |
| 34 | + |
| 35 | +if __name__ == "__main__": |
| 36 | + db = duckdb.connect(":memory:perspective") |
| 37 | + db.sql( |
| 38 | + f""" |
| 39 | + SET default_null_order=NULLS_FIRST_ON_ASC_LAST_ON_DESC; |
| 40 | + CREATE TABLE data_source_one AS |
| 41 | + SELECT * FROM '{INPUT_FILE}'; |
| 42 | + """, |
| 43 | + ) |
| 44 | + |
| 45 | + virtual_server = perspective.virtual_servers.duckdb.DuckDBVirtualServer(db) |
| 46 | + app = tornado.web.Application( |
| 47 | + [ |
| 48 | + ( |
| 49 | + r"/websocket", |
| 50 | + perspective.handlers.tornado.PerspectiveTornadoHandler, |
| 51 | + {"perspective_server": virtual_server}, |
| 52 | + ), |
| 53 | + (r"/node_modules/(.*)", StaticFileHandler, {"path": "../../node_modules/"}), |
| 54 | + ( |
| 55 | + r"/(.*)", |
| 56 | + StaticFileHandler, |
| 57 | + {"path": "./", "default_filename": "index.html"}, |
| 58 | + ), |
| 59 | + ], |
| 60 | + websocket_max_message_size=100 * 1024 * 1024, |
| 61 | + ) |
| 62 | + |
| 63 | + app.listen(3000) |
| 64 | + logger.info("Listening on http://localhost:3000") |
| 65 | + loop = tornado.ioloop.IOLoop.current() |
| 66 | + loop.start() |
0 commit comments