程序问答   发布时间:2022-05-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了UNIX 时间戳转 Google bigQuery TS 格式大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决UNIX 时间戳转 Google bigQuery TS 格式?

开发过程中遇到UNIX 时间戳转 Google bigQuery TS 格式的问题如何解决?下面主要结合日常开发的经验,给出你关于UNIX 时间戳转 Google bigQuery TS 格式的解决方法建议,希望对你解决UNIX 时间戳转 Google bigQuery TS 格式有所启发或帮助;

我使用 Google Pub/sub 接收消息并触发云函数,该函数在 Bigquery 中查询消息的数据,问题是在我的消息中我收到了 UNIX 时间戳,我需要将其转换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();
};

我访问消息中的数据。

在我的 bigquery 中查询的这部分函数:

function createquery() {
  const queryString = `INSERT INTO \`myTable\`(myTS,userTS,registerTS) 
VALUES ( @myTS,@userTS,@registerTS);`;

我的问题是我收到带有 UNIX 时间戳的消息,当函数运行时,我的查询给了我一个错误。我找不到任何解决方案,非常感谢任何帮助!提前致谢!

解决方法

您可以处理此问题的一种方法是使用 timestAMP_SECONDS 函数将您的值包装在插入

INSERT INTO \`myTable\`(myTS,userTS,registerTS) 
VALUES ( timestAMP_SECONDS(@myTS),timestAMP_SECONDS(@userTS),timestAMP_SECONDS(@registerTS));

大佬总结

以上是大佬教程为你收集整理的UNIX 时间戳转 Google bigQuery TS 格式全部内容,希望文章能够帮你解决UNIX 时间戳转 Google bigQuery TS 格式所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:Google格式