如何通过AWS开发工具包创建AWS Athena分区

时间:2018-10-11 02:33:43

标签: amazon-web-services amazon-athena

我尝试通过aws sdk nodejs添加athena分区。

const AWS = require('aws-sdk');
const athena = new AWS.Athena({apiVersion: '2017-05-18'});

let queryParams = {
    QueryString: `ALTER TABLE table_name ADD PARTITION (year='2018',month='10',day='10') location 's3://bucket-name/2018/10/10/'`,
    ResultConfiguration: {
        OutputLocation: 's3://bucket-name/result-logs'
    },
    QueryExecutionContext: {
        Database: 'database_name'
    }
}
athena.startQueryExecution(queryParams, (err, data) => {
    console.log('start query');
    console.log('err : ' ,  err);
    console.log('data : ' , data);
});

但是,我得到了以下错误日志。

{ InvalidRequestException: line 1:28: missing 'COLUMN' at 'PARTITION'
    at Request.extractError (/project/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.callListeners (/project/node_modules/aws-sdk/lib/sequential_executor.js:109:20)
    at Request.emit (/project/node_modules/aws-sdk/lib/sequential_executor.js:81:10)
    at Request.emit (/project/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/project/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/project/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /project/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/project/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/project/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/project/node_modules/aws-sdk/lib/sequential_executor.js:119:18)
  message: 'line 1:28: missing \'COLUMN\' at \'PARTITION\'',
  code: 'InvalidRequestException',
  time: 2018-10-11T02:03:48.979Z,
  requestId: 'xxxxxxx',
  statusCode: 400,
  retryable: false,
  retryDelay: 81.3136245913281 }

我在aws docs中找不到COLUMN和PARTITION参数

如何在params json中定义COLUMN和PARTITION?

2 个答案:

答案 0 :(得分:1)

S3对象键路径应包括分区名称和值。

例如:

s3://bucket-name/2018/10/10/

应该是

s3://bucket-name/year=2018/month=10/day=10/

答案 1 :(得分:0)

有同样的问题,就我而言,我正在构建如下查询字符串:

`ALTER TABLE table ADD IF NOT EXISTS
    PARTITION (x = ${x}, y = ${y}, dt = ${dt})`

''周围缺少${dt} x,y是整数,而dt是日期字符串XXXX-XX-XX