Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.37k stars 2k forks source link

[BUG] #43229

Open Blackbaud-JasonBodnar opened 22 hours ago

Blackbaud-JasonBodnar commented 22 hours ago

Describe the bug When executing a Cosmos NoSQL query with SUM() using a Spring Data repository a List is returned instead of an int or long

Exception or Stack Trace

java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.Long (java.util.ArrayList and java.lang.Long are in module java.base of loader 'bootstrap')
    at jdk.proxy3/jdk.proxy3.$Proxy172.findTotalCharactersTranslatedForLastMinute(Unknown Source)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)

To Reproduce Create a repository with a method that has a query that uses SUM()

Code Snippet

@Query(value = "SELECT VALUE SUM(c.totalCharacters) FROM c WHERE c.datetime >= @currentMinute")
 Long sumTotalCharactersTranslatedForLastMinute(OffsetDateTime currentMinute);

Expected behavior There should be no exception and a Long (or Long or Integer or int) should be returned. It works with COUNT():

@Query(
            value = "SELECT VALUE COUNT(1) FROM f " +
                    "WHERE ( " +
                    "EXISTS (SELECT VALUE f FROM f " +
                    "JOIN c IN f.formLayout.cards " +
                    "JOIN ow in c.widgets " +
                    "WHERE ow.includeOneTimeAmounts = true " +
                    "AND ow.recurringUpsellEnabled = true) " +
                    "OR EXISTS (SELECT VALUE f FROM f " +
                    "JOIN w in f.formLayout.widgets " +
                    "WHERE w.includeOneTimeAmounts = true " +
                    "AND w.recurringUpsellEnabled = true) " +
                    ") " +
                    "AND f.environmentId = @environmentId " +
                    "AND f.archived = false"
)
long countEligibleFormsWithRecurringUpsellEnabledByEnvironmentId(String environmentId);

Setup (please complete the following information):

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

github-actions[bot] commented 22 hours ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kushagraThapar @pjohari-ms @TheovanKraay.

kushagraThapar commented 22 hours ago

@trande4884 can you please take a look at this issue, thanks!

trande4884 commented 7 hours ago

@Blackbaud-JasonBodnar I am able to reproduce the issue, let me see what's going on and I will get back to you.

Blackbaud-JasonBodnar commented 6 hours ago
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Container(containerName = TranslationRequestEntity.COLLECTION_NAME)
public class TranslationRequestEntity implements Persistable<String> {

    public static final String COLLECTION_NAME = "translation_requests";
    public static int CURRENT_SCHEMA_VERSION = 1;

    @Id
    @GeneratedValue
    private String id;
    @Version
    private String version;
    @Builder.Default
    private int schemaVersion = CURRENT_SCHEMA_VERSION;

    private Long totalCharacters;
    private OffsetDateTime datetime;

    @Override
    public boolean isNew() {
        return id == null;
    }

}