Skip to content

Commit

Permalink
Tweak some code, add some docs, refs #14
Browse files Browse the repository at this point in the history
  • Loading branch information
aguynamedryan committed Feb 1, 2024
1 parent 76210f0 commit e209fa0
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/sequel/extensions/make_readyable.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
module Sequel
module MakeReadyable
##
# This method is primarily geared towards Spark SQL-based databases.
#
# Given some options, prepares a set of views to represent a set
# of tables across a collection of different schemas and external,
# unmanaged tables.
#
# DB.make_ready(use_schema: :schema)
# # => USE `schema`
#
# When using search_path, tables from previous schema override tables
# from the next schema. This is analogous to the way Unix searches
# the PATH variable for programs.
#
# Assuming the following tables: schema1.a, schema2.a, schema2.b
#
# DB.make_ready(search_path: [:schema1, :schema2])
# # => CREATE TEMPORARY VIEW `a` AS SELECT * FROM `schema1`.`a;`
# # => CREATE TEMPORARY VIEW `b` AS SELECT * FROM `schema2`.`b;`
#
# When using Pathnames, the extension on the file becomes the format
# to try to read from the file.
#
# DB.make_ready(search_path: [Pathname.new("c.parquet"), Pathname.new("d.orc")])
# # => CREATE TEMPORARY VIEW `c` USING parquet OPTIONS ('path'='c.parquet')
# # => CREATE TEMPORARY VIEW `d` USING orc OPTIONS ('path'='d.orc')
#
# @param [Hash] opts the options used to prepare the database
# @option opts [String] :use_schema The schema to be used as the primary schema
# @option opts [Array] :search_path A set of sympbols (to represent schemas) or Pathnames (to represent externally managed data files)
def make_ready(opts = {})
self.extension :usable
ReadyMaker.new(self, opts).run
end
end

private
class ReadyMaker
attr_reader :db, :opts

Expand All @@ -16,6 +46,7 @@ def initialize(db, opts)

def run
if opts[:use_schema]
db.extension :usable
db.use(opts[:use_schema])
end
only_tables = Array(opts[:only])
Expand Down

0 comments on commit e209fa0

Please sign in to comment.