【问题标题】:Does Node-Redshift supports Copy command (query) to load data from S3 to Redshift?Node-Redshift 是否支持复制命令(查询)将数据从 S3 加载到 Redshift?
【发布时间】:2019-08-02 18:58:56
【问题描述】:

我想知道“Node-redshift”模块是否支持 Copy From 查询,从 S3 存储桶中获取批量数据并将其加载到 Redshift 中? 如果不是,我可以使用哪些其他选项连接到 Redshift 并使用 Copy 命令。

【问题讨论】:

  • 我下面的回复有用吗?如果是这样,请接受它,以便其他人也会发现它有用

标签: node.js amazon-s3 amazon-redshift etl


【解决方案1】:

node-redshift 只是一个基本的 javascript 客户端,它将执行您提供的任何查询/语句/DML。

为了执行复制命令,你只需要初始化客户端并执行命令:

var copyCommand = "copy DESTINATION_TABLE_NAME 
                   from 's3://BUCKET_NAME/SOME_PREFIX/' 
                   credentials
                   access_key_id 'AKIA...'
                   secret_access_key 'secret...';"

var Redshift = require('node-redshift');

var client = {
  user: user,
  database: database,
  password: password,
  port: port,
  host: host,
};

var redshiftClient = new Redshift(client, [options]);

redshiftClient.connect(function(err){
  if(err) throw err;
  else{
    redshiftClient.query(copyCommand, [options], function(err, data){
      if(err) throw err;
      else{
        console.log(data);
        redshiftClient.close();
      }
    });
  }
});

存储在存储桶中的文件有多种受支持的格式,例如 CSV 和 PARQUET。 见复制命令文档:https://docs.aws.amazon.com/redshift/latest/dg/t_loading-tables-from-s3.html

片段取自官方 redshift-node 页面https://www.npmjs.com/package/node-redshift,并针对上述问题进行了调整。

还有官方的aws nodejs客户端https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Redshift.html,不过思路是一样的。

【讨论】:

  • 谢谢,我想通了,但是官方客户端(AWS 提供)不支持对 redshift 执行特定查询。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-22
  • 1970-01-01
  • 2018-09-12
  • 1970-01-01
相关资源
最近更新 更多