我正在尝试使用Aurora mySQL实例作为源以及Redshift实例作为目标来启用DMS复制。 复制在布尔列上失败。我已将布尔列声明为mySQL实例上的BIT(1)。 根据文档,mySQL中的布尔列应定义为BIT:
https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.MySQL.html#CHAP_Source.MySQL.DataTypes
如果我删除布尔值列,它将起作用。我也尝试将列定义为布尔值。那也不起作用。
这是我得到的错误:
2018-08-26T16:59:19 [TARGET_APPLY] E:RetCode:SQL_ERROR SqlState: 42804 NativeError:30消息:[Amazon] [Amazon Redshift](30)错误 试图执行查询时发生:[SQLState 42804]错误: “状态”列的类型为布尔值,但表达式的类型为character 提示:您将需要重写或强制转换表达式。 [1022502](ar_odbc_stmt.c:4428)
答案 0 :(得分:0)
事实证明这是DMS的错误。仅在正在进行的复制过程中会发生这种情况,而不会在满负荷情况下发生。在复制过程中,从Aurora MySql到Redshift的布尔值被强制转换为Varchar,从而导致上述错误。
答案 1 :(得分:0)
我遇到了同样的问题,但是我迁移了自己的库,所以我写了一篇可能对您有帮助的文章来解决。另外,您可以使用DMS事件来通知SMS,然后调用lambda来实现。
使用节点仅运行file.js init()
const AWS = require("aws-sdk");
AWS.config.update({
region: "us-east-1"
});
const documentClient = new AWS.DynamoDB.DocumentClient();
let invalidList = [];
const TableName = 'TableName';
const params = {
TableName: TableName,
};
module.exports.init = function () {
console.log("Start Conversions of Details Booleans")
documentClient.scan(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Scan succeeded.");
// By default scan retrieves at max 1 mb of data
if (typeof data.LastEvaluatedKey != "undefined") {
console.log("Scanning for more...");
params.ExclusiveStartKey = data.LastEvaluatedKey;
documentClient.scan(params, onScan);
}
invalidList = getinvalidList(data);
if(invalidList.length == 0) {
console.log("All data is aready migrated");
return;
}
updateList(invalidList);
}
});
};
function getinvalidList(list) {
return list.Items.reduce((invalidList, item) => {
if (item) {
const variable = (item.variable && item.variable != undefined) ? item.variable : '0';
if (isNotBoolean(variable)) {
invalidList.push(item);
}
}
return invalidList;
}, []);
}
function updateList(list) {
list.forEach(item => {
var params = {
TableName: TableName,
Key: {
"id": item.id,
},
UpdateExpression: "set variable = :variable",
ExpressionAttributeValues: {
":variable": newValue(item.variable),
},
ReturnValues: "UPDATED_NEW"
};
documentClient.update(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
},
)
});
}
function newValue(variable) {
return isNotBoolean(variable) ? !!+variable : variable
}
function isNotBoolean(variable) {
return (typeof variable !== 'boolean')
}