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

CosmosDBState - Add, as option, the partitionKey in QueryMethod #3227

Merged
merged 6 commits into from Jan 25, 2024

Conversation

luigirende
Copy link
Contributor

@luigirende luigirende commented Nov 15, 2023

Opportunity to add the partitionKey field in the metadata of the Query request (how it's done in the Set and Get method).
If the user adds the partitionKey in the query method, the database before filtering all the items that belongs to the same partitionKey value, used in the request; after applies the query defined in the request. In this case the cross partition will be disabled, so the scan of the item that the database will do in the container will be only for a subset of item, improving the performance

Description

Please explain the changes you've made

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[issue number]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation / Created issue in the https://github.com/dapr/docs/ repo: dapr/docs#[issue number]

@@ -92,8 +92,11 @@ func (p crossPartitionQueryPolicy) Do(req *policy.Request) (*http.Response, erro
// Check if we're performing a query
// In that case, remove the partitionkey header and enable cross-partition queries
if strings.ToLower(raw.Header.Get("x-ms-documentdb-query")) == "true" {
raw.Header.Add("x-ms-documentdb-query-enablecrosspartition", "true")
raw.Header.Del("x-ms-documentdb-partitionkey")
raw.Header.Add("x-ms-documentdb-query-enablecrosspartition", "True")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should be lowercase true the way it was before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into the if-clause you added. This header should only be added when the partition key is fake. You do not want to run expensive cross partition queries otherwise.

Copy link
Member

@berndverst berndverst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the idea is right, but some small correction on the details. When to add headers etc

Also please do not define the new feature key / capability. That is only intended for features which we (at least at some point in time) intend to support in all state stores.

Comment on lines 275 to 394
// Test for CosmosDB (filter test with partitionOnly) this query doesn't use the cross partition ( value from 2 different partitionKey %s-struct and %s-struct-2)
{
query: `
{
"filter": {
"OR": [
{
"EQ": {"message": "` + key + `test"}
},
{
"IN": {"message": ["test` + key + `", "dummy"]}
}
]
}
}
`,
metadata: map[string]string{
"partitionKey": fmt.Sprintf("%s-struct-2", key),
},
partitionOnly: true,
// The same query from previous test but return only item having the same partitionKey value (%s-struct-2) given in the metadata
results: []state.QueryItem{
{
Key: fmt.Sprintf("%s-struct-2", key),
Data: []byte(fmt.Sprintf(`{"message":"%stest"}`, key)),
},
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@berndverst I added PartitionKey as feature for doing this test; this scenario will be ok only for CosmosDB, because for the others states will return 2 items instead of 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Not ideal - but I can't at the moment think of a better way to do this either.

@luigirende luigirende force-pushed the cosmosdb-paritionkey-query branch 4 times, most recently from e3be222 to 6f57467 Compare December 5, 2023 17:03
Copy link
Member

@berndverst berndverst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally got around to merging your query operators PR.

Could you resolve the merge conflict here now and then we'll get this one merged also? :)

@luigirende
Copy link
Contributor Author

@berndverst done!

@berndverst
Copy link
Member

@luigirende I'll merge this. Can you please make sure to take ownership of this docs issue and make the docs PR? Otherwise nobody will know about this.

dapr/docs#3897

Use /assign on that issue.

@berndverst
Copy link
Member

/ok-to-test

@dapr-bot
Copy link
Collaborator

dapr-bot commented Dec 11, 2023

Components certification test

🔗 Link to Action run

Commit ref: 45f3b74

❌ Some certification tests failed

These tests failed:

  • pubsub.gcp.pubsub

@dapr-bot
Copy link
Collaborator

Complete Build Matrix

The build status is currently not updated here. Please visit the action run below directly.

🔗 Link to Action run

Commit ref: 45f3b74

@dapr-bot
Copy link
Collaborator

dapr-bot commented Dec 11, 2023

Components conformance test

🔗 Link to Action run

Commit ref: 45f3b74

❌ Some conformance tests failed

These tests failed:

  • state.azure.cosmosdb
  • state.postgresql.azure

Copy link
Member

@berndverst berndverst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CosmosDB conformance test is failing.

@luigirende
Copy link
Contributor Author

luigirende commented Dec 12, 2023

The CosmosDB conformance test is failing.

Hi @berndverst

I think there has been an issue with azure tests. In fact fails also the azure postgresql tes and in this PR I haven't done any change on postgresql state.
Looking at the test log seems the dbs (cosmosdb and postgresql) weren't empty, when run the tests, in fact, the query find other keys store previously.

    	Error Trace:	/home/runner/work/components-contrib/components-contrib/tests/conformance/state/state.go:478
    	Error:      	Not equal: 
    	            	expected: "1fa86a779a7d49f0ba1a15fe7ce75f01-struct-operations"
    	            	actual  : "429bcb9db8d04c8da420d686492f0239-struct-operations"

Can you do a check or test again the PR?

@berndverst
Copy link
Member

The CosmosDB conformance test is failing.

Hi @berndverst

I think there has been an issue with azure tests. In fact fails also the azure postgresql tes and in this PR I haven't done any change on postgresql state. Looking at the test log seems the dbs (cosmosdb and postgresql) weren't empty, when run the tests, in fact, the query find other keys store previously.

    	Error Trace:	/home/runner/work/components-contrib/components-contrib/tests/conformance/state/state.go:478
    	Error:      	Not equal: 
    	            	expected: "1fa86a779a7d49f0ba1a15fe7ce75f01-struct-operations"
    	            	actual  : "429bcb9db8d04c8da420d686492f0239-struct-operations"

Can you do a check or test again the PR?

@luigirende I think this because of your other PR which is now merged, but you also must keep in mind that multiple tests might be running in parallel. Your test must work in that situation!

When the test starts it uses a unique prefix for the test run. So you need to write your test such that it will only look for the results with this particular prefix.

Also keep in mind you still have a conflict in state/feature.go.

@luigirende
Copy link
Contributor Author

@berndverst merged the conflict in state/feature.go and fix the issue in the conformance tests

@luigirende luigirende force-pushed the cosmosdb-paritionkey-query branch 3 times, most recently from a2dc965 to 5ca1b69 Compare January 9, 2024 13:54
luigirende and others added 4 commits January 11, 2024 15:25
…data request for the Query Method (uniform with Set and Get). Disabling the cross partition

Signed-off-by: luigirende <luigirende@gmail.com>
Signed-off-by: Luigi Rende <luigirende@gmail.com>
Signed-off-by: Bernd Verst <github@bernd.dev>
Signed-off-by: Luigi Rende <luigirende@gmail.com>
@berndverst
Copy link
Member

/ok-to-test

@dapr-bot
Copy link
Collaborator

Complete Build Matrix

The build status is currently not updated here. Please visit the action run below directly.

🔗 Link to Action run

Commit ref: c1f2bdf

@dapr-bot
Copy link
Collaborator

dapr-bot commented Jan 17, 2024

Components certification test

🔗 Link to Action run

Commit ref: c1f2bdf

❌ Some certification tests failed

These tests failed:

  • bindings.azure.servicebusqueues
  • pubsub.mqtt3

@dapr-bot
Copy link
Collaborator

dapr-bot commented Jan 17, 2024

Components conformance test

🔗 Link to Action run

Commit ref: c1f2bdf

❌ Some conformance tests failed

These tests failed:

  • pubsub.kafka-confluent

@berndverst
Copy link
Member

/ok-to-test

@dapr-bot
Copy link
Collaborator

Complete Build Matrix

The build status is currently not updated here. Please visit the action run below directly.

🔗 Link to Action run

Commit ref: 46a5d05

@dapr-bot
Copy link
Collaborator

dapr-bot commented Jan 25, 2024

Components conformance test

🔗 Link to Action run

Commit ref: 46a5d05

✅ All conformance tests passed

All tests have reported a successful status

@dapr-bot
Copy link
Collaborator

dapr-bot commented Jan 25, 2024

Components certification test

🔗 Link to Action run

Commit ref: 46a5d05

❌ Some certification tests failed

These tests failed:

  • bindings.azure.eventhubs
  • bindings.azure.servicebusqueues
  • bindings.azure.storagequeues
  • pubsub.azure.eventhubs
  • pubsub.azure.servicebus.topics
  • pubsub.mqtt3

@berndverst berndverst merged commit 120a649 into dapr:main Jan 25, 2024
88 of 89 checks passed
@berndverst berndverst added this to the v1.13 milestone Jan 25, 2024
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

Successfully merging this pull request may close these issues.

None yet

3 participants