Skip to content

Instantly share code, notes, and snippets.

@roaramburu
Created August 1, 2019 20:48
Show Gist options
  • Save roaramburu/2c2839241252141ceec810d58b9fed29 to your computer and use it in GitHub Desktop.
Save roaramburu/2c2839241252141ceec810d58b9fed29 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from blazingsql import BlazingContext\n",
"import cudf\n",
"import dask_cudf\n",
"import dask\n",
"from dask.distributed import Client"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client = Client('127.0.0.1:8786')\n",
"bc = BlazingContext(dask_client=client)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Use HDFS\n",
"bc.hdfs('bsql_data', host='35.203.181.221', port=54310, user='hadoop')\n",
"table_list = ['hdfs://bsql_data/netflow_parquet/1_0_0.parquet', 'hdfs://bsql_data/netflow_parquet/1_1_0.parquet', 'hdfs://bsql_data/netflow_parquet/1_2_0.parquet', 'hdfs://bsql_data/netflow_parquet/1_3_0.parquet']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bc.create_table('netflow', table_list)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = bc.sql('''SELECT\n",
" a.firstSeenSrcIp as source,\n",
" a.firstSeenDestIp as destination,\n",
" count(a.firstSeenDestPort) as targetPorts,\n",
" SUM(a.firstSeenSrcTotalBytes) as bytesOut,\n",
" SUM(a.firstSeenDestTotalBytes) as bytesIn,\n",
" SUM(a.durationSeconds) as durationSeconds,\n",
" MIN(parsedDate) as firstFlowDate,\n",
" MAX(parsedDate) as lastFlowDate,\n",
" COUNT(*) as attemptCount\n",
" FROM\n",
" main.netflow a\n",
" GROUP BY\n",
" a.firstSeenSrcIp,\n",
" a.firstSeenDestIp''').get()\n",
"\n",
"print(result.head())"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment