Skip to content

Add ISNULL, ISNOTNULL Filter Expression #3706

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,25 @@ Consider the following example:
Expression exp = b.and(b.in("genre", "drama", "documentary"), b.not(b.lt("year", 2020))).build();
----

You can also use the following operators:

[source,text]
----
IS: 'IS' | 'is';
NULL: 'NULL' | 'null';
NOT NULL: 'NOT NULL' | 'not null';
----

Consider the following example:

[source,java]
----
Expression exp = b.and(b.isNull("year")).build();
Expression exp = b.and(b.isNotNull("year")).build();
----

NOTE: `IS NULL` and `IS NOT NULL` have not been implemented in all vector stores yet.

== Deleting Documents from Vector Store

The Vector Store interface provides multiple methods for deleting documents, allowing you to remove data either by specific document IDs or using filter expressions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,7 +78,7 @@ public class Filter {
*/
public enum ExpressionType {

AND, OR, EQ, NE, GT, GTE, LT, LTE, IN, NIN, NOT
AND, OR, EQ, NE, GT, GTE, LT, LTE, IN, NIN, NOT, ISNULL, ISNOTNULL

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -105,6 +105,14 @@ public Op nin(String key, List<Object> values) {
return new Op(new Filter.Expression(ExpressionType.NIN, new Key(key), new Value(values)));
}

public Op isNull(String key) {
return new Op(new Filter.Expression(ExpressionType.ISNULL, new Key(key)));
}

public Op isNotNull(String key) {
return new Op(new Filter.Expression(ExpressionType.ISNOTNULL, new Key(key)));
}

public Op group(Op content) {
return new Op(new Filter.Group(content.build()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -239,6 +239,16 @@ public Filter.Operand visitCompareExpression(FiltersParser.CompareExpressionCont
this.visitIdentifier(ctx.identifier()), this.visit(ctx.constant()));
}

@Override
public Filter.Operand visitIsNullExpression(FiltersParser.IsNullExpressionContext ctx) {
return new Filter.Expression(Filter.ExpressionType.ISNULL, this.visitIdentifier(ctx.identifier()));
}

@Override
public Filter.Operand visitIsNotNullExpression(FiltersParser.IsNotNullExpressionContext ctx) {
return new Filter.Expression(Filter.ExpressionType.ISNOTNULL, this.visitIdentifier(ctx.identifier()));
}

private Filter.ExpressionType covertCompare(String compare) {
if (!COMP_EXPRESSION_TYPE_MAP.containsKey(compare)) {
throw new RuntimeException("Unknown compare operator: " + compare);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ null
null
null
null
null
null

token symbolic names:
null
Expand All @@ -49,6 +51,8 @@ OR
IN
NIN
NOT
IS
NULL
BOOLEAN_VALUE
QUOTED_STRING
INTEGER_VALUE
Expand All @@ -66,4 +70,4 @@ constant


atn:
[4, 1, 26, 89, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 36, 40, 1, 0, 0, 0, 37, 38, 5, 20, 0, 0, 38, 40, 3, 2, 1, 1, 39, 16, 1, 0, 0, 0, 39, 21, 1, 0, 0, 0, 39, 25, 1, 0, 0, 0, 39, 33, 1, 0, 0, 0, 39, 37, 1, 0, 0, 0, 40, 49, 1, 0, 0, 0, 41, 42, 10, 4, 0, 0, 42, 43, 5, 16, 0, 0, 43, 48, 3, 2, 1, 5, 44, 45, 10, 3, 0, 0, 45, 46, 5, 17, 0, 0, 46, 48, 3, 2, 1, 4, 47, 41, 1, 0, 0, 0, 47, 44, 1, 0, 0, 0, 48, 51, 1, 0, 0, 0, 49, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 3, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 52, 53, 5, 4, 0, 0, 53, 58, 3, 10, 5, 0, 54, 55, 5, 3, 0, 0, 55, 57, 3, 10, 5, 0, 56, 54, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 62, 5, 5, 0, 0, 62, 5, 1, 0, 0, 0, 63, 64, 7, 0, 0, 0, 64, 7, 1, 0, 0, 0, 65, 66, 5, 25, 0, 0, 66, 67, 5, 2, 0, 0, 67, 71, 5, 25, 0, 0, 68, 71, 5, 25, 0, 0, 69, 71, 5, 22, 0, 0, 70, 65, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 69, 1, 0, 0, 0, 71, 9, 1, 0, 0, 0, 72, 74, 7, 1, 0, 0, 73, 72, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 87, 5, 23, 0, 0, 76, 78, 7, 1, 0, 0, 77, 76, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 87, 5, 24, 0, 0, 80, 82, 5, 22, 0, 0, 81, 80, 1,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 1, 0, 0, 0, 12, 13, 5, 1, 0, 0, 13, 14, 3, 2, 1, 0, 14, 15, 5, 0, 0, 1, 15, 1, 1, 0, 0, 0, 16, 17, 6, 1, -1, 0, 17, 18, 3, 8, 4, 0, 18, 19, 3, 6, 3, 0, 19, 20, 3, 10, 5, 0, 20, 49, 1, 0, 0, 0, 21, 22, 3, 8, 4, 0, 22, 23, 5, 18, 0, 0, 23, 24, 3, 4, 2, 0, 24, 49, 1, 0, 0, 0, 25, 29, 3, 8, 4, 0, 26, 27, 5, 20, 0, 0, 27, 30, 5, 18, 0, 0, 28, 30, 5, 19, 0, 0, 29, 26, 1, 0, 0, 0, 29, 28, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 32, 3, 4, 2, 0, 32, 49, 1, 0, 0, 0, 33, 34, 3, 8, 4, 0, 34, 35, 5, 21, 0, 0, 35, 36, 5, 22, 0, 0, 36, 49, 1, 0, 0, 0, 37, 38, 3, 8, 4, 0, 38, 39, 5, 21, 0, 0, 39, 40, 5, 20, 0, 0, 40, 41, 5, 22, 0, 0, 41, 49, 1, 0, 0, 0, 42, 43, 5, 6, 0, 0, 43, 44, 3, 2, 1, 0, 44, 45, 5, 7, 0, 0, 45, 49, 1, 0, 0, 0, 46, 47, 5, 20, 0, 0, 47, 49, 3, 2, 1, 1, 48, 16, 1, 0, 0, 0, 48, 21, 1, 0, 0, 0, 48, 25, 1, 0, 0, 0, 48, 33, 1, 0, 0, 0, 48, 37, 1, 0, 0, 0, 48, 42, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, 58, 1, 0, 0, 0, 50, 51, 10, 4, 0, 0, 51, 52, 5, 16, 0, 0, 52, 57, 3, 2, 1, 5, 53, 54, 10, 3, 0, 0, 54, 55, 5, 17, 0, 0, 55, 57, 3, 2, 1, 4, 56, 50, 1, 0, 0, 0, 56, 53, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 3, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 62, 5, 4, 0, 0, 62, 67, 3, 10, 5, 0, 63, 64, 5, 3, 0, 0, 64, 66, 3, 10, 5, 0, 65, 63, 1, 0, 0, 0, 66, 69, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, 70, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 70, 71, 5, 5, 0, 0, 71, 5, 1, 0, 0, 0, 72, 73, 7, 0, 0, 0, 73, 7, 1, 0, 0, 0, 74, 75, 5, 27, 0, 0, 75, 76, 5, 2, 0, 0, 76, 80, 5, 27, 0, 0, 77, 80, 5, 27, 0, 0, 78, 80, 5, 24, 0, 0, 79, 74, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 78, 1, 0, 0, 0, 80, 9, 1, 0, 0, 0, 81, 83, 7, 1, 0, 0, 82, 81, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 84, 1, 0, 0, 0, 84, 96, 5, 25, 0, 0, 85, 87, 7, 1, 0, 0, 86, 85, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 88, 1, 0, 0, 0, 88, 96, 5, 26, 0, 0, 89, 91, 5, 24, 0, 0, 90, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 90, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, 93, 96, 1, 0, 0, 0, 94, 96, 5, 23, 0, 0, 95, 82, 1, 0, 0, 0, 95, 86, 1, 0, 0, 0, 95, 90, 1, 0, 0, 0, 95, 94, 1, 0, 0, 0, 96, 11, 1, 0, 0, 0, 10, 29, 48, 56, 58, 67, 79, 82, 86, 92, 95]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,6 +78,50 @@ public void enterNinExpression(FiltersParser.NinExpressionContext ctx) {
public void exitNinExpression(FiltersParser.NinExpressionContext ctx) {
}

/**
* {@inheritDoc}
*
* <p>
* The default implementation does nothing.
* </p>
*/
@Override
public void enterIsNullExpression(FiltersParser.IsNullExpressionContext ctx) {
}

/**
* {@inheritDoc}
*
* <p>
* The default implementation does nothing.
* </p>
*/
@Override
public void exitIsNullExpression(FiltersParser.IsNullExpressionContext ctx) {
}

/**
* {@inheritDoc}
*
* <p>
* The default implementation does nothing.
* </p>
*/
@Override
public void enterIsNotNullExpression(FiltersParser.IsNotNullExpressionContext ctx) {
}

/**
* {@inheritDoc}
*
* <p>
* The default implementation does nothing.
* </p>
*/
@Override
public void exitIsNotNullExpression(FiltersParser.IsNotNullExpressionContext ctx) {
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,6 +61,32 @@ public T visitNinExpression(FiltersParser.NinExpressionContext ctx) {
return visitChildren(ctx);
}

/**
* {@inheritDoc}
*
* <p>
* The default implementation returns the result of calling {@link #visitChildren} on
* {@code ctx}.
* </p>
*/
@Override
public T visitIsNullExpression(FiltersParser.IsNullExpressionContext ctx) {
return visitChildren(ctx);
}

/**
* {@inheritDoc}
*
* <p>
* The default implementation returns the result of calling {@link #visitChildren} on
* {@code ctx}.
* </p>
*/
@Override
public T visitIsNotNullExpression(FiltersParser.IsNotNullExpressionContext ctx) {
return visitChildren(ctx);
}

/**
* {@inheritDoc}
*
Expand Down

Large diffs are not rendered by default.

Loading