Module: Sequel::MakeReadyable

Defined in:
lib/sequel/extensions/make_readyable.rb

Instance Method Summary collapse

Instance Method Details

#make_ready(opts = {}) ⇒ Object

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')

Parameters:

  • opts (Hash) (defaults to: {})

    the options used to prepare the database

Options Hash (opts):

  • :use_schema (String)

    The schema to be used as the primary schema

  • :search_path (Array)

    A set of sympbols (to represent schemas) or Pathnames (to represent externally managed data files)



33
34
35
# File 'lib/sequel/extensions/make_readyable.rb', line 33

def make_ready(opts = {})
  ReadyMaker.new(self, opts).run
end