ducklake 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 451f6059faf0e7c451599b218bb9dafbbb8b80a2b54416833a5dafb85a0d1a9d
4
- data.tar.gz: a1c6c7825da3dd5a077705c1c3f106a0cc1d75bc2e60b17ccb5099f98a3bdf1a
3
+ metadata.gz: 9366806f0dee7b0277dfee65be6c4718c339b6e9ab53e595e1f88534d5144534
4
+ data.tar.gz: 3b3c01d575bb8d0c380b49cbbc8b6deb62cc7de5542449dc73d0fd3b5ccffb1f
5
5
  SHA512:
6
- metadata.gz: 9359cf3aaf06ed4398b9bc0ff35489c0e50008cd8d3426a787339d33f541a6bce8e3a1eca4a2b88b46852545895b591d08613f88ad26902aa4d41cf8b842bc93
7
- data.tar.gz: 5bd9818d1b928aa2c0a11301c3455b89f8a4fc99912c6d1b8e52fdd151088adcc331b0ca01169df08412e151841f2f6b50f4c7b85b909ca558d6c21f0ffebd56
6
+ metadata.gz: 2e1fb28d47b8efeedaedba54727d678bdf946efd6aac1001ae0a2ad9aa9fbdc5b28bf8df06b2a10be13f6684195e2f684eafe71c7bedb27b36eff7af36d65abf
7
+ data.tar.gz: 4feea1505445b4347e722ea31d87c6dd9ed759489550f7a69997fced7b9a45827b4beaa81c4bc5e12abb801226af82f1c4903aff5ab6fd4b0851b6772b2c83c3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.2 (2025-08-23)
2
+
3
+ - Added `transaction` method
4
+
1
5
  ## 0.1.1 (2025-08-18)
2
6
 
3
7
  - Added experimental support for Polars
data/README.md CHANGED
@@ -163,12 +163,46 @@ Delete data
163
163
  ducklake.sql("DELETE * FROM events WHERE id = ?", [1])
164
164
  ```
165
165
 
166
+ Run multiple statements in a transaction
167
+
168
+ ```ruby
169
+ ducklake.transaction do
170
+ # ...
171
+ end
172
+ ```
173
+
174
+ Raise `DuckLake::Rollback` to rollback
175
+
176
+ ## Schema Changes
177
+
166
178
  Update the schema
167
179
 
168
180
  ```ruby
169
181
  ducklake.sql("ALTER TABLE events ADD COLUMN active BOOLEAN")
170
182
  ```
171
183
 
184
+ Set or remove a [partitioning key](https://ducklake.select/docs/stable/duckdb/advanced_features/partitioning)
185
+
186
+ ```ruby
187
+ ducklake.sql("ALTER TABLE events SET PARTITIONED BY (name)")
188
+ # or
189
+ ducklake.sql("ALTER TABLE events RESET PARTITIONED BY")
190
+ ```
191
+
192
+ ## Views
193
+
194
+ Create a view
195
+
196
+ ```ruby
197
+ ducklake.sql("CREATE VIEW events_view AS SELECT * FROM events")
198
+ ```
199
+
200
+ Drop a view
201
+
202
+ ```ruby
203
+ ducklake.sql("DROP VIEW events_view")
204
+ ```
205
+
172
206
  ## Snapshots
173
207
 
174
208
  Get snapshots
@@ -235,9 +269,9 @@ ducklake.set_option("parquet_compression", "zstd", table_name: "events")
235
269
 
236
270
  ## Read-Only Mode
237
271
 
238
- Note: This feature is experimental
272
+ Note: This feature is experimental and does not prevent the DuckDB engine from writing files via `sql`
239
273
 
240
- Connect to the data lake in read-only mode
274
+ Attach the catalog in read-only mode
241
275
 
242
276
  ```ruby
243
277
  DuckLake::Client.new(read_only: true, ...)
@@ -294,7 +328,7 @@ ducklake.sql("COPY #{quoted_table} FROM #{quoted_file}")
294
328
 
295
329
  ## Polars
296
330
 
297
- Note: This feature is experimental and does not work on tables with schema changes
331
+ Note: This feature is experimental and does not currently work on tables with schema changes
298
332
 
299
333
  Query the data with [Ruby Polars](https://github.com/ankane/ruby-polars)
300
334
 
@@ -106,6 +106,17 @@ module DuckLake
106
106
  execute(sql, params)
107
107
  end
108
108
 
109
+ def transaction
110
+ execute("BEGIN")
111
+ begin
112
+ yield
113
+ execute("COMMIT")
114
+ rescue => e
115
+ execute("ROLLBACK")
116
+ raise e unless e.is_a?(Rollback)
117
+ end
118
+ end
119
+
109
120
  def attach(alias_, url)
110
121
  type = nil
111
122
  extension = nil
@@ -151,6 +162,15 @@ module DuckLake
151
162
  symbolize_keys result
152
163
  end
153
164
 
165
+ # experimental
166
+ # TODO use keyword arguments or range?
167
+ def table_changes(table, start_snapshot, end_snapshot)
168
+ params = [@catalog, "main", table, start_snapshot, end_snapshot]
169
+ result = execute("SELECT * FROM ducklake_table_changes(?, ?, ?, ?, ?)", params)
170
+ # only return changes between snapshots
171
+ symbolize_keys result.reject { |v| v["snapshot_id"] == start_snapshot }
172
+ end
173
+
154
174
  # TODO more DDL methods?
155
175
  def drop_table(table, if_exists: nil)
156
176
  execute("DROP TABLE#{" IF EXISTS" if if_exists} #{quote_identifier(table)}")
@@ -289,15 +309,26 @@ module DuckLake
289
309
  end
290
310
 
291
311
  # experimental
292
- # TODO support schema changes
293
312
  def polars(table, snapshot_version: nil, snapshot_time: nil)
294
313
  files = list_files(table, snapshot_version:, snapshot_time:)
295
314
  sources = files.map { |v| v[:data_file] }
315
+ # TODO support schema changes
316
+ # column_mapping = [
317
+ # "iceberg-column-mapping",
318
+ # nil
319
+ # ]
296
320
  deletion_files = [
297
321
  "iceberg-position-delete",
298
322
  files.map.with_index.select { |v, i| v[:delete_file] }.to_h { |v, i| [i, [v[:delete_file]]] }
299
323
  ]
300
- Polars.scan_parquet(sources, _deletion_files: deletion_files, storage_options: polars_storage_options)
324
+ Polars.scan_parquet(
325
+ sources,
326
+ storage_options: polars_storage_options,
327
+ # allow_missing_columns: true,
328
+ # extra_columns: "ignore",
329
+ # _column_mapping: column_mapping,
330
+ _deletion_files: deletion_files
331
+ )
301
332
  end
302
333
 
303
334
  # libduckdb does not provide function
@@ -370,7 +401,9 @@ module DuckLake
370
401
  "Conversion Error: " => ConversionError,
371
402
  "Invalid Input Error: " => InvalidInputError,
372
403
  "IO Error: " => IOError,
373
- "Permission Error: " => PermissionError
404
+ "Not implemented Error: " => NotImplementedError,
405
+ "Permission Error: " => PermissionError,
406
+ "TransactionContext Error: " => TransactionContextError
374
407
  }
375
408
  end
376
409
 
@@ -1,3 +1,3 @@
1
1
  module DuckLake
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/ducklake.rb CHANGED
@@ -15,5 +15,8 @@ module DuckLake
15
15
  class ConversionError < Error; end
16
16
  class InvalidInputError < Error; end
17
17
  class IOError < Error; end
18
+ class NotImplementedError < Error; end
18
19
  class PermissionError < Error; end
20
+ class Rollback < Error; end
21
+ class TransactionContextError < Error; end
19
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ducklake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane