Created
March 20, 2018 12:32
-
-
Save dmitriyshashkin/6a4849bdcf882ba340cdfbc1990da401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import sqlalchemy\n", | |
"import pandas as pd\n", | |
"import io\n", | |
"import requests\n", | |
"from clickhouse_driver import Client" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"engine = sqlalchemy.create_engine('clickhouse+native://default:@localhost/default')\n", | |
"conn_yc = engine.connect()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"engine = sqlalchemy.create_engine('clickhouse://default:@localhost:8123/default')\n", | |
"conn_yc_http = engine.connect()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"client = Client('localhost')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[(2017, 4, 12, 1, 5, datetime.date(2017, 12, 1), 'OO', 20304, 'OO', 'N954SW', '5413', 12892, 1289206, 32575, 'LAX', 'Los Angeles, CA', 'CA', '06', 'California', 91, 14262, 1426204, 34262, 'PSP', 'Palm Springs, CA', 'CA', '06', 'California', 91, 1855, 1842, -13, 0, 0, '-1', '1800-1859', 14, 1856, 1924, 7, 1955, 1931, -24, 0, 0, -2, '1900-1959', 0, '', 0, 60, 49, 28, 1, 110, 1, 0, 0, 0, 0, 0, '', '', '', '0', '', '', '', '', '', 0, 0, '', '', '', '', '', '', 0, 0, '', '', '', '', '', '', 0, 0, '', '', '', '', '', '', 0, 0, '', '', '', '', '', '', 0, 0, '', '', '', '', '')]" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"conn_yc.execute('select * from ontime limit 1').fetchall()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 1min 13s, sys: 388 ms, total: 1min 14s\n", | |
"Wall time: 1min 14s\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"464205" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%time df = conn_yc.execute('select * from ontime').fetchall()\n", | |
"len(df)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 33.4 s, sys: 612 ms, total: 34 s\n", | |
"Wall time: 34.2 s\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"464203" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%time df = conn_yc_http.execute('select * from ontime').fetchall()\n", | |
"len(df)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 5.88 s, sys: 508 ms, total: 6.39 s\n", | |
"Wall time: 7.29 s\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"464204" | |
] | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%time df = pd.read_table(io.BytesIO(requests.get('http://localhost:8123', {'query': 'select * from ontime'}).content), low_memory=False)\n", | |
"len(df)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 50 s, sys: 249 ms, total: 50.3 s\n", | |
"Wall time: 50.4 s\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"464205" | |
] | |
}, | |
"execution_count": 29, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"client = Client('localhost')\n", | |
"%time df = client.execute('select * from ontime')\n", | |
"len(df)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 50.3 s, sys: 240 ms, total: 50.6 s\n", | |
"Wall time: 50.7 s\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"464205" | |
] | |
}, | |
"execution_count": 25, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"client = Client('localhost', compression=True)\n", | |
"%time df = client.execute('select * from ontime')\n", | |
"len(df)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment