class_docstr: Task builder for standard data warehouse validation tasks.
class_docstr_tok: ["Task","builder","for","standard","data","warehouse","validation","tasks","."]
docstr: Generates a list of tasks for validating the measures of the manifest.
  
  The high level tasks returned are "short cut" queries which try to
  query all the measures for a given semantic model. If that query fails,
  one or more of the measures is incorrectly specified. Thus if the
  query fails, there are subtasks which query the individual measures
  on the semantic model to identify which have issues.
docstr_tok: ["Generates","a","list","of","tasks","for","validating","the","measures","of","the","manifest",".","The","high","level","tasks","returned","are","``","short","cut","''","queries","which","try","to","query","all","the","measures","for","a","given","semantic","model",".","If","that","query","fails",",","one","or","more","of","the","measures","is","incorrectly","specified",".","Thus","if","the","query","fails",",","there","are","subtasks","which","query","the","individual","measures","on","the","semantic","model","to","identify","which","have","issues","."]
code: def gen_measure_tasks(
      cls, manifest: SemanticManifest, sql_client: SqlClient
  ) -> List[DataWarehouseValidationTask]:
      """Generates a list of tasks for validating the measures of the manifest.
  
      The high level tasks returned are "short cut" queries which try to
      query all the measures for a given semantic model. If that query fails,
      one or more of the measures is incorrectly specified. Thus if the
      query fails, there are subtasks which query the individual measures
      on the semantic model to identify which have issues.
      """
      render_tools = QueryRenderingTools(manifest=manifest)
  
      tasks: List[DataWarehouseValidationTask] = []
      for semantic_model in manifest.semantic_models:
          if not semantic_model.measures:
              continue
  
          source_nodes = cls._semantic_model_nodes(
              render_tools=render_tools, semantic_model=semantic_model
          )
          dataset = render_tools.converter.create_sql_source_data_set(
              semantic_model
          )
          semantic_model_specs = (
              dataset.instance_set.spec_set.measure_specs
          )
  
          source_node_by_measure_spec: Dict[
              MeasureSpec, BaseOutput
          ] = {}
          measure_specs_source_node_pair = []
          for source_node in source_nodes:
              measure_specs = (
                  render_tools.node_resolver.get_output_data_set(
                      source_node
                  ).instance_set.spec_set.measure_specs
              )
              source_node_by_measure_spec.update(
                  {
                      measure_spec: source_node
                      for measure_spec in measure_specs
                  }
              )
              measure_specs_source_node_pair.append(
                  (measure_specs, source_node)
              )
  
          source_node_to_sub_task: DefaultDict[
              BaseOutput, List[DataWarehouseValidationTask]
          ] = collections.defaultdict(list)
          for spec in semantic_model_specs:
              obtained_source_node = source_node_by_measure_spec.get(
                  spec
              )
              assert (
                  obtained_source_node
              ), f"Unable to find generated source node for measure: {spec.element_name}"
  
              filter_elements_node = FilterElementsNode(
                  parent_node=obtained_source_node,
                  include_specs=InstanceSpecSet(
                      measure_specs=(spec,),
                  ),
              )
              source_node_to_sub_task[obtained_source_node].append(
                  DataWarehouseValidationTask(
                      query_and_params_callable=partial(
                          cls.renderize,
                          sql_client=sql_client,
                          plan_converter=render_tools.plan_converter,
                          plan_id=f"{semantic_model.name}_measure_{spec.element_name}_validation",
                          nodes=filter_elements_node,
                      ),
                      context=SemanticModelElementContext(
                          file_context=FileContext.from_metadata(
                              metadata=semantic_model.metadata
                          ),
                          semantic_model_element=SemanticModelElementReference(
                              semantic_model_name=semantic_model.name,
                              element_name=spec.element_name,
                          ),
                          element_type=SemanticModelElementType.MEASURE,
                      ),
                      error_message=f"Unable to query measure `{spec.element_name}` on semantic model `{semantic_model.name}` in data warehouse",
                  )
              )
  
          for (
              measure_specs,
              source_node,
          ) in measure_specs_source_node_pair:
              filter_elements_node = FilterElementsNode(
                  parent_node=source_node,
                  include_specs=InstanceSpecSet(
                      measure_specs=measure_specs
                  ),
              )
              tasks.append(
                  DataWarehouseValidationTask(
                      query_and_params_callable=partial(
                          cls.renderize,
                          sql_client=sql_client,
                          plan_converter=render_tools.plan_converter,
                          plan_id=f"{semantic_model.name}_all_measures_validation",
                          nodes=filter_elements_node,
                      ),
                      context=SemanticModelContext(
                          file_context=FileContext.from_metadata(
                              metadata=semantic_model.metadata
                          ),
                          semantic_model=SemanticModelReference(
                              semantic_model_name=semantic_model.name
                          ),
                      ),
                      error_message=f"Failed to query measures in data warehouse for semantic model `{semantic_model.name}`",
                      on_fail_subtasks=source_node_to_sub_task[
                          source_node
                      ],
                  )
              )
      return tasks
  
imports: from __future__ import annotations
  import collections
  import traceback
  from dataclasses import dataclass, field
  from functools import partial
  from math import floor
  from time import perf_counter
  from typing import Callable, DefaultDict, Dict, List, Optional, Sequence, Tuple, TypeVar
  from dbt_semantic_interfaces.protocols.metric import Metric
  from dbt_semantic_interfaces.protocols.semantic_manifest import SemanticManifest
  from dbt_semantic_interfaces.protocols.semantic_model import SemanticModel
  from dbt_semantic_interfaces.references import MetricModelReference, SemanticModelElementReference, SemanticModelReference
  from dbt_semantic_interfaces.validations.validator_helpers import FileContext, MetricContext, SemanticManifestValidationResults, SemanticModelContext, SemanticModelElementContext, SemanticModelElementType, ValidationContext, ValidationError, ValidationIssue, ValidationWarning
  from metricflow.dataflow.builder.node_data_set import DataflowPlanNodeOutputDataSetResolver
  from metricflow.dataflow.builder.source_node import SourceNodeBuilder
  from metricflow.dataflow.dataflow_plan import BaseOutput, FilterElementsNode
  from metricflow.dataset.convert_semantic_model import SemanticModelToDataSetConverter
  from metricflow.dataset.dataset import DataSet
  from metricflow.engine.metricflow_engine import MetricFlowEngine, MetricFlowExplainResult, MetricFlowQueryRequest
  from metricflow.model.semantic_manifest_lookup import SemanticManifestLookup
  from metricflow.plan_conversion.column_resolver import DunderColumnAssociationResolver
  from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter
  from metricflow.plan_conversion.time_spine import TimeSpineSource
  from metricflow.protocols.sql_client import SqlClient
  from metricflow.specs.specs import InstanceSpecSet, LinkableInstanceSpec, MeasureSpec
  from metricflow.sql.sql_bind_parameters import SqlBindParameters
label_desc: Use image node_id 7 for calling the DataWarehouseTaskBuilder obj's underlying member method code with example usage: obj.gen_measure_tasks(cls, manifest, sql_client) and returns: tasks