Class: Sequel::ReadyMaker::FileSourcerer

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/extensions/make_readyable.rb

Overview

FileSourcerer

Handles external file sources for the make_ready functionality. This class creates temporary views that read from external files like Parquet, ORC, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, schema) ⇒ FileSourcerer

Creates a new FileSourcerer instance.

Parameters:

  • db (Sequel::Database)

    the database instance

  • schema (Pathname)

    the file path



150
151
152
153
# File 'lib/sequel/extensions/make_readyable.rb', line 150

def initialize(db, schema)
  @db = db
  @schema = schema
end

Instance Attribute Details

#dbSequel::Database (readonly)

Returns the database instance.

Returns:

  • (Sequel::Database)

    the database instance



144
145
146
# File 'lib/sequel/extensions/make_readyable.rb', line 144

def db
  @db
end

#schemaObject (readonly)

Returns the value of attribute schema.



144
# File 'lib/sequel/extensions/make_readyable.rb', line 144

attr_reader :db, :schema

Instance Method Details

#create_view(table, opts = {}) ⇒ Object

Creates a temporary view that reads from the external file.

Parameters:

  • table (Symbol)

    the table/view name

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

    additional options to merge



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/sequel/extensions/make_readyable.rb', line 167

def create_view(table, opts = {})
  case db.database_type
  when :spark
    # Spark SQL uses USING clause for external tables
    db.create_view(table, {
      temp: true,
      using: format,
      options: { path: schema.expand_path },
    }.merge(opts))
  when :duckdb
    # DuckDB uses direct file reading with read_* functions
    create_duckdb_view(table, opts)
  else
    raise Sequel::Error, "External file sources are not supported on #{db.database_type}"
  end
end

#tables(_opts = {}) ⇒ Array<Symbol>

Returns the table name derived from the file name.

Parameters:

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

    unused options parameter

Returns:

  • (Array<Symbol>)

    array containing the table name



159
160
161
# File 'lib/sequel/extensions/make_readyable.rb', line 159

def tables(_opts = {})
  [schema.basename(schema.extname).to_s.to_sym]
end