@@ -155,4 +155,183 @@ public void testCombinedComparisons() {
155155 .isEqualTo ("metadata[\" price\" ] > 1000 && metadata[\" temperature\" ] < 25 && metadata[\" humidity\" ] <= 80" );
156156 }
157157
158+ @ Test
159+ public void testNin () {
160+ // region not in ["A", "B", "C"]
161+ String vectorExpr = this .converter
162+ .convertExpression (new Expression (NIN , new Key ("region" ), new Value (List .of ("A" , "B" , "C" ))));
163+ assertThat (vectorExpr ).isEqualTo ("metadata[\" region\" ] not in [\" A\" ,\" B\" ,\" C\" ]" );
164+ }
165+
166+ @ Test
167+ public void testNullValue () {
168+ // status == null
169+ String vectorExpr = this .converter .convertExpression (new Expression (EQ , new Key ("status" ), new Value (null )));
170+ assertThat (vectorExpr ).isEqualTo ("metadata[\" status\" ] == null" );
171+ }
172+
173+ @ Test
174+ public void testEmptyString () {
175+ // name == ""
176+ String vectorExpr = this .converter .convertExpression (new Expression (EQ , new Key ("name" ), new Value ("" )));
177+ assertThat (vectorExpr ).isEqualTo ("metadata[\" name\" ] == \" \" " );
178+ }
179+
180+ @ Test
181+ public void testNumericString () {
182+ // id == "12345"
183+ String vectorExpr = this .converter .convertExpression (new Expression (EQ , new Key ("id" ), new Value ("12345" )));
184+ assertThat (vectorExpr ).isEqualTo ("metadata[\" id\" ] == \" 12345\" " );
185+ }
186+
187+ @ Test
188+ public void testLongValue () {
189+ // timestamp >= 1640995200000L
190+ String vectorExpr = this .converter
191+ .convertExpression (new Expression (GTE , new Key ("timestamp" ), new Value (1640995200000L )));
192+ assertThat (vectorExpr ).isEqualTo ("metadata[\" timestamp\" ] >= 1640995200000" );
193+ }
194+
195+ @ Test
196+ public void testFloatValue () {
197+ // score >= 4.5f
198+ String vectorExpr = this .converter .convertExpression (new Expression (GTE , new Key ("score" ), new Value (4.5f )));
199+ assertThat (vectorExpr ).isEqualTo ("metadata[\" score\" ] >= 4.5" );
200+ }
201+
202+ @ Test
203+ public void testMixedTypesList () {
204+ // tags in [1, "priority", true]
205+ String vectorExpr = this .converter
206+ .convertExpression (new Expression (IN , new Key ("tags" ), new Value (List .of (1 , "priority" , true ))));
207+ assertThat (vectorExpr ).isEqualTo ("metadata[\" tags\" ] in [1,\" priority\" ,true]" );
208+ }
209+
210+ @ Test
211+ public void testEmptyList () {
212+ // categories in []
213+ String vectorExpr = this .converter
214+ .convertExpression (new Expression (IN , new Key ("categories" ), new Value (List .of ())));
215+ assertThat (vectorExpr ).isEqualTo ("metadata[\" categories\" ] in []" );
216+ }
217+
218+ @ Test
219+ public void testSingleItemList () {
220+ // status in ["active"]
221+ String vectorExpr = this .converter
222+ .convertExpression (new Expression (IN , new Key ("status" ), new Value (List .of ("active" ))));
223+ assertThat (vectorExpr ).isEqualTo ("metadata[\" status\" ] in [\" active\" ]" );
224+ }
225+
226+ @ Test
227+ public void testKeyWithDots () {
228+ // "value.field" >= 18
229+ String vectorExpr = this .converter
230+ .convertExpression (new Expression (GTE , new Key ("value.field" ), new Value (18 )));
231+ assertThat (vectorExpr ).isEqualTo ("metadata[\" value.field\" ] >= 18" );
232+ }
233+
234+ @ Test
235+ public void testKeyWithSpecialCharacters () {
236+ // "field-name_with@symbols" == "value"
237+ String vectorExpr = this .converter
238+ .convertExpression (new Expression (EQ , new Key ("field-name_with@symbols" ), new Value ("value" )));
239+ assertThat (vectorExpr ).isEqualTo ("metadata[\" field-name_with@symbols\" ] == \" value\" " );
240+ }
241+
242+ @ Test
243+ public void testTripleAnd () {
244+ // value >= 100 AND type == "primary" AND region == "X"
245+ String vectorExpr = this .converter .convertExpression (new Expression (AND ,
246+ new Expression (AND , new Expression (GTE , new Key ("value" ), new Value (100 )),
247+ new Expression (EQ , new Key ("type" ), new Value ("primary" ))),
248+ new Expression (EQ , new Key ("region" ), new Value ("X" ))));
249+
250+ assertThat (vectorExpr ).isEqualTo (
251+ "metadata[\" value\" ] >= 100 && metadata[\" type\" ] == \" primary\" && metadata[\" region\" ] == \" X\" " );
252+ }
253+
254+ @ Test
255+ public void testTripleOr () {
256+ // value < 50 OR value > 200 OR type == "special"
257+ String vectorExpr = this .converter .convertExpression (new Expression (OR ,
258+ new Expression (OR , new Expression (LT , new Key ("value" ), new Value (50 )),
259+ new Expression (GT , new Key ("value" ), new Value (200 ))),
260+ new Expression (EQ , new Key ("type" ), new Value ("special" ))));
261+
262+ assertThat (vectorExpr )
263+ .isEqualTo ("metadata[\" value\" ] < 50 || metadata[\" value\" ] > 200 || metadata[\" type\" ] == \" special\" " );
264+ }
265+
266+ @ Test
267+ public void testNegativeNumbers () {
268+ // temperature >= -20 AND temperature <= -5
269+ String vectorExpr = this .converter
270+ .convertExpression (new Expression (AND , new Expression (GTE , new Key ("temperature" ), new Value (-20 )),
271+ new Expression (LTE , new Key ("temperature" ), new Value (-5 ))));
272+
273+ assertThat (vectorExpr ).isEqualTo ("metadata[\" temperature\" ] >= -20 && metadata[\" temperature\" ] <= -5" );
274+ }
275+
276+ @ Test
277+ public void testZeroValues () {
278+ // count == 0
279+ String vectorExpr = this .converter .convertExpression (new Expression (EQ , new Key ("count" ), new Value (0 )));
280+ assertThat (vectorExpr ).isEqualTo ("metadata[\" count\" ] == 0" );
281+ }
282+
283+ @ Test
284+ public void testBooleanFalse () {
285+ // enabled == false
286+ String vectorExpr = this .converter .convertExpression (new Expression (EQ , new Key ("enabled" ), new Value (false )));
287+ assertThat (vectorExpr ).isEqualTo ("metadata[\" enabled\" ] == false" );
288+ }
289+
290+ @ Test
291+ public void testVeryLongString () {
292+ // Test with a very long string value
293+ String longValue = "This is a very long string that might be used as a value in a filter expression to test how the converter handles lengthy text content that could potentially cause issues with string manipulation" ;
294+ String vectorExpr = this .converter
295+ .convertExpression (new Expression (EQ , new Key ("content" ), new Value (longValue )));
296+ assertThat (vectorExpr ).isEqualTo ("metadata[\" content\" ] == \" " + longValue + "\" " );
297+ }
298+
299+ @ Test
300+ public void testRangeQuery () {
301+ // value >= 10 AND value <= 100
302+ String vectorExpr = this .converter
303+ .convertExpression (new Expression (AND , new Expression (GTE , new Key ("value" ), new Value (10 )),
304+ new Expression (LTE , new Key ("value" ), new Value (100 ))));
305+
306+ assertThat (vectorExpr ).isEqualTo ("metadata[\" value\" ] >= 10 && metadata[\" value\" ] <= 100" );
307+ }
308+
309+ @ Test
310+ public void testComplexOrWithMultipleFields () {
311+ // type == "primary" OR status == "active" OR priority > 5
312+ String vectorExpr = this .converter .convertExpression (new Expression (OR ,
313+ new Expression (OR , new Expression (EQ , new Key ("type" ), new Value ("primary" )),
314+ new Expression (EQ , new Key ("status" ), new Value ("active" ))),
315+ new Expression (GT , new Key ("priority" ), new Value (5 ))));
316+
317+ assertThat (vectorExpr ).isEqualTo (
318+ "metadata[\" type\" ] == \" primary\" || metadata[\" status\" ] == \" active\" || metadata[\" priority\" ] > 5" );
319+ }
320+
321+ @ Test
322+ public void testDoubleQuotedKey () {
323+ // "field with spaces" == "value"
324+ String vectorExpr = this .converter
325+ .convertExpression (new Expression (EQ , new Key ("\" field with spaces\" " ), new Value ("value" )));
326+ assertThat (vectorExpr ).isEqualTo ("metadata[\" field with spaces\" ] == \" value\" " );
327+ }
328+
329+ @ Test
330+ public void testSingleQuotedKey () {
331+ // 'field with spaces' == "value"
332+ String vectorExpr = this .converter
333+ .convertExpression (new Expression (EQ , new Key ("'field with spaces'" ), new Value ("value" )));
334+ assertThat (vectorExpr ).isEqualTo ("metadata[\" field with spaces\" ] == \" value\" " );
335+ }
336+
158337}
0 commit comments