module DeltaLake

def try_get_deltatable(table_uri, storage_options)

def try_get_deltatable(table_uri, storage_options)
  Table.new(table_uri, storage_options: storage_options)
rescue TableNotFoundError
  nil
end

def try_get_table_and_table_uri(table_or_uri, storage_options)

def try_get_table_and_table_uri(table_or_uri, storage_options)
  if !table_or_uri.is_a?(String) && !table_or_uri.is_a?(Table)
    raise ArgumentError, "table_or_uri must be a String or Table"
  end
  if table_or_uri.is_a?(String)
    table = try_get_deltatable(table_or_uri, storage_options)
    table_uri = table_or_uri.to_s
  else
    table = table_or_uri
    table_uri = table._table.table_uri
  end
  [table, table_uri]
end

def write(

def write(
  table_or_uri,
  data,
  partition_by: nil,
  mode: "error",
  name: nil,
  description: nil,
  configuration: nil,
  schema_mode: nil,
  storage_options: nil,
  predicate: nil,
  target_file_size: nil,
  writer_properties: nil,
  commit_properties: nil,
  post_commithook_properties: nil
)
  table, table_uri = try_get_table_and_table_uri(table_or_uri, storage_options)
  if partition_by.is_a?(String)
    partition_by = [partition_by]
  end
  if !table.nil? && mode == "ignore"
    return
  end
  data = Utils.convert_data(data)
  if table
    table._table.write(
      data,
      mode,
      schema_mode,
      partition_by,
      predicate,
      target_file_size,
      name,
      description,
      configuration,
      writer_properties,
      commit_properties,
      post_commithook_properties
    )
  else
    write_deltalake_rust(
      table_uri,
      data,
      mode,
      schema_mode,
      partition_by,
      predicate,
      target_file_size,
      name,
      description,
      configuration,
      storage_options,
      writer_properties,
      commit_properties,
      post_commithook_properties
    )
  end
end