Module: Sequel::Impala::DatabaseMethods
- Includes:
- UnmodifiedIdentifiers::DatabaseMethods
- Included in:
- Database, JDBC::Hive2::DatabaseMethods, JDBC::Impala::DatabaseMethods, Rbhive::Database
- Defined in:
- lib/sequel/adapters/shared/impala.rb
Instance Method Summary collapse
- #compute_stats(table_name) ⇒ Object
-
#create_join_table(hash, options = OPTS) ⇒ Object
Do not use a composite primary key, foreign keys, or an index when creating a join table, as Impala doesn’t support those.
-
#create_schema(schema, options = OPTS) ⇒ Object
Create a database/schema in Imapala.
- #create_table(name, options = OPTS) ⇒ Object
-
#database_type ⇒ Object
Set the database_type for this database to :impala.
-
#describe(table, opts = OPTS) ⇒ Object
Return the DESCRIBE output for the table, showing table columns, types, and comments.
-
#drop_schema(schema, options = OPTS) ⇒ Object
Drop a database/schema from Imapala.
- #drop_table(*names) ⇒ Object
-
#implicit_qualify(table) ⇒ Object
Implicitly quailfy the table if using the :search_path option.
-
#invalidate_metadata(identifier = nil) ⇒ Object
Invalidate the metadata for the given table, or for all tables if no argument is given.
- #invalidate_table_schemas ⇒ Object
-
#load_data(path, table, options = OPTS) ⇒ Object
Load data from HDFS into Impala.
- #refresh(table_name) ⇒ Object
-
#serial_primary_key_options ⇒ Object
Don’t use PRIMARY KEY or AUTOINCREMENT on Impala, as Impala doesn’t support either.
-
#set(opts) ⇒ Object
Sets options in the current db connection for each key/value pair.
-
#supports_create_table_if_not_exists? ⇒ Boolean
Impala supports CREATE TABLE IF NOT EXISTS.
-
#supports_foreign_key_parsing? ⇒ Boolean
Impala does not support foreign keys.
-
#supports_index_parsing? ⇒ Boolean
Impala does not support indexes.
-
#tables(opts = OPTS) ⇒ Object
Check that the tables returned by the JDBC driver are actually valid tables and not views.
-
#transaction(opts = OPTS) ⇒ Object
Impala doesn’t support transactions, so instead of issuing a transaction, just checkout a connection.
-
#values(v) ⇒ Object
Creates a dataset that uses the VALUES clause:.
-
#views(opts = OPTS) ⇒ Object
Determine the available views for listing all tables via JDBC (which includes both tables and views), and removing all valid tables.
Instance Method Details
#compute_stats(table_name) ⇒ Object
25 26 27 |
# File 'lib/sequel/adapters/shared/impala.rb', line 25 def compute_stats(table_name) run(compute_stats_sql(table_name)) end |
#create_join_table(hash, options = OPTS) ⇒ Object
Do not use a composite primary key, foreign keys, or an index when creating a join table, as Impala doesn’t support those.
12 13 14 15 16 17 18 19 |
# File 'lib/sequel/adapters/shared/impala.rb', line 12 def create_join_table(hash, =OPTS) keys = hash.keys.sort_by(&:to_s) create_table(join_table_name(hash, ), ) do keys.each do |key| Integer key end end end |
#create_schema(schema, options = OPTS) ⇒ Object
Create a database/schema in Imapala.
Options:
- :if_not_exists
-
Don’t raise an error if the schema already exists.
- :location
-
Set the file system location to store the data for tables in the created schema.
Examples:
create_schema(:s)
# CREATE SCHEMA `s`
create_schema(:s, :if_not_exists=>true)
# CREATE SCHEMA IF NOT EXISTS `s`
create_schema(:s, :location=>'/a/b')
# CREATE SCHEMA `s` LOCATION '/a/b'
46 47 48 |
# File 'lib/sequel/adapters/shared/impala.rb', line 46 def create_schema(schema, =OPTS) run(create_schema_sql(schema, )) end |
#create_table(name, options = OPTS) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/sequel/adapters/shared/impala.rb', line 50 def create_table(name, =OPTS) super if im = [:invalidate_metadata] ((name unless im == :all)) end end |
#database_type ⇒ Object
Set the database_type for this database to :impala.
58 59 60 |
# File 'lib/sequel/adapters/shared/impala.rb', line 58 def database_type :impala end |
#describe(table, opts = OPTS) ⇒ Object
Return the DESCRIBE output for the table, showing table columns, types, and comments. If the :formatted option is given, use DESCRIBE FORMATTED and return a lot more information about the table. Both of these return arrays of hashes.
Examples:
describe(:t)
# DESCRIBE `t`
describe(:t, :formatted=>true)
# DESCRIBE FORMATTED `t`
75 76 77 78 79 80 81 82 |
# File 'lib/sequel/adapters/shared/impala.rb', line 75 def describe(table, opts=OPTS) if ds = opts[:dataset] ds = ds.naked else ds = dataset end ds.with_sql("DESCRIBE #{'FORMATTED ' if opts[:formatted]} ?", table).all end |
#drop_schema(schema, options = OPTS) ⇒ Object
Drop a database/schema from Imapala.
Options:
- :if_exists
-
Don’t raise an error if the schema doesn’t exist.
Examples:
drop_schema(:s)
# DROP SCHEMA `s`
create_schema(:s, :if_exists=>true)
# DROP SCHEMA IF EXISTS `s`
96 97 98 |
# File 'lib/sequel/adapters/shared/impala.rb', line 96 def drop_schema(schema, =OPTS) run(drop_schema_sql(schema, )) end |
#drop_table(*names) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/sequel/adapters/shared/impala.rb', line 100 def drop_table(*names) # CASCADE isn't a supported option in Impala if names.last.is_a?(Hash) names.last.delete(:cascade) end super end |
#implicit_qualify(table) ⇒ Object
Implicitly quailfy the table if using the :search_path option. This will look at all of the tables and views in the schemas, and if an unqualified table is used and appears in one of the schemas, it will be implicitly qualified with the given schema name.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/sequel/adapters/shared/impala.rb', line 113 def implicit_qualify(table) return table unless opts[:search_path] case table when Symbol s, t, a = Sequel.split_symbol(table) if s return table end t = implicit_qualify(t) a ? Sequel.as(t, a) : t when String if schema = search_path_table_schemas[table] Sequel.qualify(schema, table) else invalidate_table_schemas if schema = search_path_table_schemas[table] Sequel.qualify(schema, table) else Sequel.identifier(table) end end when SQL::Identifier implicit_qualify(table.value.to_s) when SQL::AliasedExpression SQL::AliasedExpression.new(implicit_qualify(table.expression), table.alias) else table end end |
#invalidate_metadata(identifier = nil) ⇒ Object
Invalidate the metadata for the given table, or for all tables if no argument is given.
146 147 148 |
# File 'lib/sequel/adapters/shared/impala.rb', line 146 def (identifier=nil) run("INVALIDATE METADATA #{quote_schema_table(identifier) if identifier}") end |
#invalidate_table_schemas ⇒ Object
218 219 220 |
# File 'lib/sequel/adapters/shared/impala.rb', line 218 def invalidate_table_schemas @search_path_table_schemas = nil end |
#load_data(path, table, options = OPTS) ⇒ Object
Load data from HDFS into Impala.
Options:
- :overwrite
-
Overwrite the existing table instead of appending to it.
Examples:
load_data('/user/foo', :bar)
LOAD DATA INPATH '/user/foo' INTO TABLE `bar`
load_data('/user/foo', :bar, :overwrite=>true)
LOAD DATA INPATH '/user/foo' OVERWRITE INTO TABLE `bar`
162 163 164 |
# File 'lib/sequel/adapters/shared/impala.rb', line 162 def load_data(path, table, =OPTS) run(load_data_sql(path, table, )) end |
#refresh(table_name) ⇒ Object
21 22 23 |
# File 'lib/sequel/adapters/shared/impala.rb', line 21 def refresh(table_name) run(refresh_sql(table_name)) end |
#serial_primary_key_options ⇒ Object
Don’t use PRIMARY KEY or AUTOINCREMENT on Impala, as Impala doesn’t support either.
168 169 170 |
# File 'lib/sequel/adapters/shared/impala.rb', line 168 def {:type=>Integer} end |
#set(opts) ⇒ Object
Sets options in the current db connection for each key/value pair
223 224 225 226 227 |
# File 'lib/sequel/adapters/shared/impala.rb', line 223 def set(opts) set_sql(opts).each do |sql| run(sql) end end |
#supports_create_table_if_not_exists? ⇒ Boolean
Impala supports CREATE TABLE IF NOT EXISTS.
173 174 175 |
# File 'lib/sequel/adapters/shared/impala.rb', line 173 def supports_create_table_if_not_exists? true end |
#supports_foreign_key_parsing? ⇒ Boolean
Impala does not support foreign keys.
178 179 180 |
# File 'lib/sequel/adapters/shared/impala.rb', line 178 def supports_foreign_key_parsing? false end |
#supports_index_parsing? ⇒ Boolean
Impala does not support indexes.
183 184 185 |
# File 'lib/sequel/adapters/shared/impala.rb', line 183 def supports_index_parsing? false end |
#tables(opts = OPTS) ⇒ Object
Check that the tables returned by the JDBC driver are actually valid tables and not views. The Hive2 JDBC driver returns views when listing tables and nothing when listing views.
190 191 192 |
# File 'lib/sequel/adapters/shared/impala.rb', line 190 def tables(opts=OPTS) _tables(opts).select{|t| is_valid_table?(t, opts)} end |
#transaction(opts = OPTS) ⇒ Object
Impala doesn’t support transactions, so instead of issuing a transaction, just checkout a connection. This ensures the same connection is used for the transaction block, but as Impala doesn’t support transactions, you can’t rollback.
198 199 200 201 202 |
# File 'lib/sequel/adapters/shared/impala.rb', line 198 def transaction(opts=OPTS) synchronize(opts[:server]) do |c| yield c end end |
#values(v) ⇒ Object
Creates a dataset that uses the VALUES clause:
DB.values([[1, 2], [3, 4]])
VALUES ((1, 2), (3, 4))
214 215 216 |
# File 'lib/sequel/adapters/shared/impala.rb', line 214 def values(v) @default_dataset.clone(:values=>v) end |
#views(opts = OPTS) ⇒ Object
Determine the available views for listing all tables via JDBC (which includes both tables and views), and removing all valid tables.
206 207 208 |
# File 'lib/sequel/adapters/shared/impala.rb', line 206 def views(opts=OPTS) _tables(opts).reject{|t| is_valid_table?(t, opts)} end |