Class: Iceberg::Catalog
- Inherits:
-
Object
- Object
- Iceberg::Catalog
- Defined in:
- lib/iceberg/catalog.rb
Direct Known Subclasses
GlueCatalog, MemoryCatalog, RestCatalog, S3TablesCatalog, SqlCatalog
Instance Method Summary collapse
- #_initialize(catalog, default_namespace:) ⇒ Object
- #create_namespace(namespace, properties: {}, if_not_exists: nil) ⇒ Object
- #create_table(table_name, schema: nil, location: nil, partition_spec: nil, sort_order: nil, properties: {}) ⇒ 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 = nil) ⇒ Object
- #load_table(table_name) ⇒ Object
- #namespace_exists?(namespace) ⇒ Boolean
- #namespace_properties(namespace) ⇒ Object
- #purge_table(table_name) ⇒ Object
- #register_table(table_name, metadata_location) ⇒ Object
- #rename_table(table_name, new_name) ⇒ Object
- #sql(sql, params = []) ⇒ Object
- #table_exists?(table_name) ⇒ Boolean
- #update_namespace(namespace, properties:) ⇒ Object
Instance Method Details
#_initialize(catalog, default_namespace:) ⇒ Object
3 4 5 6 |
# File 'lib/iceberg/catalog.rb', line 3 def _initialize(catalog, default_namespace:) @catalog = catalog @default_namespace = default_namespace end |
#create_namespace(namespace, properties: {}, if_not_exists: nil) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/iceberg/catalog.rb', line 12 def create_namespace(namespace, properties: {}, if_not_exists: nil) @catalog.create_namespace(namespace, properties) rescue NamespaceAlreadyExistsError => e if !if_not_exists raise e end nil end |
#create_table(table_name, schema: nil, location: nil, partition_spec: nil, sort_order: nil, properties: {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/iceberg/catalog.rb', line 46 def create_table(table_name, schema: nil, location: nil, partition_spec: nil, sort_order: nil, properties: {}) 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?(Schema) # do nothing elsif schema.respond_to?(:arrow_c_schema) schema = Schema.new(schema) elsif schema.is_a?(Hash) table_definition = TableDefinition.new schema.each do |k, v| table_definition.column(k, v) end schema = Schema.new(*table_definition.fields) elsif schema.nil? schema = Schema.new end Table.new(@catalog.create_table(with_namespace(table_name), schema, location, partition_spec, sort_order, properties), @catalog) end |
#drop_namespace(namespace, if_exists: nil) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/iceberg/catalog.rb', line 33 def drop_namespace(namespace, if_exists: nil) @catalog.drop_namespace(namespace) rescue NoSuchNamespaceError => e if !if_exists raise e end nil end |
#drop_table(table_name, if_exists: nil) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/iceberg/catalog.rb', line 76 def drop_table(table_name, if_exists: nil) @catalog.drop_table(with_namespace(table_name)) rescue NoSuchTableError => e if !if_exists raise e end nil end |
#inspect ⇒ Object
hide internal state
111 112 113 |
# File 'lib/iceberg/catalog.rb', line 111 def inspect to_s end |
#list_namespaces(parent = nil) ⇒ Object
8 9 10 |
# File 'lib/iceberg/catalog.rb', line 8 def list_namespaces(parent = nil) @catalog.list_namespaces(parent) end |
#list_tables(namespace = nil) ⇒ Object
42 43 44 |
# File 'lib/iceberg/catalog.rb', line 42 def list_tables(namespace = nil) @catalog.list_tables(namespace || @default_namespace) end |
#load_table(table_name) ⇒ Object
72 73 74 |
# File 'lib/iceberg/catalog.rb', line 72 def load_table(table_name) Table.new(@catalog.load_table(with_namespace(table_name)), @catalog) end |
#namespace_exists?(namespace) ⇒ Boolean
21 22 23 |
# File 'lib/iceberg/catalog.rb', line 21 def namespace_exists?(namespace) @catalog.namespace_exists?(namespace) end |
#namespace_properties(namespace) ⇒ Object
25 26 27 |
# File 'lib/iceberg/catalog.rb', line 25 def namespace_properties(namespace) @catalog.namespace_properties(namespace) end |
#purge_table(table_name) ⇒ Object
85 86 87 |
# File 'lib/iceberg/catalog.rb', line 85 def purge_table(table_name) @catalog.purge_table(with_namespace(table_name)) end |
#register_table(table_name, metadata_location) ⇒ Object
99 100 101 |
# File 'lib/iceberg/catalog.rb', line 99 def register_table(table_name, ) @catalog.register_table(with_namespace(table_name), ) end |
#rename_table(table_name, new_name) ⇒ Object
95 96 97 |
# File 'lib/iceberg/catalog.rb', line 95 def rename_table(table_name, new_name) @catalog.rename_table(with_namespace(table_name), with_namespace(new_name)) end |
#sql(sql, params = []) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/iceberg/catalog.rb', line 103 def sql(sql, params = []) # requires datafusion feature raise Todo unless @catalog.respond_to?(:session_context) session_context.sql(sql, params) end |
#table_exists?(table_name) ⇒ Boolean
89 90 91 92 93 |
# File 'lib/iceberg/catalog.rb', line 89 def table_exists?(table_name) @catalog.table_exists?(with_namespace(table_name)) rescue NoSuchNamespaceError false end |
#update_namespace(namespace, properties:) ⇒ Object
29 30 31 |
# File 'lib/iceberg/catalog.rb', line 29 def update_namespace(namespace, properties:) @catalog.update_namespace(namespace, properties) end |