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

bigquery: api improvements #2530

Merged
merged 23 commits into from
Oct 16, 2017
Merged

bigquery: api improvements #2530

merged 23 commits into from
Oct 16, 2017

Conversation

callmehiphop
Copy link
Contributor

@callmehiphop callmehiphop commented Aug 14, 2017

Closes #2511

TODOs

  • Documentation
  • Unit Tests
  • System Tests

@callmehiphop callmehiphop added api: bigquery Issues related to the BigQuery API. status: do not merge labels Aug 14, 2017
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 14, 2017
@callmehiphop
Copy link
Contributor Author

@tswast if you have some free time, could you look through this PR to make sure all the P0 items look ok?

I also want to mention for CRUD calls on specific properties (labels, timePartitioning, etc.), this all happens through a setMetadata method, which is just a PATCH request that the user can supply an object to.

e.g.

var metadata = {
  labels: {
    foo: 'bar'
  }
};

table.setMetadata(metadata, (err, apiResponse) => {
  // ...
});

value = parseFloat(value);
break;
}
case 'INTEGER': {

This comment was marked as spam.

* // Error handling omitted.
* }
*
* job.getQueryResults(function(err, rows) {});

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

if (options.parameterMode === 'named') {
options.queryParameters = [];
if (query.params) {
reqOpts.useLegacySql = false;

This comment was marked as spam.

This comment was marked as spam.

}

var nextQuery = null;
if (resp.jobComplete === false) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* // Error handling omitted.
* }
*
* job.getQueryResults(function(err, rows) {});

This comment was marked as spam.

* bigquery.createJob().then(function(data) {
* var job = data[0];
*
* return job.getQueryResults();

This comment was marked as spam.

This comment was marked as spam.

}

var nextQuery = null;
if (resp.jobComplete === false) {

This comment was marked as spam.


callback(null, job, resp);
});
this.createJob(reqOpts, callback);

This comment was marked as spam.

This comment was marked as spam.

@callmehiphop
Copy link
Contributor Author

@stephenplusplus @tswast I think I'm ready for a final review if you can find some time soon.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 79bcb4d on callmehiphop:dg--bigquery-redesign into 118b622 on GoogleCloudPlatform:master.

@googleapis googleapis deleted a comment from coveralls Sep 25, 2017
@googleapis googleapis deleted a comment from coveralls Sep 25, 2017
@googleapis googleapis deleted a comment from coveralls Sep 25, 2017
@googleapis googleapis deleted a comment from coveralls Sep 25, 2017
@googleapis googleapis deleted a comment from coveralls Sep 25, 2017
@googleapis googleapis deleted a comment from coveralls Sep 25, 2017
request: function(reqOpts) {
if (reqOpts.method === 'PATCH' && reqOpts.json.etag) {
reqOpts.headers = reqOpts.headers || {};
reqOpts.headers['If-Match'] = reqOpts.json.etag;

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

Facing a system test error:

  1) BigQuery BigQuery/Table should insert rows via stream:
     Value '{{projectId}}' in content does not agree with value 'nth-circlet-705'. This can happen when a value set through a parameter is inconsistent with a value set in the request.
  ApiError
      at Object.parseHttpRespBody (node_modules\@google-cloud\common\src\util.js:192:30)
      at Object.handleResp (node_modules\@google-cloud\common\src\util.js:132:18)
      at Request._callback (node_modules\@google-cloud\common\src\util.js:255:14)
      at Request.self.callback (node_modules\request\request.js:186:22)
      at Request.<anonymous> (node_modules\request\request.js:1163:10)
      at IncomingMessage.<anonymous> (node_modules\request\request.js:1085:12)
      at endReadableNT (_stream_readable.js:1059:12)
      at _combinedTickCallback (internal/process/next_tick.js:138:11)
      at process._tickCallback (internal/process/next_tick.js:180:9)

This is a console.log of bigquery:

BigQuery {
  makeAuthenticatedRequest:
   { [Function: makeAuthenticatedRequest]
     getCredentials: [Function: bound getCredentials],
     authClient:
      Auth {
        authClientPromise: [Object],
        authClient: [Object],
        config: [Object],
        environment: {},
        projectId: 'nth-circlet-705' } },
  authClient:
   Auth {
     authClientPromise: Promise { [Object] },
     authClient:
      JWT {
        transporter: DefaultTransporter {},
        clientId_: undefined,
        clientSecret_: undefined,
        redirectUri_: undefined,
        opts: {},
        credentials: [Object],
        email: '[email protected]',
        keyFile: undefined,
        key: '-----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY-----\n',
        scopes: [Array],
        subject: undefined,
        gToken: [Function: GoogleToken],
        projectId: 'nth-circlet-705',
        gtoken: [Object] },
     config:
      { baseUrl: 'https://www.googleapis.com/bigquery/v2',
        scopes: [Array],
        packageJson: [Object] },
     environment: {},
     projectId: 'nth-circlet-705' },
  baseUrl: 'https://www.googleapis.com/bigquery/v2',
  getCredentials: [Function: bound getCredentials],
  globalInterceptors: [],
  interceptors: [],
  packageJson: { ... },
  projectId: '{{projectId}}',
  projectIdRequired: true,
  Promise: [Function: Promise] }

@@ -249,33 +260,13 @@ Dataset.prototype.createTable = function(id, options, callback) {
options = {};
}

var body = extend(true, {}, options, {

This comment was marked as spam.

var FAKE_QUERY = 'SELECT * FROM `table`';

it('should call through to bigQuery#startQuery', function(done) {
ds.bigQuery.startQuery = function() {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


switch (schemaField.type) {
case 'BOOLEAN':
case 'BOOL': {

This comment was marked as spam.

break;
}
case 'FLOAT':
case 'FLOAT64': {

This comment was marked as spam.

break;
}
case 'INTEGER':
case 'INT64': {

This comment was marked as spam.

@@ -1064,12 +871,21 @@ Table.prototype.import = function(source, metadata, callback) {
*
* @param {object|object[]} rows - The rows to insert into the table.
* @param {object=} options - Configuration object.
* @param {boolean} options.autoCreate - Automatically create the table if it

This comment was marked as spam.

if (metadata.name) {
metadata.friendlyName = metadata.name;
delete metadata.name;
if (is.fn(metadata)) {

This comment was marked as spam.

}
});

if (is.fn(metadata)) {

This comment was marked as spam.

table.startCopyFrom(SOURCE_TABLE, done);
});

it('should pass an error to the callback', function(done) {

This comment was marked as spam.

table.bigQuery.createJob = function() {};
});

it('should send the correct API request', function(done) {

This comment was marked as spam.

@callmehiphop
Copy link
Contributor Author

@dwmclary for whatever reason it won't let me add you as a reviewer, so I hope a friendly ping here will suffice.

@callmehiphop
Copy link
Contributor Author

@stephenplusplus in regard to #2530 (comment) - are you using a specific OS/Node version/etc.? I can't reproduce it on my machine.

@stephenplusplus
Copy link
Contributor

Windows 10, Node v8.6.0, npm 5.3.0.

It might depend on how you are auth'ing. From table.createWriteStream():

      request: {
        uri: format('{base}/{projectId}/jobs', {
          base: 'https://www.googleapis.com/upload/bigquery/v2/projects',
          projectId: self.bigQuery.projectId
        })
      }

I'm using ADC, so self.bigQuery.projectId isn't set. This probably isn't new to this PR, but maybe sneak a fix in?

@callmehiphop
Copy link
Contributor Author

@stephenplusplus ah, gotcha. I'm wondering what the most correct solution here is, initially I would think to call util.replaceProjectIdToken(...) on all the options, but that feels wrong. If you think it's more involved than that, I would ask we open a separate issue so we don't delay the release of these changes.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 6631a1e on callmehiphop:dg--bigquery-redesign into 118b622 on GoogleCloudPlatform:master.

@stephenplusplus
Copy link
Contributor

That makes sense, re: separate effort.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling d5364b0 on callmehiphop:dg--bigquery-redesign into 118b622 on GoogleCloudPlatform:master.

@callmehiphop
Copy link
Contributor Author

@stephenplusplus I think we're still waiting for an approval from @dwmclary, but is there anything else I may have forgotten to tackle in this?

@stephenplusplus
Copy link
Contributor

@callmehiphop want to just merge this?

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. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants