Module: Sequel::Impala::DatabaseMethods
- Extended by:
- Database::ResetIdentifierMangling
- Included in:
- Database, JDBC::Hive2::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.
-
#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.
-
#implicit_qualify(table) ⇒ Object
Implicitly quailfy the table if using the :search_path option.
- #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
23 24 25 |
# File 'lib/sequel/adapters/shared/impala.rb', line 23 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.
10 11 12 13 14 15 16 17 |
# File 'lib/sequel/adapters/shared/impala.rb', line 10 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'
44 45 46 |
# File 'lib/sequel/adapters/shared/impala.rb', line 44 def create_schema(schema, =OPTS) run(create_schema_sql(schema, )) end |
#database_type ⇒ Object
Set the database_type for this database to :impala.
49 50 51 |
# File 'lib/sequel/adapters/shared/impala.rb', line 49 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`
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sequel/adapters/shared/impala.rb', line 66 def describe(table, opts=OPTS) if ds = opts[:dataset] ds = ds.naked else ds = dataset.clone ds.identifier_input_method = identifier_input_method end ds.identifier_output_method = nil 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`
89 90 91 |
# File 'lib/sequel/adapters/shared/impala.rb', line 89 def drop_schema(schema, =OPTS) run(drop_schema_sql(schema, )) 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.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/sequel/adapters/shared/impala.rb', line 98 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_table_schemas ⇒ Object
189 190 191 |
# File 'lib/sequel/adapters/shared/impala.rb', line 189 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`
141 142 143 |
# File 'lib/sequel/adapters/shared/impala.rb', line 141 def load_data(path, table, =OPTS) run(load_data_sql(path, table, )) end |
#refresh(table_name) ⇒ Object
19 20 21 |
# File 'lib/sequel/adapters/shared/impala.rb', line 19 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.
147 148 149 |
# File 'lib/sequel/adapters/shared/impala.rb', line 147 def {:type=>Integer} end |
#set(opts) ⇒ Object
Sets options in the current db connection for each key/value pair
206 207 208 209 210 |
# File 'lib/sequel/adapters/shared/impala.rb', line 206 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.
152 153 154 |
# File 'lib/sequel/adapters/shared/impala.rb', line 152 def supports_create_table_if_not_exists? true end |
#supports_foreign_key_parsing? ⇒ Boolean
Impala does not support foreign keys.
157 158 159 |
# File 'lib/sequel/adapters/shared/impala.rb', line 157 def supports_foreign_key_parsing? false end |
#supports_index_parsing? ⇒ Boolean
Impala does not support indexes.
162 163 164 |
# File 'lib/sequel/adapters/shared/impala.rb', line 162 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.
169 170 171 |
# File 'lib/sequel/adapters/shared/impala.rb', line 169 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.
177 178 179 180 181 |
# File 'lib/sequel/adapters/shared/impala.rb', line 177 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))
197 198 199 |
# File 'lib/sequel/adapters/shared/impala.rb', line 197 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.
185 186 187 |
# File 'lib/sequel/adapters/shared/impala.rb', line 185 def views(opts=OPTS) _tables(opts).reject{|t| is_valid_table?(t, opts)} end |