You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Red Remote Input downloads the data automatically if it's not cached,
and closes the input upon exiting the block:
RemoteInput.open(url)do |input|
input.readend
By default, url (host + path) is converted to a directory
safe path in the system cache path.
For example, https://example.com/sample/data.csv is converted to /system cache path/example.com-sample/data.csv.
But how about disabling cache when a user doesn't specify cache ID explicitly? Or how about specifying cache_path instead of cache_id:
RemoteInput.open("https://example.com/sample/data.csv",cache_path: "example/sub-directory/data.csv")do |input|
input.local_path# => "/system cache path/example/sub-directory/data.csv" # "example" is cache ID and "sub-directory/data.csv" is path in the cacheend
We can use the following API for streaming:
remote_input.open(...)do |input|
loopdochunk=input.read(4096)breakifchunk.nil?# Use chunkendend
We may provide #each_chunk:
remote_input.open(...)do |input|
input.each_chunkdo |chunk|
# Use chunkendend
But how about disabling cache when a user doesn't specify cache ID explicitly? Or how about specifying cache_path instead of cache_id:
A user may not want to cache data, so we can disable cache by doesn't
specify cache_path explicitly:
RemoteInput.open("https://example.com/sample/data.csv")do |input|
input.local_path# => nil or /Tmpdir path/data.csvend
A user can also specify a cache path:
RemoteInput.open("https://example.com/sample/data.csv",cache_path: "example/sub-directory/data.csv")do |input|
input.local_path# => "/system cache path/example/sub-directory/data.csv" # "example" is cache ID and "sub-directory/data.csv" is path in the cacheend
#each_chunk is sounds nice. Thanks for your suggestion.
I will open the following pull requests one by one in this order for easier to review:
Add RemoteInput.open without cache
Add RemoteInput.open with cache (the cache_path: option)
Add RemoteInput::Input#clear_cache
Add RemoteInput::Input#each_chunk
Update README for the new API
Prepare for the 0.1.0 release
Note that RemoteInput::Input.new, not RemoteInput.new, because RemoteInput is a module not a class.
For now, the class name is RemoteInput::Input. I know Input is repeated, but I couldn't think of a better name.
After the 0.1.0 release, I would like to migrate Red Datasets to this API step by step.
We can add to_path but CSV.open isn't suitable API for RemoteInput. CSV.open opens an input but RemoteInput is already an input. CSV.new is for an opened input. So CSV.new(remote_input) not CSV.open(remote_input) is preferred API for RemoteInput.
$ ruby -Ilib test.rb/Users/tikkss/.rbenv/versions/ruby-dev/lib/ruby/gems/4.1.0+4/gems/csv-3.3.6/lib/csv/parser.rb:323:in 'CSV::Parser::InputsScanner#read_chunk': private method 'gets' called for an instance of RemoteInput (NoMethodError) chunk = input.gets(@row_separator, @chunk_size) ^^^^^ from /Users/tikkss/.rbenv/versions/ruby-dev/lib/ruby/gems/4.1.0+4/gems/csv-3.3.6/lib/csv/parser.rb:107:in 'CSV::Parser::InputsScanner#initialize' from /Users/tikkss/.rbenv/versions/ruby-dev/lib/ruby/gems/4.1.0+4/gems/csv-3.3.6/lib/csv/parser.rb:908:in 'CSV::Parser#build_scanner' from /Users/tikkss/.rbenv/versions/ruby-dev/lib/ruby/gems/4.1.0+4/gems/csv-3.3.6/lib/csv/parser.rb:424:in 'CSV::Parser#parse' from /Users/tikkss/.rbenv/versions/ruby-dev/lib/ruby/gems/4.1.0+4/gems/csv-3.3.6/lib/csv.rb:2677:in 'CSV#each' from test.rb:6:in 'Enumerable#first' from test.rb:6:in 'block in <main>' from /Users/tikkss/src/github.com/red-data-tools/red-remote-input/lib/remote_input.rb:12:in 'RemoteInput.open' from test.rb:4:in '<main>'
Activity
tikkss commentedon Nov 3, 2025
How about the following new API?
Red Remote Inputdownloads the data automatically if it's not cached,and closes the input upon exiting the block:
By default,
url(host + path) is converted to a directorysafe path in the system cache path.
For example,
https://example.com/sample/data.csvis converted to/system cache path/example.com-sample/data.csv.You can also specify a custom cache path:
You can also use
RemoteInputwithout a block:You can also clear the cache:
Work in progress... for streaming data such as big data:
kou commentedon Nov 3, 2025
Thanks. Let's try the API.
But how about disabling cache when a user doesn't specify cache ID explicitly? Or how about specifying
cache_pathinstead ofcache_id:We can use the following API for streaming:
We may provide
#each_chunk:tikkss commentedon Nov 10, 2025
Thanks for your reply.
A user may not want to cache data, so we can disable cache by doesn't
specify
cache_pathexplicitly:A user can also specify a cache path:
#each_chunkis sounds nice. Thanks for your suggestion.I'll try to implement the new API.
tikkss commentedon Aug 29, 2026
I will open the following pull requests one by one in this order for easier to review:
RemoteInput.openwithout cacheRemoteInput.openwith cache (thecache_path:option)RemoteInput::Input#clear_cacheRemoteInput::Input#each_chunkNote that
RemoteInput::Input.new, notRemoteInput.new, becauseRemoteInputis a module not a class.For now, the class name is
RemoteInput::Input. I knowInputis repeated, but I couldn't think of a better name.After the 0.1.0 release, I would like to migrate Red Datasets to this API step by step.
Add RemoteInput.open (#24)
tikkss commentedon Sep 29, 2026
I've updated the plan as is (1 is done):
RemoteInput.openwith cache (not without)RemoteInput::Input#clear_cacheRemoteInput.openwith cache (thecache_path:option)RemoteInput::Input#each_chunk#patha public API (that downloads the data lazily)I'll work on 2.
Add cache_path: option to RemoteInput.open (#29)
Add RemoteInput#each_chunk (#31)
tikkss commentedon Nov 2, 2026
I want to pass a
RemoteInputobject toCSV.opendirectly.Steps to reproduce (with GH-36):
Expected:
["5.1", "3.5", "1.4", "0.2", "Iris-setosa"]Actual:
.../csv-3.3.6/lib/csv.rb:1668:in 'File#initialize': no implicit conversion of RemoteInput into String (TypeError)Cause:
CSV.openpasses the given object toFile.open: https://github.com/ruby/csv/blob/v3.3.6/lib/csv.rb#L1668File.openaccepts aStringor an object that has#to_path.RemoteInputhas neither.Workaround:
We can use
RemoteInput#pathfor this:Proposal:
How about adding
RemoteInput#to_path?Then we can pass a
RemoteInputobject toCSV.open,File.openand so on directly:kou commentedon Nov 4, 2026
We can add
to_pathbutCSV.openisn't suitable API forRemoteInput.CSV.openopens an input butRemoteInputis already an input.CSV.newis for an opened input. SoCSV.new(remote_input)notCSV.open(remote_input)is preferred API forRemoteInput.Make RemoteInput#path public (#36)
tikkss commentedon Nov 6, 2026
I see.
CSV.newis better forRemoteInput.How about adding
RemoteInput#getsinstead ofRemoteInput#to_path? It's the same asIO#getslikeRemoteInput#read.Because
CSV#eachreads an input byIO#gets:https://github.com/ruby/csv/blob/afbee5e3548d38914706ae0de8a6cf421ba43187/lib/csv/parser.rb#L323 .
So we can't read a
RemoteInputobject byCSVfor now:It works when I add
RemoteInput#gets.kou commentedon Nov 8, 2026
We can add both of
#getsand#to_path.tikkss commentedon Nov 8, 2026
Thanks! I'll open pull requests for them.
I found that we may also need the following methods to migrate red-datasets to red-remote-input:
#each_line#eof?#readline#seekI'll add them too.
Add RemoteInput#gets (#37)
Add RemoteInput#to_path (#38)
Add RemoteInput#each_line (#39)
Add RemoteInput#readline (#40)
Add RemoteInput#eof? (#42)
Add RemoteInput#seek (#43)