Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

Can't query my bigQuery Error Unrecognized name

I need some help.

I have this script to send pubsub messages to my topic:

const topicName = "---";
const data = JSON.stringify({
  customerToken: "teste",
  fbclid: "Icanchangethat",
  fbc: "Itworks",
  fbp: "thisismydata",
  firstHitTS: "2021-01-12",
  consentFB: true,
});

// Imports the Google Cloud client library
const { PubSub } = require("@google-cloud/pubsub");

// Creates a client; cache this for further use
const pubSubClient = new PubSub();

async function publishMessageWithCustomAttributes() {
  // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject)
  const dataBuffer = Buffer.from(data);

  // Add two custom attributes, origin and username, to the message
  const customAttributes = {};

  const messageId = await pubSubClient
    .topic(topicName)
    .publish(dataBuffer, customAttributes);
  console.log(`Message ${messageId} published.`);
  console.log(customAttributes);
}

publishMessageWithCustomAttributes().catch(console.error);

As you can see I send data in my message (customerToken,fbclid..etc)

With this cloud func:

const { BigQuery } = require("@google-cloud/bigquery");
const bigquery = new BigQuery();

exports.insertBigQuery = async (message, context) => {
  // Decode base64 the PubSub message
  let logData = Buffer.from(message.data, "base64").toString();
  // Convert it in JSON
  let logMessage = JSON.parse(logData);

  const query = createQuery(logMessage);

  const options = {
    query: query,
    location: "US",
  };

  const [job] = await bigquery.createQueryJob(options);
  console.log(`Job ${job.id} started.`);

  // Only wait the end of the job. Theere is no row as answer, it's only an insert
  await job.getQueryResults();
};

function createQuery(logMessage) {
  return `INSERT INTO MYTABLE(customerToken, fbclid, fbc, fbp, firstHitTS, consentFB)
          VALUES (`+logMessage.customerToken+`,`+ logMessage.fbclid+`,`+ logMessage.fbc+`,`+ logMessage.fbp+`,`+logMessage.firstHitTS+`,`+logMessage.consentFB+`)`;
}

I need to query the data I've receive from the message into my bigQuery, every thing seems to be working but I keep receiving Error: Unrecognized name: teste at [2:19] test is the value for customerToken.

I went through the other posts but I could not find an answer that works for me, anyone can help?

Thanks in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...