Как сделать запрос DynamoDB с помощью DynamodbHashkeyIndex, DynamodbRangeKeyIndeax и других неключевых атрибутов - PullRequest
0 голосов
/ 19 февраля 2020

Может ли кто-нибудь помочь мне с запросом DynamoDB, используя ключ индекса * Ha sh, ключ диапазона индекса и 2 других неключевых атрибута. Я совершенно не в курсе этого варианта использования. Пожалуйста, извините, если это избыточный вопрос, задающий этот вопрос, так как я совершенно не понимаю этого варианта использования с DynamodB и не смог найти точный вопрос здесь

Структура таблицы:

var params = {
TableName: 'DocServiceTripData',
KeySchema: [ // The type of of schema.  Must start with a HASH type, with an optional second RANGE.
    { // Required HASH type attribute
        AttributeName: 'item_id',
        KeyType: 'HASH',
    }
],
AttributeDefinitions: [ // The names and types of all primary and index key attributes only
    {
        AttributeName: 'item_id',
        AttributeType: 'S', // (S | N | B) for string, number, binary
    },
    {
        AttributeName: 'vendor_id',
        AttributeType: 'N', // (S | N | B) for string, number, binary
    },
    {
        AttributeName: 'booking_datetime',
        AttributeType: 'S', // (S | N | B) for string, number, binary
    },
    {
        AttributeName: 'LOB',
        AttributeType: 'S', // (S | N | B) for string, number, binary
    },
    {
        AttributeName: 'Group_id',
        AttributeType: 'N', // (S | N | B) for string, number, binary
    },

    // ... more attributes ...
],
ProvisionedThroughput: { // required provisioned throughput for the table
    ReadCapacityUnits: 50, 
    WriteCapacityUnits: 50, 
},
GlobalSecondaryIndexes: [ // optional (list of GlobalSecondaryIndex)
    { 
        IndexName: 'vendor_id-booking_datetime-index', 
        KeySchema: [
            { // Required HASH type attribute
                AttributeName: 'vendor_id',
                KeyType: 'HASH',
            },
            { // Optional RANGE key type for HASH + RANGE secondary indexes
                AttributeName: 'booking_datetime', 
                KeyType: 'RANGE', 
            }
        ],
        Projection: { // attributes to project into the index
            ProjectionType: 'ALL'
            },

        ProvisionedThroughput: { // throughput to provision to the index
            ReadCapacityUnits: 50,
            WriteCapacityUnits: 50,
        },
    },
    // ... more global secondary indexes ...
]

}; dynamicodb.createTable (params, function (err, data) {if (err) pp Json (err); // произошла ошибка, иначе pp Json (data); // успешный ответ});

В коде java, который я написал,

@ DynamoDBTable (tableName = "DocServiceTripData")

publi c класс VendorIDBookingDateQuery {

@DynamoDBHashKey
@DynamoDBAttribute
@DynamoDBIndexHashKey(attributeName = "vendor_id", globalSecondaryIndexName="vendor_id-booking_datetime-index")
private Integer vendor;

public VendorIDBookingDateQuery(Integer vendor){
   this.vendor=vendor;

}


@DynamoDBIndexRangeKey(attributeName = "bookingdatetime", globalSecondaryIndexName="vendor_id-booking_datetime-index")
private String bookinddatetime;

public VendorIDBookingDateQuery(String vendor){
    this.bookinddatetime=bookinddatetime;

}

}

Но здесь я не могу запросить мой индекс, указав следующие условия

select * from DocServiceTripData where vendor_id=1 and booking_datetime between '2020-01-01' and '2020-02-01' and LOB='text' and Group_id in (1,2,3)
...