Skip to content

Commit

Permalink
add support for InExpression in infinity (#1890)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

_Support In Operator in filter statement for python sdk and http api._

Issue link : #1839 

### Type of change

- [x] Test cases
- [x] Python SDK impacted, Need to update PyPI
  • Loading branch information
vsian authored Sep 23, 2024
1 parent 14962eb commit a0ded6b
Show file tree
Hide file tree
Showing 24 changed files with 1,894 additions and 1,323 deletions.
43 changes: 40 additions & 3 deletions python/infinity_embedded/local_infinity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from infinity_embedded.common import InfinityException, SparseVector
from infinity_embedded.local_infinity.types import build_result, logic_type_to_dtype
from infinity_embedded.utils import binary_exp_to_paser_exp
from infinity_embedded.embedded_infinity_ext import WrapParsedExpr, WrapFunctionExpr, WrapColumnExpr, WrapConstantExpr, ParsedExprType, LiteralType
from infinity_embedded.embedded_infinity_ext import WrapInExpr, WrapParsedExpr, WrapFunctionExpr, WrapColumnExpr, WrapConstantExpr, ParsedExprType, LiteralType
from infinity_embedded.embedded_infinity_ext import WrapEmbeddingType, WrapColumnDef, WrapDataType, LogicalType, EmbeddingDataType, WrapSparseType, ConstraintType


Expand All @@ -48,7 +48,7 @@ def traverse_conditions(cons, fn=None):
parsed_expr.function_expr = function_expr

return parsed_expr
elif isinstance(cons, exp.Not):
elif isinstance(cons, exp.Not) and isinstance(cons.args['this'], exp.In) == False:
parsed_expr = WrapParsedExpr()
function_expr = WrapFunctionExpr()
function_expr.func_name = "not"
Expand Down Expand Up @@ -155,6 +155,43 @@ def traverse_conditions(cons, fn=None):
parsed_expr = WrapParsedExpr()
parsed_expr.type = ParsedExprType.kFunction
parsed_expr.function_expr = func_expr
return parsed_expr
# in
elif isinstance(cons, exp.In):
left_operand = parse_expr(cons.args['this'])
arguments = []
for arg in cons.args['expressions'] :
if arg :
arguments.append(parse_expr(arg))

in_expr = WrapInExpr()
in_expr.left = left_operand
in_expr.arguments = arguments
in_expr.in_type = True

parsed_expr = WrapParsedExpr()
parsed_expr.type = ParsedExprType.kIn
parsed_expr.in_expr = in_expr

return parsed_expr
# not in
elif isinstance(cons, exp.Not) and isinstance(cons.args['this'], exp.In):
raw_in = cons.this
left_operand = parse_expr(raw_in.args['this'])
arguments = []
for arg in raw_in.args['expressions'] :
if arg :
arguments.append(parse_expr(arg))

in_expr = WrapInExpr()
in_expr.left = left_operand
in_expr.arguments = arguments
in_expr.in_type = False

parsed_expr = WrapParsedExpr()
parsed_expr.type = ParsedExprType.kIn
parsed_expr.in_expr = in_expr

return parsed_expr
else:
raise Exception(f"unknown condition type: {cons}")
Expand Down Expand Up @@ -545,4 +582,4 @@ def get_ordinary_info(column_info, column_defs, column_name, index):

proto_column_def.constant_expr = get_constant_expr(column_info)

column_defs.append(proto_column_def)
column_defs.append(proto_column_def)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a0ded6b

Please sign in to comment.