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