Skip to content

Commit

Permalink
round
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Chen authored and Rachel Chen committed Jan 17, 2025
1 parent 298b46c commit 628c371
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CalculatedAverageProcessor(LogicalQueryProcessor):
"""

def process_query(self, query: Query, query_settings: QuerySettings) -> None:
print("huh_process_query")
# use a matcher to find something like avg(value)
matcher = FunctionCallMatch(
Or([String("avg"), String("avgIf")]),
Expand All @@ -25,7 +24,6 @@ def process_query(self, query: Query, query_settings: QuerySettings) -> None:
)

def transform_expression(exp: Expression) -> Expression:
print("huh_transform_expression")
match = matcher.match(exp)
if isinstance(exp, FunctionCall) and match is not None:
suffix = "If" if exp.function_name == "avgIf" else ""
Expand Down
3 changes: 0 additions & 3 deletions snuba/query/processors/logical/filter_in_select_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class FindConditionalAggregateFunctionsVisitor(
"""

def __init__(self) -> None:
print("huh_FindConditionalAggregateFunctionsVisitor")
self._matches: list[FunctionCall | CurriedFunctionCall] = []

def visit_literal(self, exp: Literal) -> list[FunctionCall | CurriedFunctionCall]:
Expand Down Expand Up @@ -101,7 +100,6 @@ class FilterInSelectOptimizer(LogicalQueryProcessor):
"""

def process_query(self, query: LogicalQuery, query_settings: QuerySettings) -> None:
print("huh_FilterInSelectOptimizer")
try:
new_condition = self.get_select_filter(query)
except Exception:
Expand All @@ -117,7 +115,6 @@ def get_select_filter(
self,
query: LogicalQuery | CompositeQuery[QueryEntity],
) -> FunctionCall | None:
print("huh_get_select_filter")
"""
Given a query, grabs all the conditions from conditional aggregates and lifts into
one condition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(
aggregation_names: list[str],
curried_aggregation_names: list[str],
):
print("huh_OptionalAttributeAggregationTransformer")
self._attribute_column_names = attribute_column_names
self._aggregation_names = aggregation_names
self._curried_aggregation_names = curried_aggregation_names
Expand Down
4 changes: 0 additions & 4 deletions snuba/web/db_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,13 @@ def execute_query(
# Apply clickhouse query setting overrides
clickhouse_query_settings.update(query_settings.get_clickhouse_settings())

print("formatted_queryyyy", formatted_query)

result = reader.execute(
formatted_query,
clickhouse_query_settings,
with_totals=clickhouse_query.has_totals(),
robust=robust,
)

print("resulttttttt", result)

timer.mark("execute")
stats.update(
{
Expand Down
1 change: 0 additions & 1 deletion snuba/web/rpc/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def _build_label_mapping_key(attr_key: AttributeKey) -> str:

if attr_key.name in NORMALIZED_COLUMNS:
# the second if statement allows Sentry to send TYPE_FLOAT to Snuba when Snuba still has to be backward compatible with TYPE_FLOATS
print("attr_keyyy", attr_key.name, attr_key.type)
if NORMALIZED_COLUMNS[attr_key.name] == attr_key.type or (
attr_key.type == AttributeKey.Type.TYPE_FLOAT
and NORMALIZED_COLUMNS[attr_key.name] == AttributeKey.Type.TYPE_DOUBLE
Expand Down
6 changes: 4 additions & 2 deletions snuba/web/rpc/v1/resolvers/R_eap_spans/common/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,9 @@ def aggregation_to_expression(aggregation: AttributeAggregation) -> Expression:
alias = aggregation.label if aggregation.label else None
alias_dict = {"alias": alias} if alias else {}
function_map: dict[Function.ValueType, CurriedFunctionCall | FunctionCall] = {
Function.FUNCTION_SUM: f.sum(f.multiply(field, sign_column), **alias_dict),
Function.FUNCTION_SUM: f.round(
f.sum(f.multiply(field, sign_column)), 8, **alias_dict
),
Function.FUNCTION_AVERAGE: f.divide(
f.sum(f.multiply(field, sign_column)),
f.sumIf(sign_column, get_field_existence_expression(aggregation)),
Expand All @@ -628,7 +630,7 @@ def aggregation_to_expression(aggregation: AttributeAggregation) -> Expression:
Function.FUNCTION_P90: cf.quantile(0.9)(field, **alias_dict),
Function.FUNCTION_P95: cf.quantile(0.95)(field, **alias_dict),
Function.FUNCTION_P99: cf.quantile(0.99)(field, **alias_dict),
Function.FUNCTION_AVG: f.round(f.avg(field), 9, **alias_dict),
Function.FUNCTION_AVG: f.round(f.avg(field), 8, **alias_dict),
Function.FUNCTION_MAX: f.max(field, **alias_dict),
Function.FUNCTION_MIN: f.min(field, **alias_dict),
Function.FUNCTION_UNIQ: f.uniq(field, **alias_dict),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ def _build_query(request: TraceItemTableRequest) -> Query:
)
elif column.HasField("aggregation"):
function_expr = aggregation_to_expression(column.aggregation)
print("function_expr_1", function_expr)
# aggregation label may not be set and the column label takes priority anyways.
function_expr = replace(function_expr, alias=column.label)
print("function_expr_2", function_expr)
selected_columns.append(
SelectedExpression(name=column.label, expression=function_expr)
)
Expand Down Expand Up @@ -188,7 +186,6 @@ def _build_query(request: TraceItemTableRequest) -> Query:
raise BadSnubaRPCRequestException(
"Column is neither an aggregate or an attribute"
)
print("selected_columnsss", selected_columns)
res = Query(
from_clause=entity,
selected_columns=selected_columns,
Expand Down Expand Up @@ -244,7 +241,6 @@ def _convert_results(

for column in request.columns:
if column.HasField("key"):
print("columnnnnkey", column, column.key, column.key.type)
if column.key.type == AttributeKey.TYPE_BOOLEAN:
converters[column.label] = lambda x: AttributeValue(val_bool=bool(x))
elif column.key.type == AttributeKey.TYPE_STRING:
Expand All @@ -262,8 +258,6 @@ def _convert_results(
"column is neither an attribute or aggregation"
)

print("covertersss", converters)

res: defaultdict[str, TraceItemColumnValues] = defaultdict(TraceItemColumnValues)
for row in data:
for column_name, value in row.items():
Expand Down Expand Up @@ -301,16 +295,13 @@ def trace_item_type(cls) -> TraceItemType.ValueType:
return TraceItemType.TRACE_ITEM_TYPE_SPAN

def resolve(self, in_msg: TraceItemTableRequest) -> TraceItemTableResponse:
print("in_msgggg", in_msg)
snuba_request = _build_snuba_request(in_msg)
res = run_query(
dataset=PluggableDataset(name="eap", all_entities=[]),
request=snuba_request,
timer=self._timer,
)
print("ressss", res)
column_values = _convert_results(in_msg, res.result.get("data", []))
print("column_valuesss", column_values)
response_meta = extract_response_meta(
in_msg.meta.request_id,
in_msg.meta.debug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,37 +557,37 @@ def test_table_with_aggregates(self, setup_teardown: Any) -> None:
)
response = EndpointTraceItemTable().execute(message)

print("responseee", response.column_values)

print(
"RESULTSSS",
[
TraceItemColumnValues(
attribute_name="location",
results=[
AttributeValue(val_str="backend"),
AttributeValue(val_str="frontend"),
AttributeValue(val_str="mobile"),
],
),
TraceItemColumnValues(
attribute_name="max(my.float.field)",
results=[
AttributeValue(val_double=101.2),
AttributeValue(val_double=101.2),
AttributeValue(val_double=101.2),
],
),
TraceItemColumnValues(
attribute_name="avg(my.float.field)",
results=[
AttributeValue(val_double=101.2),
AttributeValue(val_double=101.2),
AttributeValue(val_double=101.2),
],
),
],
)
# print("responseee", response.column_values)
#
# print(
# "RESULTSSS",
# [
# TraceItemColumnValues(
# attribute_name="location",
# results=[
# AttributeValue(val_str="backend"),
# AttributeValue(val_str="frontend"),
# AttributeValue(val_str="mobile"),
# ],
# ),
# TraceItemColumnValues(
# attribute_name="max(my.float.field)",
# results=[
# AttributeValue(val_double=101.2),
# AttributeValue(val_double=101.2),
# AttributeValue(val_double=101.2),
# ],
# ),
# TraceItemColumnValues(
# attribute_name="avg(my.float.field)",
# results=[
# AttributeValue(val_double=101.2),
# AttributeValue(val_double=101.2),
# AttributeValue(val_double=101.2),
# ],
# ),
# ],
# )

assert response.column_values == [
TraceItemColumnValues(
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def test_aggregation_filter_basic(self, setup_teardown: Any) -> None:
aggregation=AttributeAggregation(
aggregate=Function.FUNCTION_SUM,
key=AttributeKey(
type=AttributeKey.TYPE_FLOAT, name="my.float.field"
type=AttributeKey.TYPE_DOUBLE, name="my.float.field"
),
label="sum(my.float.field)",
extrapolation_mode=ExtrapolationMode.EXTRAPOLATION_MODE_NONE,
Expand All @@ -1179,7 +1179,7 @@ def test_aggregation_filter_basic(self, setup_teardown: Any) -> None:
aggregation=AttributeAggregation(
aggregate=Function.FUNCTION_SUM,
key=AttributeKey(
type=AttributeKey.TYPE_FLOAT, name="my.float.field"
type=AttributeKey.TYPE_DOUBLE, name="my.float.field"
),
label="this-doesnt-matter-and-can-be-left-out",
),
Expand All @@ -1200,8 +1200,8 @@ def test_aggregation_filter_basic(self, setup_teardown: Any) -> None:
TraceItemColumnValues(
attribute_name="sum(my.float.field)",
results=[
AttributeValue(val_float=1214.4),
AttributeValue(val_float=3036),
AttributeValue(val_double=1214.4),
AttributeValue(val_double=3036),
],
),
]
Expand Down Expand Up @@ -1311,8 +1311,8 @@ def test_aggregation_filter_and_or(self, setup_teardown: Any) -> None:
TraceItemColumnValues(
attribute_name="sum(my.float.field)",
results=[
AttributeValue(val_float=1214.4),
AttributeValue(val_float=3036),
AttributeValue(val_double=1214.4),
AttributeValue(val_double=3036),
],
),
]
Expand Down Expand Up @@ -1365,9 +1365,9 @@ def test_aggregation_filter_and_or(self, setup_teardown: Any) -> None:
TraceItemColumnValues(
attribute_name="sum(my.float.field)",
results=[
AttributeValue(val_float=303.6),
AttributeValue(val_float=1214.4),
AttributeValue(val_float=3036),
AttributeValue(val_double=303.6),
AttributeValue(val_double=1214.4),
AttributeValue(val_double=3036),
],
),
]
Expand Down

0 comments on commit 628c371

Please sign in to comment.