altertable-lakehouse 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +2 -1
- data/lib/altertable/lakehouse/adapters.rb +30 -17
- data/lib/altertable/lakehouse/client.rb +76 -35
- data/lib/altertable/lakehouse/version.rb +1 -1
- data/rbi/altertable/lakehouse.rbi +38 -2
- data/rbi/todo.rbi +2 -0
- data/sig/altertable/lakehouse/adapters.rbs +1 -0
- data/sig/altertable/lakehouse/client.rbs +18 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc216c58c6d19bb15aff580cda0bdc95254b6aa9995e4d6c5480876314e11665
|
|
4
|
+
data.tar.gz: 838bc09df3b5ffb6d60f28a73576fe1005b838c126be899a1e5e071e44713f84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d83c2091e31e688f2eb3ab338170fc991f432e883a88b8c7b6d1f655a699240abbddf83439decf2869c65f60dc39e8d4406f7b963504002d779c3b5b01f7bed1
|
|
7
|
+
data.tar.gz: a8cf6157ad97f10e46875adeccc79165c8b032c27825627d2da29352bce5dfd0948e90050223922f34f07d51ed0bd63ba248e4b5a92ac8ed0bca6611a93a2c6c
|
data/CHANGELOG.md
CHANGED
|
@@ -13,13 +13,23 @@ All notable changes to this project will be documented in this file.
|
|
|
13
13
|
### Changed
|
|
14
14
|
|
|
15
15
|
* Require Ruby 3.2 or newer (`ColumnDescriptor` is a `Data` class). CI already only tested 3.2+.
|
|
16
|
+
* `query` streams its result: rows are parsed and yielded as `/query` chunks arrive, instead of after the whole body is held in memory. This works with the Faraday, HTTPX and Net::HTTP adapters.
|
|
17
|
+
* A malformed `/query` NDJSON line now raises `ParseError` instead of being skipped.
|
|
16
18
|
|
|
17
19
|
### Fixed
|
|
18
20
|
|
|
19
21
|
* `QueryLogResponse#progress` is no longer always `nil`.
|
|
22
|
+
* `query` works with the HTTPX adapter. It raised `HTTPX::Error: invalid URI: /query` because the streamed request lost the client's base URL.
|
|
20
23
|
* `QueryResult#columns` and `query_all[:columns]` return typed column descriptors again instead of bare names; rows stay keyed by column name.
|
|
21
24
|
* A malformed `/query` column line (anything other than an array of `{ "name", "type" }` string objects) now raises `ParseError` instead of passing through untyped.
|
|
22
25
|
|
|
26
|
+
## [0.10.0](https://github.com/altertable-ai/altertable-lakehouse-ruby/compare/altertable-lakehouse/v0.9.1...altertable-lakehouse/v0.10.0) (2026-11-06)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* **query:** stream /query rows as chunks arrive ([#64](https://github.com/altertable-ai/altertable-lakehouse-ruby/issues/64)) ([493395e](https://github.com/altertable-ai/altertable-lakehouse-ruby/commit/493395e7577e766f24a42ba6f50d7c1b6d99957f))
|
|
32
|
+
|
|
23
33
|
## [0.9.1](https://github.com/altertable-ai/altertable-lakehouse-ruby/compare/altertable-lakehouse/v0.9.0...altertable-lakehouse/v0.9.1) (2026-11-03)
|
|
24
34
|
|
|
25
35
|
|
data/Gemfile.lock
CHANGED
|
@@ -56,7 +56,8 @@ module Altertable
|
|
|
56
56
|
req.params = params if params
|
|
57
57
|
req.headers = req.headers.merge(headers) unless headers.empty?
|
|
58
58
|
req.body = body
|
|
59
|
-
|
|
59
|
+
# Faraday 2 passes the env, whose status is set before the first chunk.
|
|
60
|
+
req.options.on_data = proc { |chunk, _received, env| block.call(chunk, env&.status) } if block_given?
|
|
60
61
|
end
|
|
61
62
|
wrap_response(resp)
|
|
62
63
|
rescue Faraday::ConnectionFailed => e
|
|
@@ -93,7 +94,7 @@ module Altertable
|
|
|
93
94
|
base_url: @base_url
|
|
94
95
|
}
|
|
95
96
|
http_options[:proxy] = options[:proxy] if options.key?(:proxy)
|
|
96
|
-
@client = HTTPX.plugin(:retries).with(**http_options)
|
|
97
|
+
@client = HTTPX.plugin(:retries).plugin(:stream).with(**http_options)
|
|
97
98
|
end
|
|
98
99
|
|
|
99
100
|
def get(path, body: nil, params: {}, headers: {}, &_block) # rubocop:disable Lint/UnusedMethodArgument
|
|
@@ -101,22 +102,10 @@ module Altertable
|
|
|
101
102
|
wrap_response(resp)
|
|
102
103
|
end
|
|
103
104
|
|
|
104
|
-
def post(path, body: nil, params: {}, headers: {}, &
|
|
105
|
+
def post(path, body: nil, params: {}, headers: {}, &)
|
|
105
106
|
client = @client.with(headers: headers)
|
|
106
107
|
if block_given?
|
|
107
|
-
|
|
108
|
-
# HTTPX response streaming:
|
|
109
|
-
response = client.request("POST", path, body: body, params: params, stream: true)
|
|
110
|
-
|
|
111
|
-
# Check for error immediately
|
|
112
|
-
if response.is_a?(HTTPX::ErrorResponse)
|
|
113
|
-
raise Altertable::Lakehouse::NetworkError, response.error.message
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
response.body.each do |chunk|
|
|
117
|
-
block.call(chunk, response.headers["content-length"])
|
|
118
|
-
end
|
|
119
|
-
wrap_response(response)
|
|
108
|
+
stream_post(client, path, body: body, params: params, &)
|
|
120
109
|
else
|
|
121
110
|
resp = client.post(path, body: body, params: params)
|
|
122
111
|
wrap_response(resp)
|
|
@@ -130,6 +119,30 @@ module Altertable
|
|
|
130
119
|
|
|
131
120
|
private
|
|
132
121
|
|
|
122
|
+
# Yields body chunks as they arrive instead of buffering the body.
|
|
123
|
+
def stream_post(client, path, body:, params:, &block)
|
|
124
|
+
# The stream plugin drops the base_url origin, so pass a full URL.
|
|
125
|
+
url = "#{@base_url.to_s.chomp('/')}#{path}"
|
|
126
|
+
# It also sets a 60s operation timeout, so restore the configured
|
|
127
|
+
# one. operation_timeout bounds each wait on the socket (a late
|
|
128
|
+
# response or a stalled stream), like Net::HTTP's read_timeout. The
|
|
129
|
+
# plugin's infinite read_timeout stays: on a stream it would cap the
|
|
130
|
+
# whole response.
|
|
131
|
+
timeout = { operation_timeout: @timeout, connect_timeout: @open_timeout }
|
|
132
|
+
response = client.request("POST", url, body: body, params: params, stream: true, timeout: timeout)
|
|
133
|
+
begin
|
|
134
|
+
response.each { |chunk| block.call(chunk, response.status) }
|
|
135
|
+
rescue HTTPX::HTTPError => e
|
|
136
|
+
# Raised once a 4xx/5xx body has been streamed to the block.
|
|
137
|
+
return Response.new(e.response.status, nil, e.response.headers)
|
|
138
|
+
rescue HTTPX::TimeoutError => e
|
|
139
|
+
raise Altertable::Lakehouse::TimeoutError, e.message
|
|
140
|
+
rescue HTTPX::Error => e
|
|
141
|
+
raise Altertable::Lakehouse::NetworkError, e.message
|
|
142
|
+
end
|
|
143
|
+
Response.new(response.status, nil, response.headers)
|
|
144
|
+
end
|
|
145
|
+
|
|
133
146
|
def wrap_response(resp)
|
|
134
147
|
if resp.is_a?(HTTPX::ErrorResponse)
|
|
135
148
|
raise Altertable::Lakehouse::NetworkError, resp.error.message
|
|
@@ -178,7 +191,7 @@ module Altertable
|
|
|
178
191
|
# Stream the body if block is given
|
|
179
192
|
if response.is_a?(Net::HTTPSuccess)
|
|
180
193
|
response.read_body do |chunk|
|
|
181
|
-
block.call(chunk, response.
|
|
194
|
+
block.call(chunk, response.code.to_i)
|
|
182
195
|
end
|
|
183
196
|
end
|
|
184
197
|
# Return wrapped response (body might be empty if consumed?)
|
|
@@ -63,14 +63,15 @@ module Altertable
|
|
|
63
63
|
req_body = Models::QueryRequest.new(statement: statement, **).to_h.to_json
|
|
64
64
|
|
|
65
65
|
enum = Enumerator.new do |yielder|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
#
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
stream = NdjsonStream.new { |value| yielder << value }
|
|
67
|
+
|
|
68
|
+
# The adapter yields each body chunk with the response status (when
|
|
69
|
+
# it knows it), so rows reach the caller as they arrive.
|
|
70
|
+
resp = @adapter.post("/query", body: req_body, headers: json_headers(headers)) do |chunk, status|
|
|
71
|
+
stream.write(chunk, status)
|
|
71
72
|
end
|
|
72
73
|
|
|
73
|
-
handle_stream_response(resp,
|
|
74
|
+
handle_stream_response(resp, stream)
|
|
74
75
|
end
|
|
75
76
|
|
|
76
77
|
QueryResult.new(enum)
|
|
@@ -219,43 +220,27 @@ module Altertable
|
|
|
219
220
|
end
|
|
220
221
|
end
|
|
221
222
|
|
|
222
|
-
def handle_stream_response(resp,
|
|
223
|
+
def handle_stream_response(resp, stream)
|
|
223
224
|
case resp.status
|
|
225
|
+
when 200..299
|
|
226
|
+
stream.finish
|
|
224
227
|
when 400
|
|
225
|
-
raise BadRequestError, "Bad Request: #{
|
|
228
|
+
raise BadRequestError, "Bad Request: #{stream_error_body(resp, stream)}"
|
|
226
229
|
when 401
|
|
227
230
|
raise AuthError, "Unauthorized"
|
|
228
|
-
when 200..299
|
|
229
|
-
# Parse the accumulated NDJSON buffer line by line
|
|
230
|
-
# Buffer might be partial?
|
|
231
|
-
# In streaming, the block is called.
|
|
232
|
-
# Here we are processing after the stream is done?
|
|
233
|
-
# Wait, QueryResult expects the stream to be processed as it comes?
|
|
234
|
-
# The previous implementation used an Enumerator that yielded as data came in.
|
|
235
|
-
# Here, @adapter.post blocks until done?
|
|
236
|
-
# If @adapter.post blocks, we only get the buffer at the end.
|
|
237
|
-
# To stream truly, @adapter.post needs to yield to the block, which yields to yielder?
|
|
238
|
-
|
|
239
|
-
# Re-implementing streaming logic:
|
|
240
|
-
# The enumerator in `query` wraps the call.
|
|
241
|
-
# When `query` returns QueryResult, it hasn't run the request yet.
|
|
242
|
-
# Enumerator logic is inside.
|
|
243
|
-
|
|
244
|
-
buffer.each_line do |line|
|
|
245
|
-
line = line.strip
|
|
246
|
-
next if line.empty?
|
|
247
|
-
begin
|
|
248
|
-
yielder << JSON.parse(line)
|
|
249
|
-
rescue JSON::ParserError
|
|
250
|
-
# Partial line?
|
|
251
|
-
# For now assume full lines or handle buffering properly
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
231
|
else
|
|
255
|
-
raise ApiError, "API Error #{resp.status}: #{
|
|
232
|
+
raise ApiError, "API Error #{resp.status}: #{stream_error_body(resp, stream)}"
|
|
256
233
|
end
|
|
257
234
|
end
|
|
258
235
|
|
|
236
|
+
# Adapters stream error bodies to the block too, except Net::HTTP, which
|
|
237
|
+
# returns them in the response.
|
|
238
|
+
def stream_error_body(resp, stream)
|
|
239
|
+
body = stream.body
|
|
240
|
+
body = resp.body.to_s if body.empty?
|
|
241
|
+
body.strip
|
|
242
|
+
end
|
|
243
|
+
|
|
259
244
|
def handle_response(resp)
|
|
260
245
|
case resp.status
|
|
261
246
|
when 200..299
|
|
@@ -278,6 +263,62 @@ module Altertable
|
|
|
278
263
|
end
|
|
279
264
|
end
|
|
280
265
|
|
|
266
|
+
# Splits a /query NDJSON body into JSON values as chunks arrive, carrying a
|
|
267
|
+
# partial trailing line over to the next chunk. Until a chunk comes with a
|
|
268
|
+
# 2xx status, the body is only buffered: it may be an error message, or the
|
|
269
|
+
# adapter may not know the status before the response ends.
|
|
270
|
+
class NdjsonStream
|
|
271
|
+
def initialize(&on_value)
|
|
272
|
+
@on_value = on_value
|
|
273
|
+
@buffer = String.new(encoding: Encoding::BINARY)
|
|
274
|
+
@streaming = false
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def write(chunk, status)
|
|
278
|
+
@buffer << chunk.b
|
|
279
|
+
@streaming ||= !status.nil? && (200..299).cover?(status)
|
|
280
|
+
emit_complete_lines if @streaming
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Emits whatever is left once the response ended with a 2xx status.
|
|
284
|
+
def finish
|
|
285
|
+
emit_complete_lines
|
|
286
|
+
emit(@buffer)
|
|
287
|
+
@buffer = String.new(encoding: Encoding::BINARY)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# The buffered, not yet emitted body.
|
|
291
|
+
def body
|
|
292
|
+
@buffer.dup.force_encoding(Encoding::UTF_8)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
private
|
|
296
|
+
|
|
297
|
+
def emit_complete_lines
|
|
298
|
+
last_newline = @buffer.rindex("\n")
|
|
299
|
+
return unless last_newline
|
|
300
|
+
|
|
301
|
+
complete = @buffer.byteslice(0..last_newline)
|
|
302
|
+
@buffer = @buffer.byteslice((last_newline + 1)..)
|
|
303
|
+
complete.each_line { |line| emit(line) }
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def emit(line)
|
|
307
|
+
line = line.dup.force_encoding(Encoding::UTF_8).strip
|
|
308
|
+
return if line.empty?
|
|
309
|
+
|
|
310
|
+
@on_value.call(JSON.parse(line))
|
|
311
|
+
rescue JSON::ParserError => e
|
|
312
|
+
raise ParseError.new(
|
|
313
|
+
"Malformed /query line: #{e.message}",
|
|
314
|
+
operation: "query",
|
|
315
|
+
http_method: "POST",
|
|
316
|
+
http_path: "/query",
|
|
317
|
+
cause: e
|
|
318
|
+
)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
281
322
|
ColumnDescriptor = Data.define(:name, :type)
|
|
282
323
|
|
|
283
324
|
class QueryResult
|
|
@@ -197,13 +197,38 @@ module Altertable
|
|
|
197
197
|
end
|
|
198
198
|
def request(method, path, body: nil, query: nil, headers: {}); end
|
|
199
199
|
|
|
200
|
-
sig { params(resp: ::Altertable::Lakehouse::Adapters::Response,
|
|
201
|
-
def handle_stream_response(resp,
|
|
200
|
+
sig { params(resp: ::Altertable::Lakehouse::Adapters::Response, stream: ::Altertable::Lakehouse::NdjsonStream).void }
|
|
201
|
+
def handle_stream_response(resp, stream); end
|
|
202
|
+
|
|
203
|
+
sig { params(resp: ::Altertable::Lakehouse::Adapters::Response, stream: ::Altertable::Lakehouse::NdjsonStream).returns(String) }
|
|
204
|
+
def stream_error_body(resp, stream); end
|
|
202
205
|
|
|
203
206
|
sig { params(resp: ::Altertable::Lakehouse::Adapters::Response).returns(T.untyped) }
|
|
204
207
|
def handle_response(resp); end
|
|
205
208
|
end
|
|
206
209
|
|
|
210
|
+
class NdjsonStream
|
|
211
|
+
sig { params(on_value: T.proc.params(value: T.untyped).void).void }
|
|
212
|
+
def initialize(&on_value); end
|
|
213
|
+
|
|
214
|
+
sig { params(chunk: String, status: T.nilable(Integer)).void }
|
|
215
|
+
def write(chunk, status); end
|
|
216
|
+
|
|
217
|
+
sig { void }
|
|
218
|
+
def finish; end
|
|
219
|
+
|
|
220
|
+
sig { returns(String) }
|
|
221
|
+
def body; end
|
|
222
|
+
|
|
223
|
+
private
|
|
224
|
+
|
|
225
|
+
sig { void }
|
|
226
|
+
def emit_complete_lines; end
|
|
227
|
+
|
|
228
|
+
sig { params(line: String).void }
|
|
229
|
+
def emit(line); end
|
|
230
|
+
end
|
|
231
|
+
|
|
207
232
|
class ColumnDescriptor < Data
|
|
208
233
|
sig { returns(String) }
|
|
209
234
|
def name; end
|
|
@@ -858,6 +883,17 @@ module Altertable
|
|
|
858
883
|
|
|
859
884
|
private
|
|
860
885
|
|
|
886
|
+
sig do
|
|
887
|
+
params(
|
|
888
|
+
client: T.untyped,
|
|
889
|
+
path: String,
|
|
890
|
+
body: T.nilable(String),
|
|
891
|
+
params: T::Hash[T.any(Symbol, String), T.untyped],
|
|
892
|
+
block: T.proc.params(arg0: String, arg1: Integer).void
|
|
893
|
+
).returns(::Altertable::Lakehouse::Adapters::Response)
|
|
894
|
+
end
|
|
895
|
+
def stream_post(client, path, body:, params:, &block); end
|
|
896
|
+
|
|
861
897
|
sig { params(resp: T.untyped).returns(::Altertable::Lakehouse::Adapters::Response) }
|
|
862
898
|
def wrap_response(resp); end
|
|
863
899
|
end
|
data/rbi/todo.rbi
CHANGED
|
@@ -99,10 +99,27 @@ module Altertable
|
|
|
99
99
|
?query: ::Hash[Symbol | String, untyped]?,
|
|
100
100
|
?headers: ::Hash[String, String]
|
|
101
101
|
) -> untyped
|
|
102
|
-
def handle_stream_response: (Adapters::Response resp,
|
|
102
|
+
def handle_stream_response: (Adapters::Response resp, NdjsonStream stream) -> void
|
|
103
|
+
def stream_error_body: (Adapters::Response resp, NdjsonStream stream) -> String
|
|
103
104
|
def handle_response: (Adapters::Response resp) -> untyped
|
|
104
105
|
end
|
|
105
106
|
|
|
107
|
+
class NdjsonStream
|
|
108
|
+
@on_value: ^(untyped value) -> void
|
|
109
|
+
@buffer: String
|
|
110
|
+
@streaming: bool
|
|
111
|
+
|
|
112
|
+
def initialize: () { (untyped value) -> void } -> void
|
|
113
|
+
def write: (String chunk, Integer? status) -> void
|
|
114
|
+
def finish: () -> void
|
|
115
|
+
def body: () -> String
|
|
116
|
+
|
|
117
|
+
private
|
|
118
|
+
|
|
119
|
+
def emit_complete_lines: () -> void
|
|
120
|
+
def emit: (String line) -> void
|
|
121
|
+
end
|
|
122
|
+
|
|
106
123
|
class ColumnDescriptor < ::Data
|
|
107
124
|
attr_reader name: String
|
|
108
125
|
attr_reader type: String
|