Skip to content

Why key querying are returning a list with null element instead a empty list? #213

Open
@hfcipriano

Description

@hfcipriano

When I invoke a repository method that makes a key search in dynamo:

enter image description here

"{"TableName":"music","Key":{"artist":{"S":"Djavan"},"title":{"S":"Tempo"}},"ConsistentRead":false}"

this is aws output:

"{}"

And when i invoke another methos that makes a find using sortKey start with:

enter image description here

this is sent to aws:

"{"TableName":"music","ConsistentRead":true,"KeyConditions":{"artist":{"AttributeValueList":[{"S":"Djavan"}],"ComparisonOperator":"EQ"},"title":{"AttributeValueList":[{"S":"Tempo"}],"ComparisonOperator":"BEGINS_WITH"}},"ScanIndexForward":true}"

and this is the return:

"{"Count":0,"Items":[],"ScannedCount":0}"

Steps to Reproduce the Problem

Using a entity named Music

@DynamoDBTable(tableName = "music")
data class Music(

        @get:DynamoDBHashKey(attributeName = "artist")
        var artist: String? = null,

        @get:DynamoDBRangeKey(attributeName = "title")
        var title: String? = null,

        var genre: String? = null
) {

    @Id
    private var id: MusicId? = null
        get() = MusicId(artist, title)
}

@DynamoDBDocument
data class MusicId(

        @field:DynamoDBHashKey(attributeName = "artist")
        var artist: String? = null,

        @field:DynamoDBRangeKey(attributeName = "title")
        var title: String? = null
) : Serializable

And a repository

interface MusicRepository : CrudRepository<Music, MusicId> {

    fun findByArtistAndTitle(artist: String, title: String): List<Music>

    fun findByArtistAndTitleStartingWith(artista: String, sortKey: String): List<Music>
}

And when i invoke:

@PostConstruct
    fun init() {
        println(musicRepository.findByArtistAndTitleStartingWith("Djavan", "Eu te devoro").joinToString())
    }

the log show's me the call to AWS as i showed above

Specifications

Stackoverflow question: https://stackoverflow.com/questions/65996950/why-spring-data-dynamodb-are-returning-a-list-with-null-element-instead-a-empty

Someone know if is there a clean way to guarantee that the dynamo repo will never return a list that only accepts non null elements, with null elements?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions