From 4c35bf79dcb2235e679303b69df4ee93196623cd Mon Sep 17 00:00:00 2001 From: LangChain4j Date: Wed, 21 Aug 2024 15:51:34 +0200 Subject: [PATCH] 1505-feature-chroma-support-metadata-filtering (#1556) Fixed merge conflict --- .../EmbeddingStoreWithFilteringIT.java | 1121 ----------------- 1 file changed, 1121 deletions(-) diff --git a/langchain4j-core/src/test/java/dev/langchain4j/store/embedding/EmbeddingStoreWithFilteringIT.java b/langchain4j-core/src/test/java/dev/langchain4j/store/embedding/EmbeddingStoreWithFilteringIT.java index cf9381c2aa2..30f6e0922ba 100644 --- a/langchain4j-core/src/test/java/dev/langchain4j/store/embedding/EmbeddingStoreWithFilteringIT.java +++ b/langchain4j-core/src/test/java/dev/langchain4j/store/embedding/EmbeddingStoreWithFilteringIT.java @@ -1116,1127 +1116,6 @@ private void shouldFilter( matches.forEach(match -> assertThat(match.score()).isCloseTo(1, withPercentage(0.01))); } - protected static Stream should_filter_by_metadata() { - return Stream.builder() - - - // === Equal === - - .add(Arguments.of( - metadataKey("key").isEqualTo("a"), - asList( - new Metadata().put("key", "a"), - new Metadata().put("key", "a").put("key2", "b") - ), - asList( - new Metadata().put("key", "A"), - new Metadata().put("key", "b"), - new Metadata().put("key", "aa"), - new Metadata().put("key", "a a"), - new Metadata().put("key2", "a") - ) - )) - .add(Arguments.of( - metadataKey("key").isEqualTo(TEST_UUID), - asList( - new Metadata().put("key", TEST_UUID), - new Metadata().put("key", TEST_UUID).put("key2", "b") - ), - asList( - new Metadata().put("key", UUID.randomUUID()), - new Metadata().put("key2", TEST_UUID) - ) - )) - .add(Arguments.of( - metadataKey("key").isEqualTo(1), - asList( - new Metadata().put("key", 1), - new Metadata().put("key", 1).put("key2", 0) - ), - asList( - new Metadata().put("key", -1), - new Metadata().put("key", 0), - new Metadata().put("key2", 1) - ) - )) - .add(Arguments.of( - metadataKey("key").isEqualTo(1L), - asList( - new Metadata().put("key", 1L), - new Metadata().put("key", 1L).put("key2", 0L) - ), - asList( - new Metadata().put("key", -1L), - new Metadata().put("key", 0L), - new Metadata().put("key2", 1L) - ) - )) - .add(Arguments.of( - metadataKey("key").isEqualTo(1.23f), - asList( - new Metadata().put("key", 1.23f), - new Metadata().put("key", 1.23f).put("key2", 0f) - ), - asList( - new Metadata().put("key", -1.23f), - new Metadata().put("key", 1.22f), - new Metadata().put("key", 1.24f), - new Metadata().put("key2", 1.23f) - ) - )).add(Arguments.of( - metadataKey("key").isEqualTo(1.23d), - asList( - new Metadata().put("key", 1.23d), - new Metadata().put("key", 1.23d).put("key2", 0d) - ), - asList( - new Metadata().put("key", -1.23d), - new Metadata().put("key", 1.22d), - new Metadata().put("key", 1.24d), - new Metadata().put("key2", 1.23d) - ) - )) - - - // === GreaterThan == - - .add(Arguments.of( - metadataKey("key").isGreaterThan("b"), - asList( - new Metadata().put("key", "c"), - new Metadata().put("key", "c").put("key2", "a") - ), - asList( - new Metadata().put("key", "a"), - new Metadata().put("key", "b"), - new Metadata().put("key2", "c") - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThan(1), - asList( - new Metadata().put("key", 2), - new Metadata().put("key", 2).put("key2", 0) - ), - asList( - new Metadata().put("key", -2), - new Metadata().put("key", 0), - new Metadata().put("key", 1), - new Metadata().put("key2", 2) - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThan(1L), - asList( - new Metadata().put("key", 2L), - new Metadata().put("key", 2L).put("key2", 0L) - ), - asList( - new Metadata().put("key", -2L), - new Metadata().put("key", 0L), - new Metadata().put("key", 1L), - new Metadata().put("key2", 2L) - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThan(1.1f), - asList( - new Metadata().put("key", 1.2f), - new Metadata().put("key", 1.2f).put("key2", 1.0f) - ), - asList( - new Metadata().put("key", -1.2f), - new Metadata().put("key", 0.0f), - new Metadata().put("key", 1.1f), - new Metadata().put("key2", 1.2f) - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThan(1.1d), - asList( - new Metadata().put("key", 1.2d), - new Metadata().put("key", 1.2d).put("key2", 1.0d) - ), - asList( - new Metadata().put("key", -1.2d), - new Metadata().put("key", 0.0d), - new Metadata().put("key", 1.1d), - new Metadata().put("key2", 1.2d) - ) - )) - - - // === GreaterThanOrEqual == - - .add(Arguments.of( - metadataKey("key").isGreaterThanOrEqualTo("b"), - asList( - new Metadata().put("key", "b"), - new Metadata().put("key", "c"), - new Metadata().put("key", "c").put("key2", "a") - ), - asList( - new Metadata().put("key", "a"), - new Metadata().put("key2", "b") - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThanOrEqualTo(1), - asList( - new Metadata().put("key", 1), - new Metadata().put("key", 2), - new Metadata().put("key", 2).put("key2", 0) - ), - asList( - new Metadata().put("key", -2), - new Metadata().put("key", -1), - new Metadata().put("key", 0), - new Metadata().put("key2", 1), - new Metadata().put("key2", 2) - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThanOrEqualTo(1L), - asList( - new Metadata().put("key", 1L), - new Metadata().put("key", 2L), - new Metadata().put("key", 2L).put("key2", 0L) - ), - asList( - new Metadata().put("key", -2L), - new Metadata().put("key", -1L), - new Metadata().put("key", 0L), - new Metadata().put("key2", 1L), - new Metadata().put("key2", 2L) - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThanOrEqualTo(1.1f), - asList( - new Metadata().put("key", 1.1f), - new Metadata().put("key", 1.2f), - new Metadata().put("key", 1.2f).put("key2", 1.0f) - ), - asList( - new Metadata().put("key", -1.2f), - new Metadata().put("key", -1.1f), - new Metadata().put("key", 0.0f), - new Metadata().put("key2", 1.1f), - new Metadata().put("key2", 1.2f) - ) - )) - .add(Arguments.of( - metadataKey("key").isGreaterThanOrEqualTo(1.1d), - asList( - new Metadata().put("key", 1.1d), - new Metadata().put("key", 1.2d), - new Metadata().put("key", 1.2d).put("key2", 1.0d) - ), - asList( - new Metadata().put("key", -1.2d), - new Metadata().put("key", -1.1d), - new Metadata().put("key", 0.0d), - new Metadata().put("key2", 1.1d), - new Metadata().put("key2", 1.2d) - ) - )) - - - // === LessThan == - - .add(Arguments.of( - metadataKey("key").isLessThan("b"), - asList( - - new Metadata().put("key", "a"), - new Metadata().put("key", "a").put("key2", "c") - ), - asList( - new Metadata().put("key", "b"), - new Metadata().put("key", "c"), - new Metadata().put("key2", "a") - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThan(1), - asList( - new Metadata().put("key", -2), - new Metadata().put("key", 0), - new Metadata().put("key", 0).put("key2", 2) - ), - asList( - new Metadata().put("key", 1), - new Metadata().put("key", 2), - new Metadata().put("key2", 0) - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThan(1L), - asList( - new Metadata().put("key", -2L), - new Metadata().put("key", 0L), - new Metadata().put("key", 0L).put("key2", 2L) - ), - asList( - new Metadata().put("key", 1L), - new Metadata().put("key", 2L), - new Metadata().put("key2", 0L) - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThan(1.1f), - asList( - new Metadata().put("key", -1.2f), - new Metadata().put("key", 1.0f), - new Metadata().put("key", 1.0f).put("key2", 1.2f) - ), - asList( - new Metadata().put("key", 1.1f), - new Metadata().put("key", 1.2f), - new Metadata().put("key2", 1.0f) - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThan(1.1d), - asList( - new Metadata().put("key", -1.2d), - new Metadata().put("key", 1.0d), - new Metadata().put("key", 1.0d).put("key2", 1.2d) - ), - asList( - new Metadata().put("key", 1.1d), - new Metadata().put("key", 1.2d), - new Metadata().put("key2", 1.0d) - ) - )) - - - // === LessThanOrEqual == - - .add(Arguments.of( - metadataKey("key").isLessThanOrEqualTo("b"), - asList( - - new Metadata().put("key", "a"), - new Metadata().put("key", "b"), - new Metadata().put("key", "b").put("key2", "c") - ), - asList( - new Metadata().put("key", "c"), - new Metadata().put("key2", "a") - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThanOrEqualTo(1), - asList( - new Metadata().put("key", -2), - new Metadata().put("key", 0), - new Metadata().put("key", 1), - new Metadata().put("key", 1).put("key2", 2) - ), - asList( - new Metadata().put("key", 2), - new Metadata().put("key2", 0) - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThanOrEqualTo(1L), - asList( - new Metadata().put("key", -2L), - new Metadata().put("key", 0L), - new Metadata().put("key", 1L), - new Metadata().put("key", 1L).put("key2", 2L) - ), - asList( - new Metadata().put("key", 2L), - new Metadata().put("key2", 0L) - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThanOrEqualTo(1.1f), - asList( - new Metadata().put("key", -1.2f), - new Metadata().put("key", 1.0f), - new Metadata().put("key", 1.1f), - new Metadata().put("key", 1.1f).put("key2", 1.2f) - ), - asList( - new Metadata().put("key", 1.2f), - new Metadata().put("key2", 1.0f) - ) - )) - .add(Arguments.of( - metadataKey("key").isLessThanOrEqualTo(1.1d), - asList( - new Metadata().put("key", -1.2d), - new Metadata().put("key", 1.0d), - new Metadata().put("key", 1.1d), - new Metadata().put("key", 1.1d).put("key2", 1.2d) - ), - asList( - new Metadata().put("key", 1.2d), - new Metadata().put("key2", 1.0d) - ) - )) - - - // === In === - - // In: string - .add(Arguments.of( - metadataKey("name").isIn("Klaus"), - asList( - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("age", 42) - ), - asList( - new Metadata().put("name", "Klaus Heisler"), - new Metadata().put("name", "Alice"), - new Metadata().put("name2", "Klaus") - ) - )) - .add(Arguments.of( - metadataKey("name").isIn(singletonList("Klaus")), - asList( - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("age", 42) - ), - asList( - new Metadata().put("name", "Klaus Heisler"), - new Metadata().put("name", "Alice"), - new Metadata().put("name2", "Klaus") - ) - )) - .add(Arguments.of( - metadataKey("name").isIn("Klaus", "Alice"), - asList( - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Alice"), - new Metadata().put("name", "Alice").put("age", 42) - ), - asList( - new Metadata().put("name", "Klaus Heisler"), - new Metadata().put("name", "Zoe"), - new Metadata().put("name2", "Klaus") - ) - )) - .add(Arguments.of( - metadataKey("name").isIn(asList("Klaus", "Alice")), - asList( - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Alice"), - new Metadata().put("name", "Alice").put("age", 42) - ), - asList( - new Metadata().put("name", "Klaus Heisler"), - new Metadata().put("name", "Zoe"), - new Metadata().put("name2", "Klaus") - ) - )) - - // In: UUID - .add(Arguments.of( - metadataKey("name").isIn(TEST_UUID), - asList( - new Metadata().put("name", TEST_UUID), - new Metadata().put("name", TEST_UUID).put("age", 42) - ), - asList( - new Metadata().put("name", UUID.randomUUID()), - new Metadata().put("name2", TEST_UUID) - ) - )) - .add(Arguments.of( - metadataKey("name").isIn(singletonList(TEST_UUID)), - asList( - new Metadata().put("name", TEST_UUID), - new Metadata().put("name", TEST_UUID).put("age", 42) - ), - asList( - new Metadata().put("name", UUID.randomUUID()), - new Metadata().put("name2", TEST_UUID) - ) - )) - .add(Arguments.of( - metadataKey("name").isIn(TEST_UUID, TEST_UUID2), - asList( - new Metadata().put("name", TEST_UUID), - new Metadata().put("name", TEST_UUID).put("age", 42), - new Metadata().put("name", TEST_UUID2), - new Metadata().put("name", TEST_UUID2).put("age", 42) - ), - asList( - new Metadata().put("name", UUID.randomUUID()), - new Metadata().put("name2", TEST_UUID) - ) - )) - .add(Arguments.of( - metadataKey("name").isIn(asList(TEST_UUID, TEST_UUID2)), - asList( - new Metadata().put("name", TEST_UUID), - new Metadata().put("name", TEST_UUID).put("age", 42), - new Metadata().put("name", TEST_UUID2), - new Metadata().put("name", TEST_UUID2).put("age", 42) - ), - asList( - new Metadata().put("name", UUID.randomUUID()), - new Metadata().put("name2", TEST_UUID) - ) - )) - - // In: integer - .add(Arguments.of( - metadataKey("age").isIn(42), - asList( - new Metadata().put("age", 42), - new Metadata().put("age", 42).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666), - new Metadata().put("age2", 42) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(singletonList(42)), - asList( - new Metadata().put("age", 42), - new Metadata().put("age", 42).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666), - new Metadata().put("age2", 42) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(42, 18), - asList( - new Metadata().put("age", 42), - new Metadata().put("age", 18), - new Metadata().put("age", 42).put("name", "Klaus"), - new Metadata().put("age", 18).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666), - new Metadata().put("age2", 42) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(asList(42, 18)), - asList( - new Metadata().put("age", 42), - new Metadata().put("age", 18), - new Metadata().put("age", 42).put("name", "Klaus"), - new Metadata().put("age", 18).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666), - new Metadata().put("age2", 42) - ) - )) - - // In: long - .add(Arguments.of( - metadataKey("age").isIn(42L), - asList( - new Metadata().put("age", 42L), - new Metadata().put("age", 42L).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666L), - new Metadata().put("age2", 42L) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(singletonList(42L)), - asList( - new Metadata().put("age", 42L), - new Metadata().put("age", 42L).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666L), - new Metadata().put("age2", 42L) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(42L, 18L), - asList( - new Metadata().put("age", 42L), - new Metadata().put("age", 18L), - new Metadata().put("age", 42L).put("name", "Klaus"), - new Metadata().put("age", 18L).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666L), - new Metadata().put("age2", 42L) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(asList(42L, 18L)), - asList( - new Metadata().put("age", 42L), - new Metadata().put("age", 18L), - new Metadata().put("age", 42L).put("name", "Klaus"), - new Metadata().put("age", 18L).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666L), - new Metadata().put("age2", 42L) - ) - )) - - // In: float - .add(Arguments.of( - metadataKey("age").isIn(42.0f), - asList( - new Metadata().put("age", 42.0f), - new Metadata().put("age", 42.0f).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0f), - new Metadata().put("age2", 42.0f) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(singletonList(42.0f)), - asList( - new Metadata().put("age", 42.0f), - new Metadata().put("age", 42.0f).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0f), - new Metadata().put("age2", 42.0f) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(42.0f, 18.0f), - asList( - new Metadata().put("age", 42.0f), - new Metadata().put("age", 18.0f), - new Metadata().put("age", 42.0f).put("name", "Klaus"), - new Metadata().put("age", 18.0f).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0f), - new Metadata().put("age2", 42.0f) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(asList(42.0f, 18.0f)), - asList( - new Metadata().put("age", 42.0f), - new Metadata().put("age", 18.0f), - new Metadata().put("age", 42.0f).put("name", "Klaus"), - new Metadata().put("age", 18.0f).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0f), - new Metadata().put("age2", 42.0f) - ) - )) - - // In: double - .add(Arguments.of( - metadataKey("age").isIn(42.0d), - asList( - new Metadata().put("age", 42.0d), - new Metadata().put("age", 42.0d).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0d), - new Metadata().put("age2", 42.0d) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(singletonList(42.0d)), - asList( - new Metadata().put("age", 42.0d), - new Metadata().put("age", 42.0d).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0d), - new Metadata().put("age2", 42.0d) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(42.0d, 18.0d), - asList( - new Metadata().put("age", 42.0d), - new Metadata().put("age", 18.0d), - new Metadata().put("age", 42.0d).put("name", "Klaus"), - new Metadata().put("age", 18.0d).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0d), - new Metadata().put("age2", 42.0d) - ) - )) - .add(Arguments.of( - metadataKey("age").isIn(asList(42.0d, 18.0d)), - asList( - new Metadata().put("age", 42.0d), - new Metadata().put("age", 18.0d), - new Metadata().put("age", 42.0d).put("name", "Klaus"), - new Metadata().put("age", 18.0d).put("name", "Klaus") - ), - asList( - new Metadata().put("age", 666.0d), - new Metadata().put("age2", 42.0d) - ) - )) - - - // === Or === - - // Or: one key - .add(Arguments.of( - or( - metadataKey("name").isEqualTo("Klaus"), - metadataKey("name").isEqualTo("Alice") - ), - asList( - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Alice"), - new Metadata().put("name", "Alice").put("age", 42) - ), - singletonList( - new Metadata().put("name", "Zoe") - ) - )) - .add(Arguments.of( - or( - metadataKey("name").isEqualTo("Alice"), - metadataKey("name").isEqualTo("Klaus") - ), - asList( - new Metadata().put("name", "Alice"), - new Metadata().put("name", "Alice").put("age", 42), - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("age", 42) - ), - singletonList( - new Metadata().put("name", "Zoe") - ) - )) - - // Or: multiple keys - .add(Arguments.of( - or( - metadataKey("name").isEqualTo("Klaus"), - metadataKey("age").isEqualTo(42) - ), - asList( - // only Or.left is present and true - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("city", "Munich"), - - // Or.left is true, Or.right is false - new Metadata().put("name", "Klaus").put("age", 666), - - // only Or.right is present and true - new Metadata().put("age", 42), - new Metadata().put("age", 42).put("city", "Munich"), - - // Or.right is true, Or.left is false - new Metadata().put("age", 42).put("name", "Alice"), - - // Or.left and Or.right are both true - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich") - ), - asList( - new Metadata().put("name", "Alice"), - new Metadata().put("age", 666), - new Metadata().put("name", "Alice").put("age", 666) - ) - )) - .add(Arguments.of( - or( - metadataKey("age").isEqualTo(42), - metadataKey("name").isEqualTo("Klaus") - ), - asList( - // only Or.left is present and true - new Metadata().put("age", 42), - new Metadata().put("age", 42).put("city", "Munich"), - - // Or.left is true, Or.right is false - new Metadata().put("age", 42).put("name", "Alice"), - - // only Or.right is present and true - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("city", "Munich"), - - // Or.right is true, Or.left is false - new Metadata().put("name", "Klaus").put("age", 666), - - // Or.left and Or.right are both true - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich") - ), - asList( - new Metadata().put("name", "Alice"), - new Metadata().put("age", 666), - new Metadata().put("name", "Alice").put("age", 666) - ) - )) - - // Or: x2 - .add(Arguments.of( - or( - metadataKey("name").isEqualTo("Klaus"), - or( - metadataKey("age").isEqualTo(42), - metadataKey("city").isEqualTo("Munich") - ) - ), - asList( - // only Or.left is present and true - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("country", "Germany"), - - // Or.left is true, Or.right is false - new Metadata().put("name", "Klaus").put("age", 666), - new Metadata().put("name", "Klaus").put("city", "Frankfurt"), - new Metadata().put("name", "Klaus").put("age", 666).put("city", "Frankfurt"), - - // only Or.right is present and true - new Metadata().put("age", 42), - new Metadata().put("age", 42).put("country", "Germany"), - new Metadata().put("city", "Munich"), - new Metadata().put("city", "Munich").put("country", "Germany"), - new Metadata().put("age", 42).put("city", "Munich"), - new Metadata().put("age", 42).put("city", "Munich").put("country", "Germany"), - - // Or.right is true, Or.left is false - new Metadata().put("age", 42).put("name", "Alice"), - new Metadata().put("city", "Munich").put("name", "Alice"), - new Metadata().put("age", 42).put("city", "Munich").put("name", "Alice"), - - // Or.left and Or.right are both true - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("country", "Germany"), - new Metadata().put("name", "Klaus").put("city", "Munich"), - new Metadata().put("name", "Klaus").put("city", "Munich").put("country", "Germany"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich").put("country", "Germany") - ), - asList( - new Metadata().put("name", "Alice"), - new Metadata().put("age", 666), - new Metadata().put("city", "Frankfurt"), - new Metadata().put("name", "Alice").put("age", 666), - new Metadata().put("name", "Alice").put("city", "Frankfurt"), - new Metadata().put("name", "Alice").put("age", 666).put("city", "Frankfurt") - ) - )) - .add(Arguments.of( - or( - or( - metadataKey("name").isEqualTo("Klaus"), - metadataKey("age").isEqualTo(42) - ), - metadataKey("city").isEqualTo("Munich") - ), - asList( - // only Or.left is present and true - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("country", "Germany"), - new Metadata().put("age", 42), - new Metadata().put("age", 42).put("country", "Germany"), - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("country", "Germany"), - - // Or.left is true, Or.right is false - new Metadata().put("name", "Klaus").put("city", "Frankfurt"), - new Metadata().put("age", 42).put("city", "Frankfurt"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Frankfurt"), - - // only Or.right is present and true - new Metadata().put("city", "Munich"), - new Metadata().put("city", "Munich").put("country", "Germany"), - - // Or.right is true, Or.left is false - new Metadata().put("city", "Munich").put("name", "Alice"), - new Metadata().put("city", "Munich").put("age", 666), - - // Or.left and Or.right are both true - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("country", "Germany"), - new Metadata().put("name", "Klaus").put("city", "Munich"), - new Metadata().put("name", "Klaus").put("city", "Munich").put("country", "Germany"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich").put("country", "Germany") - ), - asList( - new Metadata().put("name", "Alice"), - new Metadata().put("age", 666), - new Metadata().put("city", "Frankfurt"), - new Metadata().put("name", "Alice").put("age", 666), - new Metadata().put("name", "Alice").put("city", "Frankfurt"), - new Metadata().put("name", "Alice").put("age", 666).put("city", "Frankfurt") - ) - )) - - // === AND === - - .add(Arguments.of( - and( - metadataKey("name").isEqualTo("Klaus"), - metadataKey("age").isEqualTo(42) - ), - asList( - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich") - ), - asList( - // only And.left is present and true - new Metadata().put("name", "Klaus"), - - // And.left is true, And.right is false - new Metadata().put("name", "Klaus").put("age", 666), - - // only And.right is present and true - new Metadata().put("age", 42), - - // And.right is true, And.left is false - new Metadata().put("age", 42).put("name", "Alice"), - - // And.left, And.right are both false - new Metadata().put("age", 666).put("name", "Alice") - ) - )) - .add(Arguments.of( - and( - metadataKey("age").isEqualTo(42), - metadataKey("name").isEqualTo("Klaus") - ), - asList( - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich") - ), - asList( - // only And.left is present and true - new Metadata().put("age", 42), - - // And.left is true, And.right is false - new Metadata().put("age", 42).put("name", "Alice"), - - // only And.right is present and true - new Metadata().put("name", "Klaus"), - - // And.right is true, And.left is false - new Metadata().put("name", "Klaus").put("age", 666), - - // And.left, And.right are both false - new Metadata().put("age", 666).put("name", "Alice") - ) - )) - - // And: x2 - .add(Arguments.of( - and( - metadataKey("name").isEqualTo("Klaus"), - and( - metadataKey("age").isEqualTo(42), - metadataKey("city").isEqualTo("Munich") - ) - ), - asList( - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich").put("country", "Germany") - ), - asList( - // only And.left is present and true - new Metadata().put("name", "Klaus"), - - // And.left is true, And.right is false - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 666).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Frankfurt"), - - // only And.right is present and true - new Metadata().put("age", 42).put("city", "Munich"), - - // And.right is true, And.left is false - new Metadata().put("age", 42).put("city", "Munich").put("name", "Alice") - ) - )) - .add(Arguments.of( - and( - and( - metadataKey("name").isEqualTo("Klaus"), - metadataKey("age").isEqualTo(42) - ), - metadataKey("city").isEqualTo("Munich") - ), - asList( - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich").put("country", "Germany") - ), - asList( - // only And.left is present and true - new Metadata().put("name", "Klaus").put("age", 42), - - // And.left is true, And.right is false - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Frankfurt"), - - // only And.right is present and true - new Metadata().put("city", "Munich"), - - // And.right is true, And.left is false - new Metadata().put("city", "Munich").put("name", "Klaus"), - new Metadata().put("city", "Munich").put("name", "Klaus").put("age", 666), - new Metadata().put("city", "Munich").put("age", 42), - new Metadata().put("city", "Munich").put("age", 42).put("name", "Alice") - ) - )) - - // === AND + nested OR === - - .add(Arguments.of( - and( - metadataKey("name").isEqualTo("Klaus"), - or( - metadataKey("age").isEqualTo(42), - metadataKey("city").isEqualTo("Munich") - ) - ), - asList( - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("country", "Germany"), - new Metadata().put("name", "Klaus").put("city", "Munich"), - new Metadata().put("name", "Klaus").put("city", "Munich").put("country", "Germany"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich").put("country", "Germany") - ), - asList( - // only And.left is present and true - new Metadata().put("name", "Klaus"), - - // And.left is true, And.right is false - new Metadata().put("name", "Klaus").put("age", 666), - new Metadata().put("name", "Klaus").put("city", "Frankfurt"), - - // only And.right is present and true - new Metadata().put("age", 42), - new Metadata().put("city", "Munich"), - new Metadata().put("age", 42).put("city", "Munich"), - - // And.right is true, And.left is false - new Metadata().put("age", 42).put("name", "Alice"), - new Metadata().put("city", "Munich").put("name", "Alice"), - new Metadata().put("age", 42).put("city", "Munich").put("name", "Alice") - ) - )) - .add(Arguments.of( - and( - or( - metadataKey("name").isEqualTo("Klaus"), - metadataKey("age").isEqualTo(42) - ), - metadataKey("city").isEqualTo("Munich") - ), - asList( - new Metadata().put("name", "Klaus").put("city", "Munich"), - new Metadata().put("name", "Klaus").put("city", "Munich").put("country", "Germany"), - new Metadata().put("age", 42).put("city", "Munich"), - new Metadata().put("age", 42).put("city", "Munich").put("country", "Germany"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich").put("country", "Germany") - ), - asList( - // only And.left is present and true - new Metadata().put("name", "Klaus"), - new Metadata().put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42), - - // And.left is true, And.right is false - new Metadata().put("name", "Klaus").put("city", "Frankfurt"), - new Metadata().put("age", 42).put("city", "Frankfurt"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Frankfurt"), - - // only And.right is present and true - new Metadata().put("city", "Munich"), - - // And.right is true, And.left is false - new Metadata().put("city", "Munich").put("name", "Alice"), - new Metadata().put("city", "Munich").put("age", 666), - new Metadata().put("city", "Munich").put("name", "Alice").put("age", 666) - ) - )) - - // === OR + nested AND === - .add(Arguments.of( - or( - metadataKey("name").isEqualTo("Klaus"), - and( - metadataKey("age").isEqualTo(42), - metadataKey("city").isEqualTo("Munich") - ) - ), - asList( - // only Or.left is present and true - new Metadata().put("name", "Klaus"), - new Metadata().put("name", "Klaus").put("country", "Germany"), - - // Or.left is true, Or.right is false - new Metadata().put("name", "Klaus").put("age", 666), - new Metadata().put("name", "Klaus").put("city", "Frankfurt"), - new Metadata().put("name", "Klaus").put("age", 666).put("city", "Frankfurt"), - - // only Or.right is present and true - new Metadata().put("age", 42).put("city", "Munich"), - new Metadata().put("age", 42).put("city", "Munich").put("country", "Germany"), - - // Or.right is true, Or.left is false - new Metadata().put("age", 42).put("city", "Munich").put("name", "Alice") - ), - asList( - new Metadata().put("name", "Alice"), - new Metadata().put("age", 666), - new Metadata().put("city", "Frankfurt"), - new Metadata().put("name", "Alice").put("age", 666).put("city", "Frankfurt") - ) - )) - .add(Arguments.of( - or( - and( - metadataKey("name").isEqualTo("Klaus"), - metadataKey("age").isEqualTo(42) - ), - metadataKey("city").isEqualTo("Munich") - ), - asList( - // only Or.left is present and true - new Metadata().put("name", "Klaus").put("age", 42), - new Metadata().put("name", "Klaus").put("age", 42).put("country", "Germany"), - - // Or.left is true, Or.right is false - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Frankfurt"), - - // only Or.right is present and true - new Metadata().put("city", "Munich"), - new Metadata().put("city", "Munich").put("country", "Germany"), - - // Or.right is true, Or.left is true - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich"), - new Metadata().put("name", "Klaus").put("age", 42).put("city", "Munich").put("country", "Germany") - ), - asList( - new Metadata().put("name", "Alice"), - new Metadata().put("age", 666), - new Metadata().put("city", "Frankfurt"), - new Metadata().put("name", "Alice").put("age", 666).put("city", "Frankfurt") - ) - )) - - .build(); - } - @ParameterizedTest @MethodSource protected void should_filter_by_metadata_not(