File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
1
import sys
2
2
import os
3
+ import pyarrow as pa
4
+
3
5
4
6
chdb_version = (0 , 1 , 0 )
5
7
if sys .version_info [:2 ] >= (3 , 7 ):
22
24
except : # pragma: no cover
23
25
__version__ = "unknown"
24
26
25
- # wrap _chdb functions
26
27
28
+ def _to_arrowTable (res ):
29
+ """convert res to arrow table"""
30
+ return pa .RecordBatchFileReader (res .get_memview ()).read_all ()
31
+
32
+ def to_df (r ):
33
+ """"convert arrow table to Dataframe"""
34
+ t = _to_arrowTable (r )
35
+ return t .to_pandas (use_threads = True )
36
+
37
+ # wrap _chdb functions
27
38
def query (sql , output_format = "CSV" , ** kwargs ):
39
+ if output_format .lower () == "dataframe" :
40
+ r = _chdb .query (sql , "Arrow" , ** kwargs )
41
+ return to_df (r )
28
42
return _chdb .query (sql , output_format , ** kwargs )
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from .__init__ import query
3
+
4
+ def main ():
5
+ if len (sys .argv ) < 2 :
6
+ exit (0 )
7
+ output_format = sys .argv [2 ] if len (sys .argv ) > 2 else "CSV"
8
+ res = query (sys .argv [1 ], output_format )
9
+ if output_format .lower () == 'dataframe' :
10
+ temp = res
11
+ else :
12
+ temp = res .data ()
13
+ print (temp , end = "" )
14
+
15
+ if __name__ == '__main__' :
16
+ main ()
Original file line number Diff line number Diff line change @@ -24,3 +24,5 @@ python3 -c \
24
24
python3 -c \
25
25
" import chdb; res = chdb.query('select version()', 'CSV'); print(str(res.get_memview().tobytes()))"
26
26
27
+ # test cli
28
+ python3 -m chdb " select 1112222222,555" Dataframe
Original file line number Diff line number Diff line change @@ -155,6 +155,7 @@ def build_extensions(self):
155
155
exclude_package_data = {'' : ['*.pyc' , 'src/**' ]},
156
156
ext_modules = ext_modules ,
157
157
python_requires = '>=3.7' ,
158
+ install_requires = ['pyarrow' , 'pandas' ],
158
159
cmdclass = {'build_ext' : BuildExt },
159
160
test_suite = "tests" ,
160
161
zip_safe = False ,
You can’t perform that action at this time.
0 commit comments