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

createTable - Required parameter is missing #1422

Closed
mlynch opened this issue Jul 12, 2016 · 4 comments
Closed

createTable - Required parameter is missing #1422

mlynch opened this issue Jul 12, 2016 · 4 comments
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: question Request for information or clarification. Not an issue.

Comments

@mlynch
Copy link

mlynch commented Jul 12, 2016

I'm creating a table with an existing dataset like this:

var bigquery = gcloud.bigquery({
  projectId: 'ionic-stats-storage',
  keyFilename: './bigquery.json'
});

var cliDataset = bigquery.dataset('CLI');
cliDataset.createTable(type, {
        schema: {
          fields: [
            { type: 'string', name: 'type' },
            { type: 'string', name: 'service' },
            { type: 'string', name: 'uuid' },
            { type: 'timestamp', name: 'created_at' },
            { name: 'data', fields: fields }
          ]
        }
      }, function(err, table, apiResponse) {
...
});

This is the payload being sent to the /tables endpoint as I inspected it in the gcloud node library (pretty-printed):

{
  "schema": {
    "fields": [
      {
        "type": "string",
        "name": "type"
      },
      {
        "type": "string",
        "name": "service"
      },
      {
        "type": "string",
        "name": "uuid"
      },
      {
        "type": "timestamp",
        "name": "created_at"
      },
      {
        "name": "data",
        "fields": [
          {
            "name": "favorite_flavor",
            "type": "string"
          }
        ]
      }
    ]
  },
  "tableReference": {
    "datasetId": "CLI",
    "projectId": "ionic-stats-storage"
  }
}

The API is returning a vague error about a missing required parameter, but doesn't say which one, and I believe I'm using the node API correctly (very possible I'm not). Note: I also tried removing the data record in case I wasn't doing that properly, but I receive the same response:

{ ApiError: Required parameter is missing
    at new util.ApiError (/Users/max/git/ionic-track/node_modules/gcloud/lib/common/util.js:106:10)
    at Object.parseHttpRespBody (/Users/max/git/ionic-track/node_modules/gcloud/lib/common/util.js:184:30)
    at Object.handleResp (/Users/max/git/ionic-track/node_modules/gcloud/lib/common/util.js:124:18)
    at /Users/max/git/ionic-track/node_modules/gcloud/lib/common/util.js:447:12
    at Request.onResponse [as _callback] (/Users/max/git/ionic-track/node_modules/retry-request/index.js:120:7)
    at Request.self.callback (/Users/max/git/ionic-track/node_modules/request/request.js:187:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/Users/max/git/ionic-track/node_modules/request/request.js:1044:10)
    at emitOne (events.js:96:13)
  code: 400,
  errors:
   [ { domain: 'global',
       reason: 'required',
       message: 'Required parameter is missing' } ],
  response: undefined,
  message: 'Required parameter is missing' }
@mlynch mlynch closed this as completed Jul 12, 2016
@stephenplusplus
Copy link
Contributor

I believe this should work:

cliDataset.createTable(type, {
  schema: {
    fields: [
      { type: 'string', name: 'type' },
      { type: 'string', name: 'service' },
      { type: 'string', name: 'uuid' },
      { type: 'timestamp', name: 'created_at' },
      {
        name: 'data',
        type: 'record', // <-- new
        fields: [
          {
            type: 'string',
            name: 'favorite_flavor'
          }
        ]
      }
    ]
  }
}, function(err, table, apiResponse) {
  // ...
});

@stephenplusplus stephenplusplus added type: question Request for information or clarification. Not an issue. api: bigquery Issues related to the BigQuery API. labels Jul 12, 2016
@mlynch
Copy link
Author

mlynch commented Jul 12, 2016

Okay, I figured out what I was doing wrong here. First, my table id was undefined since I was sending incorrect data to my API. However, in the process of tweaking things and trying to get this to work, I tried using the id sub record as per #954 which does not seem to work yet. Additionally, sub-records need the 'record' type but using them is not documented in the API docs anywhere. Making those changes works now 👯

@stephenplusplus thanks for the help!

@stephenplusplus
Copy link
Contributor

Yeah, I think we can make this easier. We try to focus on the common use cases and decorate them to make things easier. This leaves holes where we link to the upstream API docs to show all of the options (https://cloud.google.com/bigquery/docs/reference/v2/tables#resource) from our docs (https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.36.0/bigquery/dataset?method=createTable).

Making this easier should be pretty... easy. I'll re-open this issue and ping you when I have a PR, if you don't mind. Thanks for calling this out!

@mlynch
Copy link
Author

mlynch commented Jul 12, 2016

Sounds great, thanks!

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: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants