Class: Iceberg::Catalog
- Inherits:
-
Object
- Object
- Iceberg::Catalog
- Defined in:
- lib/iceberg/catalog.rb
Direct Known Subclasses
Instance Method Summary collapse
- #create_namespace(namespace, properties: {}, if_not_exists: nil) ⇒ Object
- #create_table(table_name, schema: nil, location: nil) ⇒ Object
- #drop_namespace(namespace, if_exists: nil) ⇒ Object
- #drop_table(table_name, if_exists: nil) ⇒ Object
-
#inspect ⇒ Object
hide internal state.
- #list_namespaces(parent = nil) ⇒ Object
- #list_tables(namespace) ⇒ Object
- #load_table(table_name) ⇒ Object
- #namespace_exists?(namespace) ⇒ Boolean
- #namespace_properties(namespace) ⇒ Object
- #query(sql) ⇒ Object
- #register_table(table_name, metadata_location) ⇒ Object
- #rename_table(table_name, new_name) ⇒ Object
- #table_exists?(table_name) ⇒ Boolean
- #update_namespace(namespace, properties:) ⇒ Object
Instance Method Details
#create_namespace(namespace, properties: {}, if_not_exists: nil) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/iceberg/catalog.rb', line 7 def create_namespace(namespace, properties: {}, if_not_exists: nil) @catalog.create_namespace(namespace, properties) rescue Error => e if !if_not_exists || (e. != "Cannot create namespace" && !e..include?("already exists")) raise e end nil end |
#create_table(table_name, schema: nil, location: nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/iceberg/catalog.rb', line 41 def create_table(table_name, schema: nil, location: nil) if !schema.nil? && block_given? raise ArgumentError, "Must pass schema or block" end if block_given? table_definition = TableDefinition.new yield table_definition schema = Schema.new(table_definition.fields) elsif schema.is_a?(Hash) fields = schema.map.with_index do |(k, v), i| { id: i + 1, name: k.is_a?(Symbol) ? k.to_s : k, type: v, required: false } end schema = Schema.new(fields) elsif schema.nil? schema = Schema.new([]) end Table.new(@catalog.create_table(table_name, schema, location), @catalog) end |
#drop_namespace(namespace, if_exists: nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/iceberg/catalog.rb', line 28 def drop_namespace(namespace, if_exists: nil) @catalog.drop_namespace(namespace) rescue Error => e if !if_exists || (e. != "Tried to drop a namespace that does not exist" && !e..include?("No such namespace")) raise e end nil end |
#drop_table(table_name, if_exists: nil) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/iceberg/catalog.rb', line 72 def drop_table(table_name, if_exists: nil) @catalog.drop_table(table_name) rescue Error => e if !if_exists || (e. != "Tried to drop a table that does not exist" && !e..include?("No such table")) raise e end nil end |
#inspect ⇒ Object
hide internal state
103 104 105 |
# File 'lib/iceberg/catalog.rb', line 103 def inspect to_s end |
#list_namespaces(parent = nil) ⇒ Object
3 4 5 |
# File 'lib/iceberg/catalog.rb', line 3 def list_namespaces(parent = nil) @catalog.list_namespaces(parent) end |
#list_tables(namespace) ⇒ Object
37 38 39 |
# File 'lib/iceberg/catalog.rb', line 37 def list_tables(namespace) @catalog.list_tables(namespace) end |
#load_table(table_name) ⇒ Object
68 69 70 |
# File 'lib/iceberg/catalog.rb', line 68 def load_table(table_name) Table.new(@catalog.load_table(table_name), @catalog) end |
#namespace_exists?(namespace) ⇒ Boolean
16 17 18 |
# File 'lib/iceberg/catalog.rb', line 16 def namespace_exists?(namespace) @catalog.namespace_exists?(namespace) end |
#namespace_properties(namespace) ⇒ Object
20 21 22 |
# File 'lib/iceberg/catalog.rb', line 20 def namespace_properties(namespace) @catalog.namespace_properties(namespace) end |
#query(sql) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/iceberg/catalog.rb', line 95 def query(sql) # requires datafusion feature raise Todo unless @catalog.respond_to?(:query) @catalog.query(sql) end |
#register_table(table_name, metadata_location) ⇒ Object
91 92 93 |
# File 'lib/iceberg/catalog.rb', line 91 def register_table(table_name, ) @catalog.register_table(table_name, ) end |
#rename_table(table_name, new_name) ⇒ Object
87 88 89 |
# File 'lib/iceberg/catalog.rb', line 87 def rename_table(table_name, new_name) @catalog.rename_table(table_name, new_name) end |
#table_exists?(table_name) ⇒ Boolean
81 82 83 84 85 |
# File 'lib/iceberg/catalog.rb', line 81 def table_exists?(table_name) @catalog.table_exists?(table_name) rescue NamespaceNotFoundError false end |
#update_namespace(namespace, properties:) ⇒ Object
24 25 26 |
# File 'lib/iceberg/catalog.rb', line 24 def update_namespace(namespace, properties:) @catalog.update_namespace(namespace, properties) end |