Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hfcipriano opened this issue Feb 2, 2021 · 0 comments

Comments

@hfcipriano
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant