Skip to content

Improve API for configuring the schema for a BigQuery Table #217

Closed

Description

@quartzmo

The current JSON-as-hash mechanism for setting a Table schema is needlessly verbose and exposes the all-caps convention of the underlying Rest API. Here is the example from the docs.

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery
dataset = bigquery.dataset "my_dataset"

schema = {
  "fields" => [
    {
      "name" => "first_name",
      "type" => "STRING",
      "mode" => "REQUIRED"
    },
    {
      "name" => "cities_lived",
      "type" => "RECORD",
      "mode" => "REPEATED",
      "fields" => [
        {
          "name" => "place",
          "type" => "STRING",
          "mode" => "REQUIRED"
        },
        {
          "name" => "number_of_years",
          "type" => "INTEGER",
          "mode" => "REQUIRED"
        }
      ]
    }
  ]
}
table = dataset.create_table "my_table",
                             name: "My Table",
                             schema: schema

I believe it would improve the API to use something more structured and native to Ruby, such as a builder inside a block:

table = dataset.create_table "my_table", name: "My Table" do |schema|
  schema.string :first_name, mode: :required
  schema.record :cities_lived, mode: :repeated do |repeated_schema|
    repeated_schema.string :place, mode: :required
    repeated_schema.integer :number_of_years, mode: :required
  end
end

Both Dataset#create_table and Table#schema= would need to be updated for the new approach.

Activity

  1. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    api: bigqueryIssues related to the BigQuery API.
    on Aug 13, 2015
  2. jgeewax commented on Aug 13, 2015

    @jgeewax

    Likely related to googleapis/google-cloud-python#1058 (Python)

  3. added this to the 0.3.1 milestone on Aug 28, 2015
  4. added a commit that references this issue on Sep 4, 2015
    f000d07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions