繁体   English   中英

通过 Node.js API 删除 Big Query 中的表,并得到 ENOENT: no such file or directory

[英]Deleting a table in Big Query via Node.js API, and getting ENOENT: no such file or directory

我意识到这可能是一个愚蠢的问题,所以感谢您花时间阅读(并希望回答)它。 我是 Javascript 和节点的新手,所以请假设我知道一些行话。

我正在尝试使用 table.delete() function 从 google 客户端库(链接如下)中删除 node.js (v12.15.0) 中的 Big Query 表。

https://googleapis.dev/nodejs/bigquery/latest/Table.html#delete

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

async function deleteTable(
  datasetId = 'my_dataset',
  tableId = 'my_table',
) {
  console.log(`Deleting table ${tableId}`);
  try {
    const [table] = await bigquery
    .dataset(datasetId)
    .table(tableId)
    .delete();
    console.log(`Table ${tableId} deleted.`);
  } catch (err){
    console.log(err);
  }
}

deleteTable();

要运行它,google 需要从您的 Big Query 帐户进行身份验证,我已将其下载为 json 文件并存储在“凭据”文件夹中。 该路径作为环境变量保存在我的 ~/.bash_profile 中:

export GOOGLE_APPLICATION_CREDENTIALS="/Users/tom/Desktop/work/test/credentials/google_application_credentials.json"

当我尝试运行上述脚本时,出现 ENOENT 错误:

Error: The file at {[contents of google_application_credentials.json]} does not exist, or it is not a file. 
ENOENT: no such file or directory, lstat '/Users/tom/Desktop/work/test/{[contents of google_application_credentials.json]}
   at Object.realpathSync (fs.js:1529:7)
    at GoogleAuth._getApplicationCredentialsFromFilePath (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:250:27)
    at GoogleAuth._tryGetApplicationCredentialsFromEnvironmentVariable (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:192:25)
    at GoogleAuth.getApplicationDefaultAsync (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:130:33)
    at GoogleAuth.getClient (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:502:28)
    at GoogleAuth.authorizeRequest (/Users/tom/Desktop/work/test/node_modules/google-auth-library/build/src/auth/googleauth.js:543:35)
    at BigQuery.makeAuthenticatedRequest (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/util.js:374:28)
    at BigQuery.request_ (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/service.js:129:18)
    at BigQuery.request (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/service.js:140:36)
    at Dataset.request_ (/Users/tom/Desktop/work/test/node_modules/@google-cloud/common/build/src/service-object.js:231:21) {
  errno: -2,
  syscall: 'lstat',
  code: 'ENOENT',
  path: '/Users/tom/Desktop/work/test/{[contents of google_application_credentials.json]}

很明显,这个脚本是在/Users/tom/Desktop/work/test 中搜索.json 文件的内容,而不是文件本身,但我不知道为什么。 bash配置文件中的路径肯定是正确的,环境变量也正确更新了。 如果有人能帮助我,我将不胜感激。 如果您需要更多信息,请告诉我。

已解决:我重新启动了我的笔记本电脑,它肯定已经清除了一些不应该存在的环境变量,然后从 Big Query 下载了一个新的 .json 文件,其中包含帐户身份验证详细信息。 值得注意的是这些已经改变了(我认为它们随着每次下载而改变),所以我可以事先使用过时的文件。

这使得脚本可以正常工作。

如果有人对实际发生的事情有更好的答案,请回答!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM