class_docstr: Generates an SQL query plan from a node in the a metric dataflow plan.
class_docstr_tok: ["Generates","an","SQL","query","plan","from","a","node","in","the","a","metric","dataflow","plan","."]
docstr: Generates the query that realizes the behavior of AggregateMeasuresNode.
  
  This will produce a query that aggregates all measures from a given input semantic model per the
  measure spec
  
  In the event the input aggregations are applied to measures with aliases set, in case of, e.g.,
  a constraint applied to one instance of the measure but not another one, this method will
  apply the rename in the select statement for this node, and propagate that further along via an
  instance set transform to rename the measures.
  
  Any node operating on the output of this node will need to use the measure aliases instead of
  the measure names as references.
docstr_tok: ["Generates","the","query","that","realizes","the","behavior","of","AggregateMeasuresNode",".","This","will","produce","a","query","that","aggregates","all","measures","from","a","given","input","semantic","model","per","the","measure","spec","In","the","event","the","input","aggregations","are","applied","to","measures","with","aliases","set",",","in","case","of",",","e.g.",",","a","constraint","applied","to","one","instance","of","the","measure","but","not","another","one",",","this","method","will","apply","the","rename","in","the","select","statement","for","this","node",",","and","propagate","that","further","along","via","an","instance","set","transform","to","rename","the","measures",".","Any","node","operating","on","the","output","of","this","node","will","need","to","use","the","measure","aliases","instead","of","the","measure","names","as","references","."]
code: def visit_aggregate_measures_node(
      self, node: AggregateMeasuresNode
  ) -> SqlDataSet:
      """Generates the query that realizes the behavior of AggregateMeasuresNode.
  
      This will produce a query that aggregates all measures from a given input semantic model per the
      measure spec
  
      In the event the input aggregations are applied to measures with aliases set, in case of, e.g.,
      a constraint applied to one instance of the measure but not another one, this method will
      apply the rename in the select statement for this node, and propagate that further along via an
      instance set transform to rename the measures.
  
      Any node operating on the output of this node will need to use the measure aliases instead of
      the measure names as references.
  
      """
      # Get the data from the parent, and change measure instances to the aggregated state.
      from_data_set: SqlDataSet = node.parent_node.accept(self)
      aggregated_instance_set = from_data_set.instance_set.transform(
          ChangeMeasureAggregationState(
              {
                  AggregationState.NON_AGGREGATED: AggregationState.COMPLETE,
                  AggregationState.COMPLETE: AggregationState.COMPLETE,
                  AggregationState.PARTIAL: AggregationState.COMPLETE,
              }
          )
      )
      # Also, the columns should always follow the resolver format.
      aggregated_instance_set = aggregated_instance_set.transform(
          ChangeAssociatedColumns(self._column_association_resolver)
      )
  
      # Add fill null property to corresponding measure spec
      aggregated_instance_set = aggregated_instance_set.transform(
          UpdateMeasureFillNullsWith(
              metric_input_measure_specs=node.metric_input_measure_specs
          )
      )
      from_data_set_alias = self._next_unique_table_alias()
  
      # Convert the instance set into a set of select column statements with updated aliases
      # Note any measure with an alias requirement will be recast at this point, and
      # downstream consumers of the resulting node must therefore request aggregated measures
      # by their appropriate aliases
      select_column_set: SelectColumnSet = aggregated_instance_set.transform(
          CreateSelectColumnsWithMeasuresAggregated(
              table_alias=from_data_set_alias,
              column_resolver=self._column_association_resolver,
              semantic_model_lookup=self._semantic_model_lookup,
              metric_input_measure_specs=node.metric_input_measure_specs,
          )
      )
  
      if any((spec.alias for spec in node.metric_input_measure_specs)):
          # This is a little silly, but we need to update the column instance set with the new aliases
          # There are a number of refactoring options - simplest is to consolidate this with
          # ChangeMeasureAggregationState, assuming there are no ordering dependencies up above
          aggregated_instance_set = aggregated_instance_set.transform(
              AliasAggregatedMeasures(
                  metric_input_measure_specs=node.metric_input_measure_specs
              )
          )
          # and make sure we follow the resolver format for any newly aliased measures....
          aggregated_instance_set = aggregated_instance_set.transform(
              ChangeAssociatedColumns(self._column_association_resolver)
          )
  
      return SqlDataSet(
          instance_set=aggregated_instance_set,
          sql_select_node=SqlSelectStatementNode(
              description=node.description,
              # This will generate expressions with the appropriate aggregation functions e.g. SUM()
              select_columns=select_column_set.as_tuple(),
              from_source=from_data_set.sql_select_node,
              from_source_alias=from_data_set_alias,
              joins_descs=(),
              # This will generate expressions to group by the columns that don't correspond to a measure instance.
              group_bys=select_column_set.without_measure_columns().as_tuple(),
              where=None,
              order_bys=(),
          ),
      )
  
imports: from __future__ import annotations
  import logging
  from collections import OrderedDict
  from typing import List, Optional, Sequence, Tuple, Union
  from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
  from dbt_semantic_interfaces.protocols.metric import MetricInputMeasure, MetricType
  from dbt_semantic_interfaces.references import MetricModelReference
  from dbt_semantic_interfaces.type_enums.aggregation_type import AggregationType
  from dbt_semantic_interfaces.type_enums.conversion_calculation_type import ConversionCalculationType
  from dbt_semantic_interfaces.validations.unique_valid_name import MetricFlowReservedKeywords
  from metricflow.aggregation_properties import AggregationState
  from metricflow.dag.id_generation import IdGeneratorRegistry
  from metricflow.dataflow.dataflow_plan import AddGeneratedUuidColumnNode, AggregateMeasuresNode, BaseOutput, CombineAggregatedOutputsNode, ComputedMetricsOutput, ComputeMetricsNode, ConstrainTimeRangeNode, DataflowPlanNodeVisitor, FilterElementsNode, JoinConversionEventsNode, JoinOverTimeRangeNode, JoinToBaseOutputNode, JoinToTimeSpineNode, MetricTimeDimensionTransformNode, MinMaxNode, OrderByLimitNode, ReadSqlSourceNode, SemiAdditiveJoinNode, WhereConstraintNode, WriteToResultDataframeNode, WriteToResultTableNode
  from metricflow.dataset.dataset import DataSet
  from metricflow.dataset.sql_dataset import SqlDataSet
  from metricflow.filters.time_constraint import TimeRangeConstraint
  from metricflow.instances import InstanceSet, MetadataInstance, MetricInstance, TimeDimensionInstance
  from metricflow.model.semantic_manifest_lookup import SemanticManifestLookup
  from metricflow.plan_conversion.instance_converters import AddLinkToLinkableElements, AddMetadata, AddMetrics, AliasAggregatedMeasures, ChangeAssociatedColumns, ChangeMeasureAggregationState, ConvertToMetadata, CreateSelectColumnForCombineOutputNode, CreateSelectColumnsForInstances, CreateSelectColumnsWithMeasuresAggregated, CreateSqlColumnReferencesForInstances, FilterElements, FilterLinkableInstancesWithLeadingLink, RemoveMeasures, RemoveMetrics, UpdateMeasureFillNullsWith, create_select_columns_for_instance_sets
  from metricflow.plan_conversion.select_column_gen import SelectColumnSet
  from metricflow.plan_conversion.spec_transforms import CreateColumnAssociations, CreateSelectCoalescedColumnsForLinkableSpecs, SelectOnlyLinkableSpecs
  from metricflow.plan_conversion.sql_join_builder import AnnotatedSqlDataSet, ColumnEqualityDescription, SqlQueryPlanJoinBuilder
  from metricflow.plan_conversion.time_spine import TimeSpineSource
  from metricflow.protocols.sql_client import SqlEngine
  from metricflow.specs.column_assoc import ColumnAssociation, ColumnAssociationResolver, SingleColumnCorrelationKey
  from metricflow.specs.specs import InstanceSpecSet, MeasureSpec, MetadataSpec, MetricSpec, TimeDimensionSpec
  from metricflow.sql.optimizer.optimization_levels import SqlQueryOptimizationLevel, SqlQueryOptimizerConfiguration
  from metricflow.sql.sql_exprs import SqlAggregateFunctionExpression, SqlBetweenExpression, SqlColumnReference, SqlColumnReferenceExpression, SqlComparison, SqlComparisonExpression, SqlDateTruncExpression, SqlExpressionNode, SqlExtractExpression, SqlFunction, SqlFunctionExpression, SqlGenerateUuidExpression, SqlLogicalExpression, SqlLogicalOperator, SqlRatioComputationExpression, SqlStringExpression, SqlStringLiteralExpression, SqlWindowFunction, SqlWindowFunctionExpression, SqlWindowOrderByArgument
  from metricflow.sql.sql_plan import SqlJoinDescription, SqlJoinType, SqlOrderByDescription, SqlQueryPlan, SqlQueryPlanNode, SqlSelectColumn, SqlSelectStatementNode, SqlTableFromClauseNode
  from metricflow.time.time_constants import ISO8601_PYTHON_FORMAT
label_desc: Use image node_id 8 for calling the DataflowToSqlQueryPlanConverter obj's underlying member method code with example usage: obj.visit_aggregate_measures_node(node) and returns: SqlDataSet