Skip to content

Commit

Permalink
change to or filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemumma committed Jan 24, 2025
1 parent dba9483 commit bc8f702
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sentry_protos.snuba.v1.trace_item_filter_pb2 import (
AndFilter,
ExistsFilter,
OrFilter,
TraceItemFilter,
)

Expand Down Expand Up @@ -47,13 +48,21 @@ def transform(self) -> TraceItemTableRequest:
return self.req
else:
# add the exists filters for the agg_keys
filters_to_add = [
TraceItemFilter(exists_filter=ExistsFilter(key=key)) for key in agg_keys
]
filter_to_add = TraceItemFilter(
or_filter=OrFilter(
filters=[
TraceItemFilter(exists_filter=ExistsFilter(key=key))
for key in agg_keys
]
)
)
# combine the new filters with the existing one
if self.req.HasField("filter"):
filters_to_add.append(self.req.filter)
new_filter = TraceItemFilter(and_filter=AndFilter(filters=filters_to_add))
new_filter = TraceItemFilter(
and_filter=AndFilter(filters=[self.req.filter, filter_to_add])
)
else:
new_filter = filter_to_add

new_req = TraceItemTableRequest()
new_req.CopyFrom(self.req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,7 @@ def test_sparse_aggregate(self, setup_teardown: Any) -> None:
write_eap_span(span_ts, {"animal_type": "bird", "wing.count": 2}, 10)
write_eap_span(span_ts, {"animal_type": "chicken", "wing.count": 2}, 5)
write_eap_span(span_ts, {"animal_type": "cat"}, 12)
write_eap_span(span_ts, {"animal_type": "dog"}, 2)
write_eap_span(span_ts, {"animal_type": "dog", "bark.db": 100}, 2)

ts = Timestamp(seconds=int(BASE_TIME.timestamp()))
hour_ago = int((BASE_TIME - timedelta(hours=1)).timestamp())
Expand Down Expand Up @@ -2193,6 +2193,14 @@ def test_sparse_aggregate(self, setup_teardown: Any) -> None:
extrapolation_mode=ExtrapolationMode.EXTRAPOLATION_MODE_NONE,
),
),
Column(
aggregation=AttributeAggregation(
aggregate=Function.FUNCTION_SUM,
key=AttributeKey(type=AttributeKey.TYPE_DOUBLE, name="bark.db"),
label="sum(bark.db)",
extrapolation_mode=ExtrapolationMode.EXTRAPOLATION_MODE_NONE,
),
),
],
group_by=[AttributeKey(type=AttributeKey.TYPE_STRING, name="animal_type")],
order_by=[
Expand All @@ -2213,13 +2221,23 @@ def test_sparse_aggregate(self, setup_teardown: Any) -> None:
results=[
AttributeValue(val_str="bird"),
AttributeValue(val_str="chicken"),
AttributeValue(val_str="dog"),
],
),
TraceItemColumnValues(
attribute_name="sum(wing.count)",
results=[
AttributeValue(val_double=20),
AttributeValue(val_double=10),
AttributeValue(val_double=0),
],
),
TraceItemColumnValues(
attribute_name="sum(bark.db)",
results=[
AttributeValue(val_double=0),
AttributeValue(val_double=0),
AttributeValue(val_double=200),
],
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sentry_protos.snuba.v1.trace_item_filter_pb2 import (
AndFilter,
ExistsFilter,
OrFilter,
TraceItemFilter,
)

Expand Down Expand Up @@ -81,22 +82,30 @@ def test_basic() -> None:
TraceItemFilter(
exists_filter=ExistsFilter(
key=AttributeKey(
type=AttributeKey.TYPE_DOUBLE, name="my.float.field"
)
)
),
TraceItemFilter(
exists_filter=ExistsFilter(
key=AttributeKey(
type=AttributeKey.TYPE_DOUBLE, name="my.float.field"
type=AttributeKey.TYPE_STRING, name="sentry.category"
)
)
),
TraceItemFilter(
exists_filter=ExistsFilter(
key=AttributeKey(
type=AttributeKey.TYPE_STRING, name="sentry.category"
)
or_filter=OrFilter(
filters=[
TraceItemFilter(
exists_filter=ExistsFilter(
key=AttributeKey(
type=AttributeKey.TYPE_DOUBLE,
name="my.float.field",
)
)
),
TraceItemFilter(
exists_filter=ExistsFilter(
key=AttributeKey(
type=AttributeKey.TYPE_DOUBLE,
name="my.float.field",
)
)
),
]
)
),
]
Expand Down

0 comments on commit bc8f702

Please sign in to comment.