Skip to content

Commit

Permalink
Merge pull request #24 from hhatto/imporve-result-with-apache-arrow
Browse files Browse the repository at this point in the history
improve select result with apache arrow output type
  • Loading branch information
hhatto committed Nov 3, 2023
2 parents 0a42863 + 68837cc commit 70ad206
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
33 changes: 33 additions & 0 deletions examples/groonga_microblog_tutorial/3_search_error_with_pyarrow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# coding: utf-8
from poyonga import Groonga


def _call_with_apachearrow(g, cmd, **kwargs):
print("[http with apache arrow response]")
ret = g.call(cmd, **kwargs)
print("status:", ret.status)
if cmd == "select":
print(type(ret.items))
if ret.items:
print("item:", len(ret.items))
for item in ret.items:
print(item)
else:
print(ret.body)
print("=*=" * 30)
else:
print(ret.body)


g = Groonga()

_call_with_apachearrow(
g,
"select",
table="Comment", # NOTE: invalid table name
filter="last_modified<=1268802000",
output_columns="posted_by.name,comment,last_modified",
output_type="apache-arrow",
drilldown="hash_tags,posted_by",
drilldown_output_column="_id",
)
12 changes: 8 additions & 4 deletions poyonga/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, data, output_type="json", encoding="utf-8", content_type=None
if output_type == "tsv" or content_type == "text/tab-separated-values":
# TODO: not implement
csv.reader(StringIO(data), delimiter="\t")
raise NotImplementedError(f"not implement output_type: {output_type}")
elif output_type == "msgpack" or content_type == "application/x-msgpack":
if msgpack:
_result = msgpack.unpackb(data)
Expand All @@ -37,12 +38,15 @@ def __init__(self, data, output_type="json", encoding="utf-8", content_type=None
_result = json.loads(data)
else:
_result = json.loads(data, encoding=encoding)
elif self._is_apache_arrow(content_type):
self._parse_apache_arrow(data)
return
elif output_type == "apache-arrow":
if self._is_apache_arrow(content_type):
self._parse_apache_arrow(data)
return
else:
raise Exception("groonga is not supported Apache Arrow output type")
else: # xml or other types...
# TODO: not implement
pass
raise NotImplementedError(f"not implement output_type: {output_type}")
self.status = _result[0][0]
self.start_time = _result[0][1]
self.elapsed = _result[0][2]
Expand Down

0 comments on commit 70ad206

Please sign in to comment.