abronte / BigQuery

A BigQuery wrapper
86 stars 58 forks source link

Allow media and parameters when inserting jobs #20

Closed nateberkopec closed 9 years ago

nateberkopec commented 9 years ago

This allows us to use this library for uploading data via the Jobs API.

    json = StringIO.new
    json.write({ id: 1, name: "me" }.to_json)
    json.write("\n")
    json.rewind

    media = Google::APIClient::UploadIO.new(json, 'application/octet-stream')

    metadata = {
      "load": {
        "sourceFormat": "NEWLINE_DELIMITED_JSON",
        "destinationTable": {
          "projectId": "myproject",
          "datasetId": "mydata",
          "tableId": "mytable"
        }
      }
    }

    result = $bigquery.insert_job(
      metadata,
      { uploadType: 'multipart' },
      media
    )