-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!python3 | ||
import os | ||
import pyarrow as pa | ||
import chdb | ||
|
||
# get current file dir | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
test_parquet = current_dir + "/../contrib/arrow/cpp/submodules/parquet-testing/data/alltypes_dictionary.parquet" | ||
|
||
# run SQL on parquet file and return arrow format | ||
res = chdb.query(f"select * from file('{test_parquet}', Parquet)", "Arrow") | ||
print("\nresult from chdb:") | ||
print(res.get_memview().tobytes()) | ||
|
||
def to_arrowTable(res): | ||
# convert arrow format to arrow table | ||
paTable = pa.RecordBatchFileReader(res.get_memview()).read_all() | ||
return paTable | ||
|
||
def to_df(res): | ||
# convert arrow format to arrow table | ||
paTable = to_arrowTable(res) | ||
# convert arrow table to pandas dataframe | ||
return paTable.to_pandas(use_threads=True) | ||
|
||
print("\nresult from chdb to pyarrow:") | ||
print(to_arrowTable(res)) | ||
|
||
# convert arrow table to pandas dataframe | ||
print("\nresult from chdb to pandas:") | ||
print(to_df(res)) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.