2525import org .apache .paimon .data .BinaryString ;
2626import org .apache .paimon .data .GenericRow ;
2727import org .apache .paimon .data .InternalRow ;
28+ import org .apache .paimon .data .serializer .InternalRowSerializer ;
29+ import org .apache .paimon .predicate .Predicate ;
30+ import org .apache .paimon .predicate .PredicateBuilder ;
31+ import org .apache .paimon .reader .RecordReader ;
2832import org .apache .paimon .schema .Schema ;
2933import org .apache .paimon .table .FileStoreTable ;
34+ import org .apache .paimon .table .Table ;
3035import org .apache .paimon .table .TableTestBase ;
36+ import org .apache .paimon .table .source .ReadBuilder ;
3137import org .apache .paimon .types .DataTypes ;
3238
3339import org .junit .jupiter .api .BeforeEach ;
3440import org .junit .jupiter .api .Test ;
3541
3642import java .io .IOException ;
43+ import java .util .ArrayList ;
44+ import java .util .Arrays ;
3745import java .util .List ;
3846import java .util .Map ;
3947import java .util .stream .Collectors ;
@@ -75,6 +83,40 @@ public void testPartitionRecordCount() throws Exception {
7583 assertThat (result ).containsExactlyInAnyOrderElementsOf (expectRow );
7684 }
7785
86+ @ Test
87+ public void testFilterByConsumerIdEqual () throws Exception {
88+ Predicate predicate = consumerIdEqual ("id1" );
89+ List <InternalRow > expectedRow =
90+ Arrays .asList (GenericRow .of (BinaryString .fromString ("id1" ), 5L ));
91+ List <InternalRow > result = readWithFilter (consumersTable , predicate );
92+ assertThat (result ).containsExactlyElementsOf (expectedRow );
93+ }
94+
95+ @ Test
96+ public void testFilterByConsumerIdEqualNoMatch () throws Exception {
97+ Predicate predicate = consumerIdEqual ("id999" );
98+ List <InternalRow > result = readWithFilter (consumersTable , predicate );
99+ assertThat (result ).isEmpty ();
100+ }
101+
102+ @ Test
103+ public void testFilterByConsumerIdIn () throws Exception {
104+ PredicateBuilder builder = new PredicateBuilder (ConsumersTable .TABLE_TYPE );
105+ Predicate predicate = builder .in (0 , Arrays .asList ("id1" , "id999" ));
106+ List <InternalRow > expectedRow =
107+ Arrays .asList (GenericRow .of (BinaryString .fromString ("id1" ), 5L ));
108+ List <InternalRow > result = readWithFilter (consumersTable , predicate );
109+ assertThat (result ).containsExactlyElementsOf (expectedRow );
110+ }
111+
112+ @ Test
113+ public void testFilterByConsumerIdInNoMatch () throws Exception {
114+ PredicateBuilder builder = new PredicateBuilder (ConsumersTable .TABLE_TYPE );
115+ Predicate predicate = builder .in (0 , Arrays .asList ("id998" , "id999" ));
116+ List <InternalRow > result = readWithFilter (consumersTable , predicate );
117+ assertThat (result ).isEmpty ();
118+ }
119+
78120 private List <InternalRow > getExpectedResult () throws IOException {
79121 Map <String , Long > consumers = manager .consumers ();
80122 return consumers .entrySet ().stream ()
@@ -84,4 +126,19 @@ private List<InternalRow> getExpectedResult() throws IOException {
84126 BinaryString .fromString (entry .getKey ()), entry .getValue ()))
85127 .collect (Collectors .toList ());
86128 }
129+
130+ private Predicate consumerIdEqual (String consumerId ) {
131+ PredicateBuilder builder = new PredicateBuilder (ConsumersTable .TABLE_TYPE );
132+ return builder .equal (0 , BinaryString .fromString (consumerId ));
133+ }
134+
135+ private List <InternalRow > readWithFilter (Table table , Predicate predicate ) throws Exception {
136+ ReadBuilder readBuilder = table .newReadBuilder ().withFilter (predicate );
137+ RecordReader <InternalRow > reader =
138+ readBuilder .newRead ().createReader (readBuilder .newScan ().plan ());
139+ InternalRowSerializer serializer = new InternalRowSerializer (table .rowType ());
140+ List <InternalRow > rows = new ArrayList <>();
141+ reader .forEachRemaining (row -> rows .add (serializer .copy (row )));
142+ return rows ;
143+ }
87144}
0 commit comments