Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
quartzmo opened this issue Aug 13, 2015 · 1 comment · Fixed by #264
Closed

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

quartzmo opened this issue Aug 13, 2015 · 1 comment · Fixed by #264
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Milestone

Comments

@quartzmo
Copy link
Member

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.

@quartzmo quartzmo added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. api: bigquery Issues related to the BigQuery API. labels Aug 13, 2015
@jgeewax
Copy link

jgeewax commented Aug 13, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants