diff --git a/examples/groonga_microblog_tutorial/3_search_error_with_pyarrow.py b/examples/groonga_microblog_tutorial/3_search_error_with_pyarrow.py new file mode 100644 index 0000000..d635479 --- /dev/null +++ b/examples/groonga_microblog_tutorial/3_search_error_with_pyarrow.py @@ -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", +) diff --git a/poyonga/result.py b/poyonga/result.py index 27af98d..3087285 100644 --- a/poyonga/result.py +++ b/poyonga/result.py @@ -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) @@ -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]