Skip to content

Commit 6a08cb2

Browse files
committed
implement SQL Filter
closes: #73 Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent 62b4608 commit 6a08cb2

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

rabbitmq_amqp_python_client/entities.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from .exceptions import ValidationCodeException
88
from .qpid.proton._data import Described, symbol
99

10+
SQL_FILTER = "sql-filter"
11+
AMQP_SQL_FILTER = "amqp:sql-filter"
1012
STREAM_FILTER_SPEC = "rabbitmq:stream-filter"
1113
STREAM_OFFSET_SPEC = "rabbitmq:stream-offset-spec"
1214
STREAM_FILTER_MATCH_UNFILTERED = "rabbitmq:stream-match-unfiltered"
@@ -245,20 +247,24 @@ def __init__(
245247
if offset_specification is not None:
246248
self._offset(offset_specification)
247249

248-
if filter_options is not None and filter_options.values is not None:
250+
if filter_options is None:
251+
return
252+
253+
if filter_options.values is not None:
249254
self._filter_values(filter_options.values)
250255

251-
if filter_options is not None and filter_options.match_unfiltered:
256+
if filter_options.match_unfiltered:
252257
self._filter_match_unfiltered(filter_options.match_unfiltered)
253258

254-
if filter_options is not None and filter_options.message_properties is not None:
259+
if filter_options.message_properties is not None:
255260
self._filter_message_properties(filter_options.message_properties)
256-
if (
257-
filter_options is not None
258-
and filter_options.application_properties is not None
259-
):
261+
262+
if filter_options.application_properties is not None:
260263
self._filter_application_properties(filter_options.application_properties)
261264

265+
if filter_options.sql is not None and filter_options.sql != "":
266+
self._filter_sql(filter_options.sql)
267+
262268
def _offset(self, offset_specification: Union[OffsetSpecification, int]) -> None:
263269
"""
264270
Set the offset specification for the stream.
@@ -334,6 +340,18 @@ def _filter_application_properties(
334340
Described(symbol(AMQP_APPLICATION_PROPERTIES_FILTER), app_prop)
335341
)
336342

343+
def _filter_sql(self, sql: str) -> None:
344+
"""
345+
Set SQL filter for the stream.
346+
347+
Args:
348+
sql: SQL string to apply as a filter
349+
"""
350+
if sql != "":
351+
self._filter_set[symbol(SQL_FILTER)] = Described(
352+
symbol(AMQP_SQL_FILTER), sql
353+
)
354+
337355
def filter_set(self) -> Dict[symbol, Described]:
338356
"""
339357
Get the current filter set configuration.

0 commit comments

Comments
 (0)