Can `ResumableParser` return whether the last `partial_value` container is completed or not?
还没有人认领这个 Issue。
评估
调研方向
首先复现 issue 中的两个 JSON::ResumableParser 分块示例,并检查 parse 后 partial_value 是如何填充的。跟踪最后一条记录已完成与未完成时的解析器状态;当调用方能够可靠地区分这两种情况(包括所描述的 workaround 场景)时,即可完成。
由索引模型根据 Issue 内容生成。
描述
This is not a critical feature request.
I'm trying to migrate to json gem from json-stream gem in https://github.com/groonga/groonga-command-parser/ by JSON::ResumableParser.
It parses records to be loaded to Groonga (a full text search engine with column store). The records use the following format:
[
{"column_name1": "record1's column_value1", "column_name2": 2, ...},
{"column_name1": "record2's column_value1", "column_name2": 2, ...},
...
]
groonga-command-parser wants to process a record as soon as it's completed. For example, it wants to process the first record when the following chunk is processed:
[
{"column_name1": "record1's column_value1", "column_name2": 2, ...},
We can do it by the following script:
require "json"
parser = JSON::ResumableParser.new
parser << <<-CHUNK
[
{"column1": "value1"},
CHUNK
parser.parse
p parser.partial_value[0] # => {"column1" => "value1"}
But it doesn't work with the following chunk:
[
{"column_name1": "record1's column_value1",
We can't know whether the record is completed or not:
require "json"
parser = JSON::ResumableParser.new
parser << <<-CHUNK
[
{"column1": "value1",
CHUNK
parser.parse
p parser.partial_value[0] # => {"column1" => "value1"} # This is not completed yet
groonga-command-parser has a workaround for it. It ignores the last record:
require "json"
parser = JSON::ResumableParser.new
parser << <<-CHUNK
[
{"column1": "value1"},
CHUNK
parser.parse
p parser.partial_value[0..-2] # => []
parser << <<-CHUNK
{"column1": "value2"},
CHUNK
parser.parse
p parser.partial_value[0..-2] # => [{"column1" => "value1"}] # 1st record
If we can detect whether a record in this example is completed or not, it's useful. But this is not a critical feature request because there is a workaround for this case.
- 主要语言
- Ruby
- 星标
- 782
- 派生
- 383
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 10
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/json 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 38/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
Output formatting differences between jRuby 10.0.0.1 and Ruby 3.4 when converting Float to JSON. 未关闭jruby
-
jruby
-
new feature
难度 5/5 一周以上 新手友好度 25/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
TheOdinProject/curriculum#31417 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 65/100
glossarist/glossarist-ruby#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
palladius/rails8-app-on-gcp#145 ·