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

Aggregation query method should be able to return Slice and Stream #3543

Closed
mngphm opened this issue Jan 23, 2021 · 6 comments
Closed

Aggregation query method should be able to return Slice and Stream #3543

mngphm opened this issue Jan 23, 2021 · 6 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@mngphm
Copy link

mngphm commented Jan 23, 2021

No description provided.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 23, 2021
@christophstrobl
Copy link
Member

To serve a Page we'd have to do a count to get the total amount of results. This, in turn, will lead to an extended execution time and additional load on the server.
Returning a Slice on the other hand might be a feasible option as this would only require to load one additional document (later truncated) to indicate if there's more data available. We'd be happy to consider a PR going that direction.

@christophstrobl christophstrobl added status: ideal-for-contribution An issue that a contributor can help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 8, 2021
@divyajnu08
Copy link
Contributor

Hi Mark ,

Can I look into this issue ? It may take some time as I have to go through the aggregation code .

Thanks

@divyajnu08
Copy link
Contributor

divyajnu08 commented May 3, 2021

Hi Mark

I am stuck in setup of the code at my local.
This is what I did :
Check out the spring-data-mongodb - main branch
built the jar file , created a new project with the same jar file as a dependency.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>test</groupId>
	<artifactId>test</artifactId>
	<version>0.1</version>
	<properties>
		<java.version>15</java.version>
		<maven.compiler.source>1.8</maven.compiler.source>
 		<maven.compiler.target>1.8</maven.compiler.target>
	</properties>
	<dependencies>
		<dependency>
		    <groupId>org.springframework.data</groupId>
		    <artifactId>spring-data-mongodb</artifactId>
		    <version>3.3.0-SNAPSHOT</version>
		</dependency>
	</dependencies>
</project>

this is what i am getting as the error

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [SpringConfig]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/web/servlet/config/annotation/WebMvcConfigurer.class] cannot be opened because it does not exist
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112)

I think some more dependencies it is expecting , i tried to resolve this error but repeatedly dependencies are missing.
Can you please guide me how to setup the spring-data-mongodb project on local to make any change and test it ?
Thanks

@mp911de
Copy link
Member

mp911de commented May 3, 2021

I'd suggest sticking with Java 8 for now. WebMvcConfigurer isn't available from Spring Data MongoDB. Going to start.spring.io and generating an application from there is a good approach to start your application with a clean Spring context bootstrap.

@divyajnu08
Copy link
Contributor

divyajnu08 commented May 4, 2021

Hi Mark

Currently in the code it is possible to pass a pageable with sort option in the method annotated with aggregation. Like

@Aggregation( pipeline = {...})
public List<PersonAggregate> getPaginatedResult(Pageable page);

If we pass pageable in the method , it returns paged response.

but if we take return type as Slice , it doesnt work.

@Aggregation( pipeline = {...})
public Slice<PersonAggregate> getPaginatedResult(Pageable page);
org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Repository aggregation method 'getPaginatedResult' does not support 'Slice' return type. Please use eg. 'List' instead.
	at org.springframework.data.mongodb.repository.query.StringBasedAggregation.doExecute(StringBasedAggregation.java:80) ~[spring-data-mongodb-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
	at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:107) ~[spring-data-mongodb-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.5.0.jar:2.5.0]

Is that what we need to fix ? Aggregation should be able to return Sliced response.

@mp911de
Copy link
Member

mp911de commented May 5, 2021

StringBasedAggregation verifies currently return types and part of the ticket is to allow for paging. So yes, the check needs to be removed there.

@mp911de mp911de linked a pull request May 11, 2021 that will close this issue
4 tasks
@mp911de mp911de changed the title Aggregation annotation should be able to return a Page if you pass Pageable and Sort Aggregation query method should be able to return Slice and Stream May 11, 2021
@mp911de mp911de added type: enhancement A general enhancement and removed status: ideal-for-contribution An issue that a contributor can help us with labels May 11, 2021
@mp911de mp911de added this to the 3.3 M1 (2021.1.0) milestone May 11, 2021
mp911de added a commit that referenced this issue May 11, 2021
Let appendLimitAndOffsetIfPresent accept unary operators for adjusting limit/offset values instead of appendModifiedLimitAndOffsetIfPresent. Apply simple type extraction for Slice. Add support for aggregation result streaming.

Extend tests, add author tags, update docs.

See #3543.
Original pull request: #3645.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants