Insert into BigQuery via Cloud Function not working
I am inserting the following json into a pre-created BigQuery table.
{
"Member_ID": 881230,
"First_Name": "Dave2",
"Last_Name": "Manin2",
"Gender": "M",
"Age": 53,
"Height": "5,2",
"Weight": 145,
"Hours_Sleep": 4,
"Calories_Consumed": 2497,
"Exercise_Calories_Burned": 876,
"Date": "2018-10-17"
}
When I insert the above row into the table directly it works fine but errors out (see below for complete error message) via a function. What I am missing? Any help is appreciated.
This is my node.js (error message after the code)
exports.subscribe = function (event, callback) {
const BigQuery = require('@google-cloud/bigquery');
const projectId = "mydemo-221920"; //Enter your project ID here
const datasetId = "mydemodata"; //Enter your BigQuery dataset name here
const tableId = "memid"; //Enter your BigQuery table name here -- make sure it is setup correctly
const PubSubMessage = event.data;
// Incoming data is in JSON format
const incomingData = PubSubMessage.data ? Buffer.from(PubSubMessage.data, 'base64').toString() : "{'Member_ID':'na','First_Name':'na','Last_Name':'na','Gender':'na','Age':'na','Height':'na','Weight':'na','Hours_Sleep':'na','Calories_Consumed':'na','Exercise_Calories_Burned':'na','Date':'na'}";
console.log(`My log PubSub en String est: ${incomingData}`);
const jsonData = JSON.parse(incomingData);
var rows = [jsonData];
console.log(`Uploading data: ${JSON.stringify(rows)}`);
// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
});
// Inserts data into memeid table
bigquery
.dataset(datasetId)
.table(tableId)
.insert(rows)
.then((foundErrors) => {
rows.forEach((row) => console.log('Inserted: ', row));
if (foundErrors && foundErrors.insertErrors != undefined) {
foundErrors.forEach((err) => {
console.log('Error: ', err);
})
}
})
.catch((err) => {
console.error('ERROR:', err);
});
// [END bigquery_insert_stream]
callback();
}
I get this error when the function is trying to insert
ERROR: { PartialFailureError: A failure occurred during this request.
at /user_code/node_modules/@google-cloud/bigquery/src/table.js:1213:13
at Object.handleResp (/user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:135:3)
at /user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:465:12
at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/bigquery/node_modules/retry-request/index.js:198:7)
at Request.self.callback (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:185:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:1161:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7) errors: [ { errors: [Object], row: [Object] } ], response: { kind: 'bigquery#tableDataInsertAllResponse', insertErrors: [ [Object] ] }, message: 'A failure occurred during this request.' }
The function is reading this json
{
insertId: "000000-6dbc4c0f-fe15-4260-95c6-10afe7d0960b"
labels: {…}
logName: "projects/mydemo-221920/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2018-11-13T17:27:48.429240186Z"
resource: {…}
severity: "INFO"
textPayload: "My log PubSub en String est: {"Member_ID":881230,"First_Name":"Dave2","Last_Name":"Manin2","Gender":"M","Age":53,"Height":"5,2","Weight":145,"Hours_Sleep":4,"Calories_Consumed":2497,"Exercise_Calories_Burned":876,"Date":"2018-10-17"}"
timestamp: "2018-11-13T17:27:42.143Z"
trace: "projects/mydemo-221920/traces/cef3531fe182bf1d6da6e47aae3bbff3"
}
google-cloud-platform google-bigquery google-cloud-functions google-publisher-tag
add a comment |
I am inserting the following json into a pre-created BigQuery table.
{
"Member_ID": 881230,
"First_Name": "Dave2",
"Last_Name": "Manin2",
"Gender": "M",
"Age": 53,
"Height": "5,2",
"Weight": 145,
"Hours_Sleep": 4,
"Calories_Consumed": 2497,
"Exercise_Calories_Burned": 876,
"Date": "2018-10-17"
}
When I insert the above row into the table directly it works fine but errors out (see below for complete error message) via a function. What I am missing? Any help is appreciated.
This is my node.js (error message after the code)
exports.subscribe = function (event, callback) {
const BigQuery = require('@google-cloud/bigquery');
const projectId = "mydemo-221920"; //Enter your project ID here
const datasetId = "mydemodata"; //Enter your BigQuery dataset name here
const tableId = "memid"; //Enter your BigQuery table name here -- make sure it is setup correctly
const PubSubMessage = event.data;
// Incoming data is in JSON format
const incomingData = PubSubMessage.data ? Buffer.from(PubSubMessage.data, 'base64').toString() : "{'Member_ID':'na','First_Name':'na','Last_Name':'na','Gender':'na','Age':'na','Height':'na','Weight':'na','Hours_Sleep':'na','Calories_Consumed':'na','Exercise_Calories_Burned':'na','Date':'na'}";
console.log(`My log PubSub en String est: ${incomingData}`);
const jsonData = JSON.parse(incomingData);
var rows = [jsonData];
console.log(`Uploading data: ${JSON.stringify(rows)}`);
// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
});
// Inserts data into memeid table
bigquery
.dataset(datasetId)
.table(tableId)
.insert(rows)
.then((foundErrors) => {
rows.forEach((row) => console.log('Inserted: ', row));
if (foundErrors && foundErrors.insertErrors != undefined) {
foundErrors.forEach((err) => {
console.log('Error: ', err);
})
}
})
.catch((err) => {
console.error('ERROR:', err);
});
// [END bigquery_insert_stream]
callback();
}
I get this error when the function is trying to insert
ERROR: { PartialFailureError: A failure occurred during this request.
at /user_code/node_modules/@google-cloud/bigquery/src/table.js:1213:13
at Object.handleResp (/user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:135:3)
at /user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:465:12
at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/bigquery/node_modules/retry-request/index.js:198:7)
at Request.self.callback (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:185:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:1161:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7) errors: [ { errors: [Object], row: [Object] } ], response: { kind: 'bigquery#tableDataInsertAllResponse', insertErrors: [ [Object] ] }, message: 'A failure occurred during this request.' }
The function is reading this json
{
insertId: "000000-6dbc4c0f-fe15-4260-95c6-10afe7d0960b"
labels: {…}
logName: "projects/mydemo-221920/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2018-11-13T17:27:48.429240186Z"
resource: {…}
severity: "INFO"
textPayload: "My log PubSub en String est: {"Member_ID":881230,"First_Name":"Dave2","Last_Name":"Manin2","Gender":"M","Age":53,"Height":"5,2","Weight":145,"Hours_Sleep":4,"Calories_Consumed":2497,"Exercise_Calories_Burned":876,"Date":"2018-10-17"}"
timestamp: "2018-11-13T17:27:42.143Z"
trace: "projects/mydemo-221920/traces/cef3531fe182bf1d6da6e47aae3bbff3"
}
google-cloud-platform google-bigquery google-cloud-functions google-publisher-tag
What do you mean by "errors out"? If you're seeing an error message, please edit your question to be specific about what exactly you're observing.
– Doug Stevenson
Nov 13 '18 at 17:46
Please note that you can edit your question to add additional details rather than using a comment. You can then format the error message so it's easier to read.
– Doug Stevenson
Nov 13 '18 at 18:12
got it -done. Thank you for the pointer. Learning as I go :)
– DavM
Nov 13 '18 at 18:14
add a comment |
I am inserting the following json into a pre-created BigQuery table.
{
"Member_ID": 881230,
"First_Name": "Dave2",
"Last_Name": "Manin2",
"Gender": "M",
"Age": 53,
"Height": "5,2",
"Weight": 145,
"Hours_Sleep": 4,
"Calories_Consumed": 2497,
"Exercise_Calories_Burned": 876,
"Date": "2018-10-17"
}
When I insert the above row into the table directly it works fine but errors out (see below for complete error message) via a function. What I am missing? Any help is appreciated.
This is my node.js (error message after the code)
exports.subscribe = function (event, callback) {
const BigQuery = require('@google-cloud/bigquery');
const projectId = "mydemo-221920"; //Enter your project ID here
const datasetId = "mydemodata"; //Enter your BigQuery dataset name here
const tableId = "memid"; //Enter your BigQuery table name here -- make sure it is setup correctly
const PubSubMessage = event.data;
// Incoming data is in JSON format
const incomingData = PubSubMessage.data ? Buffer.from(PubSubMessage.data, 'base64').toString() : "{'Member_ID':'na','First_Name':'na','Last_Name':'na','Gender':'na','Age':'na','Height':'na','Weight':'na','Hours_Sleep':'na','Calories_Consumed':'na','Exercise_Calories_Burned':'na','Date':'na'}";
console.log(`My log PubSub en String est: ${incomingData}`);
const jsonData = JSON.parse(incomingData);
var rows = [jsonData];
console.log(`Uploading data: ${JSON.stringify(rows)}`);
// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
});
// Inserts data into memeid table
bigquery
.dataset(datasetId)
.table(tableId)
.insert(rows)
.then((foundErrors) => {
rows.forEach((row) => console.log('Inserted: ', row));
if (foundErrors && foundErrors.insertErrors != undefined) {
foundErrors.forEach((err) => {
console.log('Error: ', err);
})
}
})
.catch((err) => {
console.error('ERROR:', err);
});
// [END bigquery_insert_stream]
callback();
}
I get this error when the function is trying to insert
ERROR: { PartialFailureError: A failure occurred during this request.
at /user_code/node_modules/@google-cloud/bigquery/src/table.js:1213:13
at Object.handleResp (/user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:135:3)
at /user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:465:12
at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/bigquery/node_modules/retry-request/index.js:198:7)
at Request.self.callback (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:185:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:1161:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7) errors: [ { errors: [Object], row: [Object] } ], response: { kind: 'bigquery#tableDataInsertAllResponse', insertErrors: [ [Object] ] }, message: 'A failure occurred during this request.' }
The function is reading this json
{
insertId: "000000-6dbc4c0f-fe15-4260-95c6-10afe7d0960b"
labels: {…}
logName: "projects/mydemo-221920/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2018-11-13T17:27:48.429240186Z"
resource: {…}
severity: "INFO"
textPayload: "My log PubSub en String est: {"Member_ID":881230,"First_Name":"Dave2","Last_Name":"Manin2","Gender":"M","Age":53,"Height":"5,2","Weight":145,"Hours_Sleep":4,"Calories_Consumed":2497,"Exercise_Calories_Burned":876,"Date":"2018-10-17"}"
timestamp: "2018-11-13T17:27:42.143Z"
trace: "projects/mydemo-221920/traces/cef3531fe182bf1d6da6e47aae3bbff3"
}
google-cloud-platform google-bigquery google-cloud-functions google-publisher-tag
I am inserting the following json into a pre-created BigQuery table.
{
"Member_ID": 881230,
"First_Name": "Dave2",
"Last_Name": "Manin2",
"Gender": "M",
"Age": 53,
"Height": "5,2",
"Weight": 145,
"Hours_Sleep": 4,
"Calories_Consumed": 2497,
"Exercise_Calories_Burned": 876,
"Date": "2018-10-17"
}
When I insert the above row into the table directly it works fine but errors out (see below for complete error message) via a function. What I am missing? Any help is appreciated.
This is my node.js (error message after the code)
exports.subscribe = function (event, callback) {
const BigQuery = require('@google-cloud/bigquery');
const projectId = "mydemo-221920"; //Enter your project ID here
const datasetId = "mydemodata"; //Enter your BigQuery dataset name here
const tableId = "memid"; //Enter your BigQuery table name here -- make sure it is setup correctly
const PubSubMessage = event.data;
// Incoming data is in JSON format
const incomingData = PubSubMessage.data ? Buffer.from(PubSubMessage.data, 'base64').toString() : "{'Member_ID':'na','First_Name':'na','Last_Name':'na','Gender':'na','Age':'na','Height':'na','Weight':'na','Hours_Sleep':'na','Calories_Consumed':'na','Exercise_Calories_Burned':'na','Date':'na'}";
console.log(`My log PubSub en String est: ${incomingData}`);
const jsonData = JSON.parse(incomingData);
var rows = [jsonData];
console.log(`Uploading data: ${JSON.stringify(rows)}`);
// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
});
// Inserts data into memeid table
bigquery
.dataset(datasetId)
.table(tableId)
.insert(rows)
.then((foundErrors) => {
rows.forEach((row) => console.log('Inserted: ', row));
if (foundErrors && foundErrors.insertErrors != undefined) {
foundErrors.forEach((err) => {
console.log('Error: ', err);
})
}
})
.catch((err) => {
console.error('ERROR:', err);
});
// [END bigquery_insert_stream]
callback();
}
I get this error when the function is trying to insert
ERROR: { PartialFailureError: A failure occurred during this request.
at /user_code/node_modules/@google-cloud/bigquery/src/table.js:1213:13
at Object.handleResp (/user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:135:3)
at /user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:465:12
at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/bigquery/node_modules/retry-request/index.js:198:7)
at Request.self.callback (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:185:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:1161:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7) errors: [ { errors: [Object], row: [Object] } ], response: { kind: 'bigquery#tableDataInsertAllResponse', insertErrors: [ [Object] ] }, message: 'A failure occurred during this request.' }
The function is reading this json
{
insertId: "000000-6dbc4c0f-fe15-4260-95c6-10afe7d0960b"
labels: {…}
logName: "projects/mydemo-221920/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2018-11-13T17:27:48.429240186Z"
resource: {…}
severity: "INFO"
textPayload: "My log PubSub en String est: {"Member_ID":881230,"First_Name":"Dave2","Last_Name":"Manin2","Gender":"M","Age":53,"Height":"5,2","Weight":145,"Hours_Sleep":4,"Calories_Consumed":2497,"Exercise_Calories_Burned":876,"Date":"2018-10-17"}"
timestamp: "2018-11-13T17:27:42.143Z"
trace: "projects/mydemo-221920/traces/cef3531fe182bf1d6da6e47aae3bbff3"
}
google-cloud-platform google-bigquery google-cloud-functions google-publisher-tag
google-cloud-platform google-bigquery google-cloud-functions google-publisher-tag
edited Nov 19 '18 at 18:05
Federico Grandi
2,93321227
2,93321227
asked Nov 13 '18 at 17:44
DavMDavM
112
112
What do you mean by "errors out"? If you're seeing an error message, please edit your question to be specific about what exactly you're observing.
– Doug Stevenson
Nov 13 '18 at 17:46
Please note that you can edit your question to add additional details rather than using a comment. You can then format the error message so it's easier to read.
– Doug Stevenson
Nov 13 '18 at 18:12
got it -done. Thank you for the pointer. Learning as I go :)
– DavM
Nov 13 '18 at 18:14
add a comment |
What do you mean by "errors out"? If you're seeing an error message, please edit your question to be specific about what exactly you're observing.
– Doug Stevenson
Nov 13 '18 at 17:46
Please note that you can edit your question to add additional details rather than using a comment. You can then format the error message so it's easier to read.
– Doug Stevenson
Nov 13 '18 at 18:12
got it -done. Thank you for the pointer. Learning as I go :)
– DavM
Nov 13 '18 at 18:14
What do you mean by "errors out"? If you're seeing an error message, please edit your question to be specific about what exactly you're observing.
– Doug Stevenson
Nov 13 '18 at 17:46
What do you mean by "errors out"? If you're seeing an error message, please edit your question to be specific about what exactly you're observing.
– Doug Stevenson
Nov 13 '18 at 17:46
Please note that you can edit your question to add additional details rather than using a comment. You can then format the error message so it's easier to read.
– Doug Stevenson
Nov 13 '18 at 18:12
Please note that you can edit your question to add additional details rather than using a comment. You can then format the error message so it's easier to read.
– Doug Stevenson
Nov 13 '18 at 18:12
got it -done. Thank you for the pointer. Learning as I go :)
– DavM
Nov 13 '18 at 18:14
got it -done. Thank you for the pointer. Learning as I go :)
– DavM
Nov 13 '18 at 18:14
add a comment |
1 Answer
1
active
oldest
votes
I cannot see any errors in your code or in your json. I tried the code that you provided and I've been able to stream data into BigQuery without getting any errors:
I tried to modify the schema of my BigQuery table in order to reproduce your issue and I've been able to get your exact same error:
This is schema should fix your issue:
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286761%2finsert-into-bigquery-via-cloud-function-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I cannot see any errors in your code or in your json. I tried the code that you provided and I've been able to stream data into BigQuery without getting any errors:
I tried to modify the schema of my BigQuery table in order to reproduce your issue and I've been able to get your exact same error:
This is schema should fix your issue:
add a comment |
I cannot see any errors in your code or in your json. I tried the code that you provided and I've been able to stream data into BigQuery without getting any errors:
I tried to modify the schema of my BigQuery table in order to reproduce your issue and I've been able to get your exact same error:
This is schema should fix your issue:
add a comment |
I cannot see any errors in your code or in your json. I tried the code that you provided and I've been able to stream data into BigQuery without getting any errors:
I tried to modify the schema of my BigQuery table in order to reproduce your issue and I've been able to get your exact same error:
This is schema should fix your issue:
I cannot see any errors in your code or in your json. I tried the code that you provided and I've been able to stream data into BigQuery without getting any errors:
I tried to modify the schema of my BigQuery table in order to reproduce your issue and I've been able to get your exact same error:
This is schema should fix your issue:
answered Nov 19 '18 at 15:04
Alex RiquelmeAlex Riquelme
56129
56129
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286761%2finsert-into-bigquery-via-cloud-function-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by "errors out"? If you're seeing an error message, please edit your question to be specific about what exactly you're observing.
– Doug Stevenson
Nov 13 '18 at 17:46
Please note that you can edit your question to add additional details rather than using a comment. You can then format the error message so it's easier to read.
– Doug Stevenson
Nov 13 '18 at 18:12
got it -done. Thank you for the pointer. Learning as I go :)
– DavM
Nov 13 '18 at 18:14