-
Notifications
You must be signed in to change notification settings - Fork 6
Obtaining partition key from value #13
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
Conversation
I may have this wrong, as new to Cosmos DB. Thank you for putting this emulator together, as I run everything Linux. I've been using the Java client to work with this emulator successfully, however can't get the readAllItems(partitionKey) to work. The above I believe is the fix, as there is no name attribute being provided. However, if something in the Java client I'm missing, happy to ignore this - though let me know what might be. Again, many thanks for putting this together.
Hi, thanks for your PR. Could you share how your partition key configuration on the container and the |
Java test code is as follows: CosmosDatabase database = ...;
// Create the container
database.createContainerIfNotExists(TestEntity.class.getSimpleName(), "/partition");
CosmosContainer container = database.getContainer(TestEntity.class.getSimpleName());
// Store in container
TestEntity entity = new TestEntity(UUID.randomUUID().toString(), "Test message");
container.createItem(entity);
// Retrieve all items from container (this triggers the failure, I'm believing this PR fixes)
long itemCount = container.readAllItems(new PartitionKey(new TestEntity().getPartition()), TestEntity.class)
.stream().count();
assertEquals(1, itemCount, "Should have the stored item"); with entity: @Data
@NoArgsConstructor
@AllArgsConstructor
public static class TestEntity {
private String id;
private String message;
private final String partition = "SINGLE";
} The readAllItems results in the following request: {"query":"SELECT * FROM c WHERE c[\"partition\"] = @pkValue","parameters":[{"name":"@pkValue","value":"SINGLE"}]} The PR is to fix to find the partition by node.property.value from the below JSON for node: {"type":"scalar_member_expression","object":{"type":"identifier","name":"c"},"property":{"type":"string_constant","value":"partition"},"computed":true} Now, must admit I'm still finding my feet with Cosmos DB. So very happy to be pointed out where I might be wrong. |
Note: I'm also wrapping the start/stop into a JUnit Extension / Rule so that it will start the emulator within NodeJS docker container. This can then be used for testing against. This is available at: https://github.com/officefloor/OfficeFloor/blob/master/officefloor/persistence/officenosql_cosmosdb_test To get the certificate issues resolved to connect, had to play with the internals to make the connection work: https://github.com/officefloor/OfficeFloor/blob/master/officefloor/persistence/officenosql_cosmosdb_test/src/main/java/net/officefloor/nosql/cosmosdb/test/AbstractCosmosDbJunit.java#L194 This allows tests as follows: https://github.com/officefloor/OfficeFloor/blob/master/officefloor/tutorials/CosmosDbHttpServer/src/test/java/net/officefloor/tutorial/cosmosdbhttpserver/CosmosDbHttpServerTest.java |
Thank you for the information. This PR makes a lot of sense 👍 Also thanks for sharing how you test Java code. Unfortunately there is no document how to use from non-node.js environment since we use only from node.js basically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!
Thanks for the info and thanks for merging :) This is only for testing (never for production). I'm always hesitant of tests creating side effects. The lessening of security in this case for running tests, is for me better than changing security for the whole JVM. But as this should only run on developers machine or CI servers, then possibly not that relevant. Thanks for the additional options though - will keep in mind, as finding the Java client from Azure not have many options for controlling this (compared to other cloud provider SDKs) :) |
I may have this wrong, as new to Cosmos DB. Thank you for putting this emulator together, as I run everything Linux. I've been using the Java client to work with this emulator successfully, however can't get the readAllItems(partitionKey) to work.
The above I believe is the fix, as there is no name attribute being provided.
However, if something in the Java client I'm missing, happy to ignore this - though let me know what might be.
Again, many thanks for putting this together.