<commit_before># https://cloud.google.com/bigquery/docs/reference/v2/tables

module BigQuery
  module Tables
    def create_table(name, schema)
      result = access_api(
        api_method: bigquery.tables.insert,
        body_object: {
          tableReference: {
            tableId: name
          },
          schema: {
            fields: schema
          }
        }
      )
      handle_error(result) if result.error?
    end

    def fetch_schema(table)
      result = access_api(
        api_method: bigquery.tables.get,
        parameters: {
          tableId: table
        }
      )
      handle_error(result) if result.error?
      JSON.parse(result.body)['schema']['fields']
    end
  end
end<commit_msg>Implements Tables API<commit_after># https://cloud.google.com/bigquery/docs/reference/v2/tables

module BigQuery
  module Tables
    def create_table(name, schema)
      result = access_api(
        api_method: bigquery.tables.insert,
        body_object: {
          tableReference: {
            tableId: name
          },
          schema: {
            fields: schema
          }
        }
      )
      handle_error(result) if result.error?
    end

    def list_tables(options = {})
      result = access_api(
        api_method: bigquery.tables.list,
        parameters: options
      )
      handle_error(result) if result.error?
      JSON.parse(result.body)
    end

    def update_table(name, options = {})
      result = access_api(
        api_method: bigquery.tables.update,
        parameters: {
          tableId: name
        },
        body_object: options
      )
      handle_error(result) if result.error?
      JSON.parse(result.body)
    end

    def patch_table(name, options = {})
      result = access_api(
        api_method: bigquery.tables.patch,
        parameters: {
          tableId: name
        },
        body_object: options
      )
      handle_error(result) if result.error?
      JSON.parse(result.body)
    end

    def fetch_schema(table)
      fetch_table_info(table)['schema']['fields']
    end

    def fetch_table_info(table)
      result = access_api(
        api_method: bigquery.tables.get,
        parameters: {
          tableId: table
        }
      )
      handle_error(result) if result.error?
      JSON.parse(result.body)
    end

    def drop_table(name)
      result = access_api(
        api_method: bigquery.tables.delete,
        parameters: {
          tableId: name
        }
      )
      handle_error(result) if result.error?
    end
  end
end
{'fraction_non_alphanumeric': 0.0925632911392405, 'fraction_numerical': 0.0007911392405063291, 'mean_word_length': 1.847972972972973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7032416', 'n_tokens_mistral': 750, 'n_tokens_neox': 742, 'n_words': 145}