Skip to content

Commit 216450c

Browse files
authored
feat(rpc): Default extrapolated for snql (#80830)
- This defaults applicable functions to be extrapolated for the snql version of EAP
1 parent 1a042e7 commit 216450c

File tree

2 files changed

+54
-77
lines changed

2 files changed

+54
-77
lines changed

src/sentry/search/events/datasets/spans_indexed.py

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
624624
default_result_type="rate",
625625
),
626626
SnQLFunction(
627-
"count",
627+
"count_sample",
628628
optional_args=[
629629
with_default("span.duration", NumericColumn("column", spans=True)),
630630
],
@@ -638,14 +638,14 @@ def function_converter(self) -> dict[str, SnQLFunction]:
638638
default_result_type="integer",
639639
),
640640
SnQLFunction(
641-
"sum",
641+
"sum_sample",
642642
required_args=[NumericColumn("column", spans=True)],
643643
snql_aggregate=self._resolve_aggregate_if("sum"),
644644
result_type_fn=self.reflective_result_type(),
645645
default_result_type="duration",
646646
),
647647
SnQLFunction(
648-
"avg",
648+
"avg_sample",
649649
optional_args=[
650650
with_default("span.duration", NumericColumn("column", spans=True)),
651651
],
@@ -655,7 +655,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
655655
redundant_grouping=True,
656656
),
657657
SnQLFunction(
658-
"p50",
658+
"p50_sample",
659659
optional_args=[
660660
with_default("span.duration", NumericColumn("column", spans=True)),
661661
],
@@ -665,7 +665,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
665665
redundant_grouping=True,
666666
),
667667
SnQLFunction(
668-
"p75",
668+
"p75_sample",
669669
optional_args=[
670670
with_default("span.duration", NumericColumn("column", spans=True)),
671671
],
@@ -675,7 +675,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
675675
redundant_grouping=True,
676676
),
677677
SnQLFunction(
678-
"p90",
678+
"p90_sample",
679679
optional_args=[
680680
with_default("span.duration", NumericColumn("column", spans=True)),
681681
],
@@ -685,7 +685,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
685685
redundant_grouping=True,
686686
),
687687
SnQLFunction(
688-
"p95",
688+
"p95_sample",
689689
optional_args=[
690690
with_default("span.duration", NumericColumn("column", spans=True)),
691691
],
@@ -695,7 +695,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
695695
redundant_grouping=True,
696696
),
697697
SnQLFunction(
698-
"p99",
698+
"p99_sample",
699699
optional_args=[
700700
with_default("span.duration", NumericColumn("column", spans=True)),
701701
],
@@ -705,7 +705,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
705705
redundant_grouping=True,
706706
),
707707
SnQLFunction(
708-
"p100",
708+
"p100_sample",
709709
optional_args=[
710710
with_default("span.duration", NumericColumn("column", spans=True)),
711711
],
@@ -731,28 +731,22 @@ def function_converter(self) -> dict[str, SnQLFunction]:
731731
redundant_grouping=True,
732732
),
733733
SnQLFunction(
734-
"count_weighted",
734+
"count",
735735
optional_args=[
736736
with_default("span.duration", NumericColumn("column", spans=True)),
737737
],
738738
snql_aggregate=self._resolve_count_weighted,
739739
default_result_type="integer",
740740
),
741741
SnQLFunction(
742-
"count_unique_weighted",
743-
required_args=[ColumnTagArg("column")],
744-
snql_aggregate=self._resolve_aggregate_if("uniq"),
745-
default_result_type="integer",
746-
),
747-
SnQLFunction(
748-
"sum_weighted",
742+
"sum",
749743
required_args=[NumericColumn("column", spans=True)],
750744
result_type_fn=self.reflective_result_type(),
751745
snql_aggregate=lambda args, alias: self._resolve_sum_weighted(args, alias),
752746
default_result_type="duration",
753747
),
754748
SnQLFunction(
755-
"avg_weighted",
749+
"avg",
756750
required_args=[NumericColumn("column", spans=True)],
757751
result_type_fn=self.reflective_result_type(),
758752
snql_aggregate=lambda args, alias: Function(
@@ -766,7 +760,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
766760
default_result_type="duration",
767761
),
768762
SnQLFunction(
769-
"percentile_weighted",
763+
"percentile",
770764
required_args=[
771765
NumericColumn("column", spans=True),
772766
NumberRange("percentile", 0, 1),
@@ -777,7 +771,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
777771
redundant_grouping=True,
778772
),
779773
SnQLFunction(
780-
"p50_weighted",
774+
"p50",
781775
optional_args=[
782776
with_default("span.duration", NumericColumn("column", spans=True)),
783777
],
@@ -789,7 +783,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
789783
redundant_grouping=True,
790784
),
791785
SnQLFunction(
792-
"p75_weighted",
786+
"p75",
793787
optional_args=[
794788
with_default("span.duration", NumericColumn("column", spans=True)),
795789
],
@@ -801,7 +795,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
801795
redundant_grouping=True,
802796
),
803797
SnQLFunction(
804-
"p90_weighted",
798+
"p90",
805799
optional_args=[
806800
with_default("span.duration", NumericColumn("column", spans=True)),
807801
],
@@ -813,7 +807,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
813807
redundant_grouping=True,
814808
),
815809
SnQLFunction(
816-
"p95_weighted",
810+
"p95",
817811
optional_args=[
818812
with_default("span.duration", NumericColumn("column", spans=True)),
819813
],
@@ -825,7 +819,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
825819
redundant_grouping=True,
826820
),
827821
SnQLFunction(
828-
"p99_weighted",
822+
"p99",
829823
optional_args=[
830824
with_default("span.duration", NumericColumn("column", spans=True)),
831825
],
@@ -837,7 +831,7 @@ def function_converter(self) -> dict[str, SnQLFunction]:
837831
redundant_grouping=True,
838832
),
839833
SnQLFunction(
840-
"p100_weighted",
834+
"p100",
841835
optional_args=[
842836
with_default("span.duration", NumericColumn("column", spans=True)),
843837
],
@@ -848,23 +842,6 @@ def function_converter(self) -> dict[str, SnQLFunction]:
848842
default_result_type="duration",
849843
redundant_grouping=True,
850844
),
851-
# Min and Max are identical to their existing implementations
852-
SnQLFunction(
853-
"min_weighted",
854-
required_args=[NumericColumn("column", spans=True)],
855-
snql_aggregate=self._resolve_aggregate_if("min"),
856-
result_type_fn=self.reflective_result_type(),
857-
default_result_type="duration",
858-
redundant_grouping=True,
859-
),
860-
SnQLFunction(
861-
"max_weighted",
862-
required_args=[NumericColumn("column", spans=True)],
863-
snql_aggregate=self._resolve_aggregate_if("max"),
864-
result_type_fn=self.reflective_result_type(),
865-
default_result_type="duration",
866-
redundant_grouping=True,
867-
),
868845
SnQLFunction(
869846
"margin_of_error",
870847
optional_args=[with_default("fpc", SnQLStringArg("fpc"))],
@@ -1060,14 +1037,14 @@ def _query_total_counts(self) -> tuple[float | int, float | int]:
10601037
dataset=self.builder.dataset,
10611038
params={},
10621039
snuba_params=self.builder.params,
1063-
selected_columns=["count()", "count_weighted()"],
1040+
selected_columns=["count_sample()", "count()"],
10641041
)
10651042
total_results = total_query.run_query(Referrer.API_SPANS_TOTAL_COUNT_FIELD.value)
10661043
results = total_query.process_results(total_results)
10671044
if len(results["data"]) != 1:
10681045
raise Exception("Could not query population size")
1069-
self._cached_count = results["data"][0]["count"]
1070-
self._cached_count_weighted = results["data"][0]["count_weighted"]
1046+
self._cached_count = results["data"][0]["count_sample"]
1047+
self._cached_count_weighted = results["data"][0]["count"]
10711048
return self._cached_count, self._cached_count_weighted
10721049

10731050
@cached_property

tests/snuba/api/endpoints/test_organization_events_span_indexed.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -690,21 +690,21 @@ def test_aggregate_numeric_attr_weighted(self):
690690
{
691691
"field": [
692692
"description",
693-
"count_unique_weighted(bar)",
694-
"count_unique_weighted(tags[bar])",
695-
"count_unique_weighted(tags[bar,string])",
696-
"count_weighted()",
697-
"count_weighted(span.duration)",
698-
"count_weighted(tags[foo, number])",
699-
"sum_weighted(tags[foo,number])",
700-
"avg_weighted(tags[foo,number])",
701-
"p50_weighted(tags[foo,number])",
702-
"p75_weighted(tags[foo,number])",
703-
"p95_weighted(tags[foo,number])",
704-
"p99_weighted(tags[foo,number])",
705-
"p100_weighted(tags[foo,number])",
706-
"min_weighted(tags[foo,number])",
707-
"max_weighted(tags[foo,number])",
693+
"count_unique(bar)",
694+
"count_unique(tags[bar])",
695+
"count_unique(tags[bar,string])",
696+
"count()",
697+
"count(span.duration)",
698+
"count(tags[foo, number])",
699+
"sum(tags[foo,number])",
700+
"avg(tags[foo,number])",
701+
"p50(tags[foo,number])",
702+
"p75(tags[foo,number])",
703+
"p95(tags[foo,number])",
704+
"p99(tags[foo,number])",
705+
"p100(tags[foo,number])",
706+
"min(tags[foo,number])",
707+
"max(tags[foo,number])",
708708
],
709709
"query": "",
710710
"orderby": "description",
@@ -718,21 +718,21 @@ def test_aggregate_numeric_attr_weighted(self):
718718
data = response.data["data"]
719719
assert data[0] == {
720720
"description": "foo",
721-
"count_unique_weighted(bar)": 3,
722-
"count_unique_weighted(tags[bar])": 3,
723-
"count_unique_weighted(tags[bar,string])": 3,
724-
"count_weighted()": 3,
725-
"count_weighted(span.duration)": 3,
726-
"count_weighted(tags[foo, number])": 1,
727-
"sum_weighted(tags[foo,number])": 5.0,
728-
"avg_weighted(tags[foo,number])": 5.0,
729-
"p50_weighted(tags[foo,number])": 5.0,
730-
"p75_weighted(tags[foo,number])": 5.0,
731-
"p95_weighted(tags[foo,number])": 5.0,
732-
"p99_weighted(tags[foo,number])": 5.0,
733-
"p100_weighted(tags[foo,number])": 5.0,
734-
"min_weighted(tags[foo,number])": 5.0,
735-
"max_weighted(tags[foo,number])": 5.0,
721+
"count_unique(bar)": 3,
722+
"count_unique(tags[bar])": 3,
723+
"count_unique(tags[bar,string])": 3,
724+
"count()": 3,
725+
"count(span.duration)": 3,
726+
"count(tags[foo, number])": 1,
727+
"sum(tags[foo,number])": 5.0,
728+
"avg(tags[foo,number])": 5.0,
729+
"p50(tags[foo,number])": 5.0,
730+
"p75(tags[foo,number])": 5.0,
731+
"p95(tags[foo,number])": 5.0,
732+
"p99(tags[foo,number])": 5.0,
733+
"p100(tags[foo,number])": 5.0,
734+
"min(tags[foo,number])": 5.0,
735+
"max(tags[foo,number])": 5.0,
736736
}
737737

738738
def test_numeric_attr_without_space(self):
@@ -1016,7 +1016,7 @@ def test_margin_of_error(self):
10161016
"margin_of_error()",
10171017
"lower_count_limit()",
10181018
"upper_count_limit()",
1019-
"count_weighted()",
1019+
"count()",
10201020
],
10211021
"query": "description:foo",
10221022
"project": self.project.id,
@@ -1029,7 +1029,7 @@ def test_margin_of_error(self):
10291029
margin_of_error = data["margin_of_error()"]
10301030
lower_limit = data["lower_count_limit()"]
10311031
upper_limit = data["upper_count_limit()"]
1032-
extrapolated = data["count_weighted()"]
1032+
extrapolated = data["count()"]
10331033
assert margin_of_error == pytest.approx(0.306, rel=1e-1)
10341034
# How to read this; these results mean that the extrapolated count is
10351035
# 500k, with a lower estimated bound of ~200k, and an upper bound of 800k

0 commit comments

Comments
 (0)