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

[BUG] #43229

Open
Blackbaud-JasonBodnar opened this issue Dec 4, 2024 · 4 comments · May be fixed by #43239
Open

[BUG] #43229

Blackbaud-JasonBodnar opened this issue Dec 4, 2024 · 4 comments · May be fixed by #43239
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@Blackbaud-JasonBodnar
Copy link

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):

  • Library/Libraries: com.azure:azure-spring-data-cosmos:5.14.0
  • Java version: 17
  • Frameworks: Spring Boot

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

  • [ X ] Bug Description Added
  • [ X ] Repro Steps Added
  • [ X ] Setup information Added
@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. labels Dec 4, 2024
Copy link

github-actions bot commented Dec 4, 2024

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

@kushagraThapar
Copy link
Member

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

@trande4884 trande4884 self-assigned this Dec 5, 2024
@trande4884
Copy link
Member

trande4884 commented Dec 5, 2024

@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
Copy link
Author

@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;
    }

}

@trande4884 trande4884 linked a pull request Dec 19, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants