class Multiwoven::Integrations::Source::Bigquery::Client

def discover(connection_config)

def discover(connection_config)
  connection_config = connection_config.with_indifferent_access
  bigquery = create_connection(connection_config)
  target_dataset_id = connection_config["dataset_id"]
  records = bigquery.datasets.flat_map do |dataset|
    next unless dataset.dataset_id == target_dataset_id
    dataset.tables.flat_map do |table|
      table.schema.fields.map do |field|
        {
          table_name: table.table_id,
          column_name: field.name,
          data_type: field.type,
          is_nullable: field.mode == "NULLABLE"
        }
      end
    end
  end
  catalog = Catalog.new(streams: create_streams(records))
  catalog.to_multiwoven_message
rescue StandardError => e
  handle_exception(e, {
                     context: "BIGQUERY:DISCOVER:EXCEPTION",
                     type: "error"
                   })
end