Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Update readme, add examples #62

Merged
merged 4 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ We are committed to supporting a baseline set of functionality on all x86 CPUs,

## Components

### Config

`Config` controls library-wide properties and must be passed to `Executor` and `DataMgr`. Default config objects should suffice for most installations. Instantiate a config first as part of library setup.

### Storage

`ArrowStorage` is currently the default (and only available) HDK storage layer. `ArrowStorage` provides storage support for [Apache Arrow](https://github.com/apache/arrow) format data. The storage layer must be explicitly initialized:
Expand Down Expand Up @@ -72,6 +76,10 @@ The return from RelAlgExecutor is a ResultSet object which can be converted to A
df = res.to_arrow().to_pandas()
```

## Examples

Standalone examples are available in the `examples` directory. Most examples run via Jupyter notebooks.

## Build

HDK includes components from external libraries as submodules. To clone the project, either use `git clone --recurse-submodules` to initially clone the repo, or clone without using flags and then run:
Expand Down
98 changes: 98 additions & 0 deletions examples/basic_python_usage.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fdef23a7",
"metadata": {},
"outputs": [],
"source": [
"# Initialization\n",
"import pyhdk \n",
"\n",
"# Uses DBID 1\n",
"pyhdk.initLogger()\n",
"config = pyhdk.buildConfig()\n",
"storage = pyhdk.storage.ArrowStorage(1)\n",
"data_mgr = pyhdk.storage.DataMgr(config)\n",
"data_mgr.registerDataProvider(storage)\n",
"\n",
"calcite = pyhdk.sql.Calcite(storage, config)\n",
"executor = pyhdk.Executor(data_mgr, config)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a5af996c",
"metadata": {},
"outputs": [],
"source": [
"# Helper Functions\n",
"def get_rel_alg(sql):\n",
" return calcite.process(sql)\n",
"\n",
"def run_query(sql):\n",
" ra = get_rel_alg(sql)\n",
" # One RelAlgExecutor per query\n",
" rel_alg_executor = pyhdk.sql.RelAlgExecutor(executor, storage, data_mgr, ra)\n",
" return rel_alg_executor.execute()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b771266",
"metadata": {},
"outputs": [],
"source": [
"## Examples \n",
"\n",
"# Load some data\n",
"import pandas\n",
"import pyarrow as pa\n",
"\n",
"tbl = pa.Table.from_pandas(pandas.DataFrame({\"a\": [1, 2, 3], \"b\": [10, 20, 30]}))\n",
"opt = pyhdk.storage.TableOptions(2)\n",
"storage.importArrowTable(tbl, \"test\", opt)\n",
"\n",
"# Basic query\n",
"print(run_query(\"SELECT * FROM test;\").to_arrow().to_pandas())\n",
"\n",
"print(run_query(\"SELECT a, count(*), sum(b) FROM test GROUP BY a;\").to_arrow().to_pandas())\n",
"\n",
"# Cleanup\n",
"storage.dropTable(\"test\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24e70d3f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
47 changes: 0 additions & 47 deletions scripts/conda/hdk-conda-dev-env.yml

This file was deleted.

1 change: 1 addition & 0 deletions scripts/conda/hdk-conda-dev-env.yml