Amazon dynamodb dynamodbxcode6swift使用三列作为键
我正在尝试使用DynamoDB表存储此数据: DartSplayrinSultTableAmazon dynamodb dynamodbxcode6swift使用三列作为键,amazon-dynamodb,secondary-indexes,Amazon Dynamodb,Secondary Indexes,我正在尝试使用DynamoDB表存储此数据: DartSplayrinSultTable CustomerId String PlayerId String PlayerInsult String 使用此处描述的方法(概念,而非代码): https://java.awsblog.com/post/Tx3GYZEVGO924K4/The-DynamoDBMapper-Local-Secondary-Indexes-and-You 在这里: 在这里: http://labs.jo
CustomerId String
PlayerId String
PlayerInsult String
使用此处描述的方法(概念,而非代码):
https://java.awsblog.com/post/Tx3GYZEVGO924K4/The-DynamoDBMapper-Local-Secondary-Indexes-and-You
在这里:
在这里:
http://labs.journwe.com/2013/12/15/dynamodb-secondary-indexes/comment-page-1/#comment-116
我希望每个客户播放器有多个侮辱记录。
CustomerId是我的哈希键
PlayerId是我的射程键
我试图在一个键中使用PlayerResult,以便
第二个playerResult值插入第二条记录
而不是取代现有的
已经为此尝试了全局索引和二级索引,
但如果我试图用一种新的侮辱来增加争吵,它仍然存在
用相同的客户播放器密钥替换侮辱
而不是添加一个新的
关于这方面最佳方法的任何建议如下:
DynanoDB?是否需要为范围键创建混合列?
尽量保持这个简单
class func createDartsPlayerInsultTable() -> BFTask {
let dynamoDB = AWSDynamoDB.defaultDynamoDB()
let hashKeyAttributeDefinition = AWSDynamoDBAttributeDefinition()
hashKeyAttributeDefinition.attributeName = "CustomerId"
hashKeyAttributeDefinition.attributeType = AWSDynamoDBScalarAttributeType.S
let hashKeySchemaElement = AWSDynamoDBKeySchemaElement()
hashKeySchemaElement.attributeName = "CustomerId"
hashKeySchemaElement.keyType = AWSDynamoDBKeyType.Hash
let rangeKeyAttributeDefinition = AWSDynamoDBAttributeDefinition()
rangeKeyAttributeDefinition.attributeName = "PlayerId"
rangeKeyAttributeDefinition.attributeType = AWSDynamoDBScalarAttributeType.S
let rangeKeySchemaElement = AWSDynamoDBKeySchemaElement()
rangeKeySchemaElement.attributeName = "PlayerId"
rangeKeySchemaElement.keyType = AWSDynamoDBKeyType.Range
/*
let indexRangeKeyAttributeDefinition = AWSDynamoDBAttributeDefinition()
indexRangeKeyAttributeDefinition.attributeName = "PlayerInsult"
indexRangeKeyAttributeDefinition.attributeType = AWSDynamoDBScalarAttributeType.S
let rangeKeySchemaElement = AWSDynamoDBKeySchemaElement()
rangeKeySchemaElement.attributeName = "PlayerId"
rangeKeySchemaElement.keyType = AWSDynamoDBKeyType.Range
let indexRangeKeyElement = AWSDynamoDBKeySchemaElement()
indexRangeKeyElement.attributeName = "PlayerInsult"
indexRangeKeyElement.keyType = AWSDynamoDBIndexRangeKeyType.
*/
//Add non-key attributes
let playerInsultAttrDef = AWSDynamoDBAttributeDefinition()
playerInsultAttrDef.attributeName = "PlayerInsult"
playerInsultAttrDef.attributeType = AWSDynamoDBScalarAttributeType.S
let provisionedThroughput = AWSDynamoDBProvisionedThroughput()
provisionedThroughput.readCapacityUnits = 5
provisionedThroughput.writeCapacityUnits = 5
// CREATE GLOBAL SECONDARY INDEX
/*
let gsi = AWSDynamoDBGlobalSecondaryIndex()
let gsiArray = NSMutableArray()
let gsiHashKeySchema = AWSDynamoDBKeySchemaElement()
gsiHashKeySchema.attributeName = "PlayerId"
gsiHashKeySchema.keyType = AWSDynamoDBKeyType.Hash
let gsiRangeKeySchema = AWSDynamoDBKeySchemaElement()
gsiRangeKeySchema.attributeName = "PlayerInsult"
gsiRangeKeySchema.keyType = AWSDynamoDBKeyType.Range
let gsiProjection = AWSDynamoDBProjection()
gsiProjection.projectionType = AWSDynamoDBProjectionType.All;
gsi.keySchema = [gsiHashKeySchema,gsiRangeKeySchema];
gsi.indexName = "PlayerInsult";
gsi.projection = gsiProjection;
gsi.provisionedThroughput = provisionedThroughput;
gsiArray .addObject(gsi)
*/
// CREATE LOCAL SECONDARY INDEX
let lsi = AWSDynamoDBLocalSecondaryIndex()
let lsiArray = NSMutableArray()
let lsiHashKeySchema = AWSDynamoDBKeySchemaElement()
lsiHashKeySchema.attributeName = "CustomerId"
lsiHashKeySchema.keyType = AWSDynamoDBKeyType.Hash
let lsiRangeKeySchema = AWSDynamoDBKeySchemaElement()
lsiRangeKeySchema.attributeName = "PlayerInsult"
lsiRangeKeySchema.keyType = AWSDynamoDBKeyType.Range
let lsiProjection = AWSDynamoDBProjection()
lsiProjection.projectionType = AWSDynamoDBProjectionType.All;
lsi.keySchema = [lsiHashKeySchema,lsiRangeKeySchema];
lsi.indexName = "PlayerInsult";
lsi.projection = lsiProjection;
//lsi.provisionedThroughput = provisionedThroughput;
lsiArray .addObject(lsi)
//Create TableInput
let createTableInput = AWSDynamoDBCreateTableInput()
createTableInput.tableName = DartsPlayerInsultTableName;
createTableInput.attributeDefinitions = [hashKeyAttributeDefinition, rangeKeyAttributeDefinition, playerInsultAttrDef]
//createTableInput.attributeDefinitions = [hashKeyAttributeDefinition, rangeKeyAttributeDefinition]
createTableInput.keySchema = [hashKeySchemaElement, rangeKeySchemaElement]
createTableInput.provisionedThroughput = provisionedThroughput
//createTableInput.globalSecondaryIndexes = gsiArray as [AnyObject]
createTableInput.localSecondaryIndexes = lsiArray as [AnyObject]
return dynamoDB.createTable(createTableInput).continueWithSuccessBlock({ (var task:BFTask!) -> AnyObject! in
if ((task.result) != nil) {
// Wait for up to 4 minutes until the table becomes ACTIVE.
let describeTableInput = AWSDynamoDBDescribeTableInput()
describeTableInput.tableName = DartsPlayerInsultTableName;
task = dynamoDB.describeTable(describeTableInput)
for var i = 0; i < 16; i++ {
task = task.continueWithSuccessBlock({ (task:BFTask!) -> AnyObject! in
let describeTableOutput:AWSDynamoDBDescribeTableOutput = task.result as! AWSDynamoDBDescribeTableOutput
let tableStatus = describeTableOutput.table.tableStatus
if tableStatus == AWSDynamoDBTableStatus.Active {
return task
}
sleep(15)
return dynamoDB .describeTable(describeTableInput)
})
}
}
return task
})
}
class func createDartsPlayerInsultTable()->BFTask{
让dynamoDB=AWSDynamoDB.defaultDynamoDB()
让hashKeyAttributeDefinition=AWSDynamoDBAttributeDefinition()
hashKeyAttributeDefinition.attributeName=“CustomerId”
hashKeyAttributeDefinition.attributeType=AWSDynamodScalarAttributeType.S
设hashKeySchemaElement=awsdynamodKeySchemaElement()
hashKeySchemaElement.attributeName=“CustomerId”
hashKeySchemaElement.keyType=AWSDynamoDBKeyType.Hash
让rangeKeyAttributeDefinition=AWSDynamoDBAttributeDefinition()
rangeKeyAttributeDefinition.attributeName=“PlayerId”
rangeKeyAttributeDefinition.attributeType=AWSDynamodScalarAttributeType.S
让rangeKeySchemaElement=AWSDynamodKeySchemaElement()
rangeKeySchemaElement.attributeName=“PlayerId”
rangeKeySchemaElement.keyType=AWSDynamoDBKeyType.Range
/*
让indexRangeKeyAttributeDefinition=AWSDynamoDBAttributeDefinition()
indexRangeKeyAttributeDefinition.attributeName=“PlayerResult”
indexRangeKeyAttributeDefinition.attributeType=AWSDynamoDBScalarAttributeType.S
让rangeKeySchemaElement=AWSDynamodKeySchemaElement()
rangeKeySchemaElement.attributeName=“PlayerId”
rangeKeySchemaElement.keyType=AWSDynamoDBKeyType.Range
让indexRangeKeyElement=AWSDynamoDBKeySchemaElement()
indexRangeKeyElement.attributeName=“PlayerResult”
indexRangeKeyElement.keyType=AWSDynamodIndexRangeKeyType。
*/
//添加非关键属性
让playerInsultAttrDef=AWSDynamoDBAttributeDefinition()
playerInsultAttrDef.attributeName=“PlayerInsult”
playerInsultAttrDef.attributeType=awsDynamodsCalarAttributeType.S
let provisionedThroughput=awsdynamodprovisionedthroughput()
provisionedThroughput.readCapacityUnits=5
provisionedThroughput.writeCapacityUnits=5
//创建全局二级索引
/*
设gsi=awsdynamodGlobalSecondaryIndex()
设gsiArray=NSMutableArray()
设gsiHashKeySchema=AWSDynamoDBKeySchemaElement()
gsiHashKeySchema.attributeName=“PlayerId”
gsiHashKeySchema.keyType=AWSDynamoDBKeyType.Hash
设gsiRangeKeySchema=AWSDynamoDBKeySchemaElement()
gsiRangeKeySchema.attributeName=“playerSult”
gsiRangeKeySchema.keyType=AWSDynamoDBKeyType.Range
设gsiProjection=AWSDynamoDBProjection()
gsiProjection.projectionType=awsdynamodprojectionType.All;
gsi.keySchema=[gsiHashKeySchema,gsiRangeKeySchema];
gsi.indexName=“PlayerInsult”;
gsi.projection=gsi projection;
gsi.provisionedThroughput=provisionedThroughput;
gsiArray.addObject(gsi)
*/
//创建本地二级索引
设lsi=AWSDynamodLocalSecondaryIndex()
设lsiArray=NSMutableArray()
设lsiHashKeySchema=awsdynamodKeySchemaElement()
lsiHashKeySchema.attributeName=“CustomerId”
lsiHashKeySchema.keyType=AWSDynamoDBKeyType.Hash
设lsiRangeKeySchema=awsdynamodKeySchemaElement()
lsiRangeKeySchema.attributeName=“playerResult”
lsiRangeKeySchema.keyType=AWSDynamoDBKeyType.Range
设lsiProjection=AWSDynamoDBProjection()
lsiProjection.projectionType=AWSDynamodProjectionType.All;
lsi.keySchema=[lsiHashKeySchema,lsiRangeKeySchema];
lsi.indexName=“PlayerInsult”;
lsi.projection=lsi projection;
//lsi.provisionedThroughput=provisionedThroughput;
lsiArray.addObject(lsi)
//创建TableInput
让createTableInput=AWSDynamoDBCreateTableInput()
createTableInput.tableName=DartsPlayerSultTableName;
createTableInput.attributeDefinitions=[hashKeyAttributeDefinition,rangeKeyAttributeDefinition,playerInsultAttrDef]
//createTableInput.attributeDefinitions=[hashKeyAttributeDefinition,rangeKeyAttributeDefinition]
createTableInput.keySchema=[hashKeySchemaElement,rangeKeySchemaElement]
createTableInput.provisionedThroughput=provisionedThroughput
//createTableInput.GlobalSecondaryIndex=gsiArray as[AnyObject]
createTableInput.localSecondaryIndexes=lsiArray作为[AnyObject]
返回dynamoDB.createTable(createTableInput).continueWithSuccessBlock({(var-task:BFTask!)->AnyObject!in
如果((任务结果)!=nil){
//最多等待4分钟,直到桌子变为活动状态。
让DescriptableInput=AWSDynamodDescriptableInput()
describeTableInput.tableName=DartsPlayerSultTableName;
任务=发电机B.可描述(可描述输入)
对于变量i=0;i<16;i++{
task=task.continueWithSuccessBlock({(task:BFTask!)->中的AnyObject
让DescriptableOutput:AWSDynamodDescriptableOutput=task.result为!AWSDynamodDescriptableOutput
设tableStatus=describeTableOutput.table.tableStatus
如果tableStatus==AWSDynamoDBTableStatus.Active{
返回任务
}
睡眠(15)
返回发电机B.可描述(可描述输入)
})
}
}
返回任务
class func createDartsPlayerInsultTable() -> BFTask {
let dynamoDB = AWSDynamoDB.defaultDynamoDB()
let hashKeyAttributeDefinition = AWSDynamoDBAttributeDefinition()
hashKeyAttributeDefinition.attributeName = "CustomerId"
hashKeyAttributeDefinition.attributeType = AWSDynamoDBScalarAttributeType.S
let hashKeySchemaElement = AWSDynamoDBKeySchemaElement()
hashKeySchemaElement.attributeName = "CustomerId"
hashKeySchemaElement.keyType = AWSDynamoDBKeyType.Hash
let rangeKeyAttributeDefinition = AWSDynamoDBAttributeDefinition()
rangeKeyAttributeDefinition.attributeName = "PlayerId"
rangeKeyAttributeDefinition.attributeType = AWSDynamoDBScalarAttributeType.S
let rangeKeySchemaElement = AWSDynamoDBKeySchemaElement()
rangeKeySchemaElement.attributeName = "PlayerId"
rangeKeySchemaElement.keyType = AWSDynamoDBKeyType.Range
/*
let indexRangeKeyAttributeDefinition = AWSDynamoDBAttributeDefinition()
indexRangeKeyAttributeDefinition.attributeName = "PlayerInsult"
indexRangeKeyAttributeDefinition.attributeType = AWSDynamoDBScalarAttributeType.S
let rangeKeySchemaElement = AWSDynamoDBKeySchemaElement()
rangeKeySchemaElement.attributeName = "PlayerId"
rangeKeySchemaElement.keyType = AWSDynamoDBKeyType.Range
let indexRangeKeyElement = AWSDynamoDBKeySchemaElement()
indexRangeKeyElement.attributeName = "PlayerInsult"
indexRangeKeyElement.keyType = AWSDynamoDBIndexRangeKeyType.
*/
//Add non-key attributes
let playerInsultAttrDef = AWSDynamoDBAttributeDefinition()
playerInsultAttrDef.attributeName = "PlayerInsult"
playerInsultAttrDef.attributeType = AWSDynamoDBScalarAttributeType.S
let provisionedThroughput = AWSDynamoDBProvisionedThroughput()
provisionedThroughput.readCapacityUnits = 5
provisionedThroughput.writeCapacityUnits = 5
// CREATE GLOBAL SECONDARY INDEX
/*
let gsi = AWSDynamoDBGlobalSecondaryIndex()
let gsiArray = NSMutableArray()
let gsiHashKeySchema = AWSDynamoDBKeySchemaElement()
gsiHashKeySchema.attributeName = "PlayerId"
gsiHashKeySchema.keyType = AWSDynamoDBKeyType.Hash
let gsiRangeKeySchema = AWSDynamoDBKeySchemaElement()
gsiRangeKeySchema.attributeName = "PlayerInsult"
gsiRangeKeySchema.keyType = AWSDynamoDBKeyType.Range
let gsiProjection = AWSDynamoDBProjection()
gsiProjection.projectionType = AWSDynamoDBProjectionType.All;
gsi.keySchema = [gsiHashKeySchema,gsiRangeKeySchema];
gsi.indexName = "PlayerInsult";
gsi.projection = gsiProjection;
gsi.provisionedThroughput = provisionedThroughput;
gsiArray .addObject(gsi)
*/
// CREATE LOCAL SECONDARY INDEX
let lsi = AWSDynamoDBLocalSecondaryIndex()
let lsiArray = NSMutableArray()
let lsiHashKeySchema = AWSDynamoDBKeySchemaElement()
lsiHashKeySchema.attributeName = "CustomerId"
lsiHashKeySchema.keyType = AWSDynamoDBKeyType.Hash
let lsiRangeKeySchema = AWSDynamoDBKeySchemaElement()
lsiRangeKeySchema.attributeName = "PlayerInsult"
lsiRangeKeySchema.keyType = AWSDynamoDBKeyType.Range
let lsiProjection = AWSDynamoDBProjection()
lsiProjection.projectionType = AWSDynamoDBProjectionType.All;
lsi.keySchema = [lsiHashKeySchema,lsiRangeKeySchema];
lsi.indexName = "PlayerInsult";
lsi.projection = lsiProjection;
//lsi.provisionedThroughput = provisionedThroughput;
lsiArray .addObject(lsi)
//Create TableInput
let createTableInput = AWSDynamoDBCreateTableInput()
createTableInput.tableName = DartsPlayerInsultTableName;
createTableInput.attributeDefinitions = [hashKeyAttributeDefinition, rangeKeyAttributeDefinition, playerInsultAttrDef]
//createTableInput.attributeDefinitions = [hashKeyAttributeDefinition, rangeKeyAttributeDefinition]
createTableInput.keySchema = [hashKeySchemaElement, rangeKeySchemaElement]
createTableInput.provisionedThroughput = provisionedThroughput
//createTableInput.globalSecondaryIndexes = gsiArray as [AnyObject]
createTableInput.localSecondaryIndexes = lsiArray as [AnyObject]
return dynamoDB.createTable(createTableInput).continueWithSuccessBlock({ (var task:BFTask!) -> AnyObject! in
if ((task.result) != nil) {
// Wait for up to 4 minutes until the table becomes ACTIVE.
let describeTableInput = AWSDynamoDBDescribeTableInput()
describeTableInput.tableName = DartsPlayerInsultTableName;
task = dynamoDB.describeTable(describeTableInput)
for var i = 0; i < 16; i++ {
task = task.continueWithSuccessBlock({ (task:BFTask!) -> AnyObject! in
let describeTableOutput:AWSDynamoDBDescribeTableOutput = task.result as! AWSDynamoDBDescribeTableOutput
let tableStatus = describeTableOutput.table.tableStatus
if tableStatus == AWSDynamoDBTableStatus.Active {
return task
}
sleep(15)
return dynamoDB .describeTable(describeTableInput)
})
}
}
return task
})
}