Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from typing_extensions import override

from metricflow_semantics.collection_helpers.syntactic_sugar import mf_first_item
from metricflow_semantics.errors.error_classes import InvalidQueryException
from metricflow_semantics.experimental.cache.mf_cache import ResultCache
from metricflow_semantics.experimental.dataclass_helpers import fast_frozen_dataclass
from metricflow_semantics.experimental.dsi.manifest_object_lookup import ManifestObjectLookup
from metricflow_semantics.experimental.metricflow_exception import MetricflowInternalError
from metricflow_semantics.experimental.mf_graph.graph_labeling import MetricflowGraphLabel
from metricflow_semantics.experimental.mf_graph.path_finding.pathfinder import MetricflowPathfinder
from metricflow_semantics.experimental.ordered_set import FrozenOrderedSet, MutableOrderedSet
Expand Down Expand Up @@ -163,9 +163,10 @@ def get_common_set(
for label in node_labels:
matching_nodes = self._semantic_graph.nodes_with_labels(label)
if len(matching_nodes) != 1:
raise MetricflowInternalError(
raise InvalidQueryException(
LazyFormat(
"Did not find exactly 1 node in the semantic graph for the given label",
"The given name is not valid. Please check that it matches one specified in the manifest.",
element_name=mf_first_item(label_to_references[label]).element_name,
label=label,
associated_references=label_to_references.get(label),
matching_nodes=matching_nodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from _pytest.fixtures import FixtureRequest
from dbt_semantic_interfaces.protocols import SemanticManifest
from dbt_semantic_interfaces.references import MeasureReference, MetricReference
from metricflow_semantics.errors.error_classes import InvalidQueryException
from metricflow_semantics.model.linkable_element_property import GroupByItemProperty
from metricflow_semantics.model.semantics.element_filter import GroupByItemSetFilter
from metricflow_semantics.model.semantics.linkable_element_set_base import BaseGroupByItemSet
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration
from metricflow_semantics.test_helpers.snapshot_helpers import assert_str_snapshot_equal

from tests_metricflow_semantics.experimental.semantic_graph.sg_fixtures import SemanticGraphTestFixture
from tests_metricflow_semantics.experimental.semantic_graph.sg_tester import SemanticGraphTester
Expand Down Expand Up @@ -91,3 +93,17 @@ def test_set_filtering_for_distinct_values_query(sg_tester: SemanticGraphTester)
complete_set=complete_set,
filtered_set_callable=lambda set_filter: sg_tester.sg_resolver.get_set_for_distinct_values_query(set_filter),
)


def test_invalid_metric(
request: FixtureRequest, mf_test_configuration: MetricFlowTestConfiguration, sg_tester: SemanticGraphTester
) -> None:
"""Check the exception associated with an invalid metric name."""
with pytest.raises(InvalidQueryException) as exc_info:
sg_tester.sg_resolver.get_common_set(metric_references=(MetricReference("invalid_metric"),))

assert_str_snapshot_equal(
request=request,
snapshot_configuration=mf_test_configuration,
snapshot_str=str(exc_info.value),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
test_name: test_invalid_metric
test_filename: test_sg_resolver_output.py
docstring:
Check the exception associated with an invalid metric name.
---
The given name is not valid. Please check that it matches one specified in the manifest.
element_name: invalid_metric
label: MetricLabel(metric_name='invalid_metric')
associated_references: {MetricReference(element_name='invalid_metric')}
matching_nodes: {}
measure_nodes:
{
Measure(identity_verifications),
Measure(visits),
Measure(visitors),
Measure(views),
Measure(bookings),
Measure(instant_bookings),
Measure(booking_value),
Measure(max_booking_value),
Measure(min_booking_value),
Measure(bookers),
Measure(average_booking_value),
Measure(referred_bookings),
Measure(median_booking_value),
Measure(booking_value_p99),
Measure(discrete_booking_value_p99),
Measure(approximate_continuous_booking_value_p99),
Measure(approximate_discrete_booking_value_p99),
Measure(booking_payments),
Measure(account_balance),
Measure(total_account_balance_first_day),
Measure(current_account_balance_by_user),
Measure(total_account_balance_first_day_of_month),
Measure(new_users),
Measure(archived_users),
Measure(buys),
Measure(buyers),
Measure(buys_month),
Measure(txn_revenue),
Measure(listings),
Measure(largest_listing),
Measure(smallest_listing),
}
metric_nodes:
{
BaseMetric(bookings),
BaseMetric(average_booking_value),
BaseMetric(instant_bookings),
BaseMetric(booking_value),
BaseMetric(max_booking_value),
BaseMetric(min_booking_value),
BaseMetric(instant_booking_value),
BaseMetric(average_instant_booking_value),
BaseMetric(booking_value_for_non_null_listing_id),
BaseMetric(bookers),
BaseMetric(booking_payments),
BaseMetric(views),
BaseMetric(listings),
BaseMetric(lux_listings),
BaseMetric(smallest_listing),
BaseMetric(largest_listing),
BaseMetric(identity_verifications),
BaseMetric(revenue),
BaseMetric(trailing_2_months_revenue),
BaseMetric(revenue_all_time),
BaseMetric(every_two_days_bookers),
BaseMetric(revenue_mtd),
DerivedMetric(booking_fees),
DerivedMetric(booking_fees_per_booker),
DerivedMetric(booking_fees_last_week_per_booker_this_week),
DerivedMetric(views_times_booking_value),
DerivedMetric(bookings_per_booker),
DerivedMetric(bookings_per_view),
DerivedMetric(bookings_per_listing),
DerivedMetric(bookings_per_dollar),
BaseMetric(total_account_balance_first_day),
BaseMetric(current_account_balance_by_user),
DerivedMetric(instant_booking_fraction_of_max_value),
DerivedMetric(lux_booking_fraction_of_max_value),
DerivedMetric(lux_booking_value_rate_expr),
DerivedMetric(instant_booking_value_ratio),
DerivedMetric(instant_lux_booking_value_rate),
DerivedMetric(regional_starting_balance_ratios),
DerivedMetric(double_counted_delayed_bookings),
BaseMetric(referred_bookings),
DerivedMetric(non_referred_bookings_pct),
DerivedMetric(booking_value_sub_instant),
DerivedMetric(booking_value_sub_instant_add_10),
DerivedMetric(bookings_per_lux_listing_derived),
DerivedMetric(instant_plus_non_referred_bookings_pct),
DerivedMetric(trailing_2_months_revenue_sub_10),
DerivedMetric(booking_value_per_view),
BaseMetric(median_booking_value),
BaseMetric(booking_value_p99),
BaseMetric(discrete_booking_value_p99),
BaseMetric(approximate_continuous_booking_value_p99),
BaseMetric(approximate_discrete_booking_value_p99),
DerivedMetric(bookings_growth_2_weeks),
BaseMetric(bookings_all_time),
DerivedMetric(bookings_all_time_at_start_of_month),
DerivedMetric(bookings_growth_since_start_of_month),
DerivedMetric(bookings_since_start_of_month),
DerivedMetric(bookings_month_start_compared_to_1_month_prior),
DerivedMetric(bookings_5_day_lag),
DerivedMetric(every_2_days_bookers_2_days_ago),
BaseMetric(bookings_join_to_time_spine),
BaseMetric(visit_buy_conversion_rate_7days),
BaseMetric(visit_buy_conversion_rate),
BaseMetric(visit_buy_conversions),
BaseMetric(visit_buy_conversion_rate_with_monthly_conversion),
BaseMetric(visit_buy_conversion_rate_by_session),
BaseMetric(bookings_fill_nulls_with_0_without_time_spine),
BaseMetric(bookings_fill_nulls_with_0),
BaseMetric(instant_bookings_with_measure_filter),
BaseMetric(bookings_join_to_time_spine_with_tiered_filters),
BaseMetric(every_two_days_bookers_fill_nulls_with_0),
DerivedMetric(bookings_growth_2_weeks_fill_nulls_with_0),
DerivedMetric(bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset),
DerivedMetric(bookings_offset_once),
DerivedMetric(bookings_offset_twice),
DerivedMetric(bookings_offset_alien_day),
DerivedMetric(bookings_at_start_of_month),
DerivedMetric(booking_fees_since_start_of_month),
DerivedMetric(bookings_1_month_ago),
DerivedMetric(bookings_mom),
DerivedMetric(derived_bookings_0),
DerivedMetric(derived_bookings_1),
DerivedMetric(twice_bookings_fill_nulls_with_0_without_time_spine),
DerivedMetric(nested_fill_nulls_without_time_spine),
BaseMetric(visit_buy_conversion_rate_7days_fill_nulls_with_0),
BaseMetric(active_listings),
DerivedMetric(popular_listing_bookings_per_booker),
DerivedMetric(derived_shared_alias_1a),
DerivedMetric(derived_shared_alias_1b),
DerivedMetric(derived_shared_alias_2),
DerivedMetric(bookings_offset_one_alien_day),
DerivedMetric(bookings_alien_day_over_alien_day),
BaseMetric(trailing_7_days_bookings),
DerivedMetric(trailing_7_days_bookings_offset_1_week),
BaseMetric(subdaily_cumulative_window_metric),
BaseMetric(subdaily_cumulative_grain_to_date_metric),
BaseMetric(archived_users),
DerivedMetric(subdaily_offset_window_metric),
DerivedMetric(subdaily_offset_grain_to_date_metric),
BaseMetric(subdaily_join_to_time_spine_metric),
BaseMetric(simple_subdaily_metric_default_day),
BaseMetric(simple_subdaily_metric_default_hour),
BaseMetric(archived_users_join_to_time_spine),
BaseMetric(total_account_balance_first_day_of_month),
BaseMetric(new_users),
}
2 changes: 1 addition & 1 deletion tests_metricflow/snapshot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def assert_sql_snapshot_equal(
def assert_str_snapshot_equal( # type: ignore[misc]
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
snapshot_id: str,
snapshot_str: str,
snapshot_id: str = "result",
snapshot_file_extension: str = ".txt",
sql_engine: Optional[SqlEngine] = None,
expectation_description: Optional[str] = None,
Expand Down
Loading