class_docstr: Converts a semantic model in the model to a data set that can be used with the dataflow plan builder.
  
  Entity links generally refer to the entities used to join the measure source to the dimension source. For
  example, the dimension name "user_id__device_id__platform" has entity links "user_id" and "device_id" and would
  mean that the measure source was joined by "user_id" to an intermediate source, and then it was joined by
  "device_id" to the source containing the "platform" dimension.
class_docstr_tok: ["Converts","a","semantic","model","in","the","model","to","a","data","set","that","can","be","used","with","the","dataflow","plan","builder",".","Entity","links","generally","refer","to","the","entities","used","to","join","the","measure","source","to","the","dimension","source",".","For","example",",","the","dimension","name","``","user_id__device_id__platform","''","has","entity","links","``","user_id","''","and","``","device_id","''","and","would","mean","that","the","measure","source","was","joined","by","``","user_id","''","to","an","intermediate","source",",","and","then","it","was","joined","by","''","device_id","''","to","the","source","containing","the","``","platform","''","dimension","."]
docstr: Create an SQL source data set from a semantic model in the model.
docstr_tok: ["Create","an","SQL","source","data","set","from","a","semantic","model","in","the","model","."]
code: def create_sql_source_data_set(
      self, semantic_model: SemanticModel
  ) -> SemanticModelDataSet:
      """Create an SQL source data set from a semantic model in the model."""
      # Gather all instances and columns from all semantic models.
      all_measure_instances: List[MeasureInstance] = []
      all_dimension_instances: List[DimensionInstance] = []
      all_time_dimension_instances: List[TimeDimensionInstance] = []
      all_entity_instances: List[EntityInstance] = []
  
      all_select_columns: List[SqlSelectColumn] = []
      from_source_alias = IdGeneratorRegistry.for_class(
          self.__class__
      ).create_id(f"{semantic_model.name}_src")
  
      # Handle measures
      if len(semantic_model.measures) > 0:
          measure_instances, select_columns = self._convert_measures(
              semantic_model_name=semantic_model.name,
              measures=semantic_model.measures,
              table_alias=from_source_alias,
          )
          all_measure_instances.extend(measure_instances)
          all_select_columns.extend(select_columns)
  
      # Group by items in the semantic model can be accessed though a subset of the entities defined in the model.
      possible_entity_links: List[Tuple[EntityReference, ...]] = [
          (),
      ]
  
      for (
          entity_link
      ) in SemanticModelLookup.entity_links_for_local_elements(
          semantic_model
      ):
          possible_entity_links.append((entity_link,))
  
      # Handle dimensions
      conversion_results = [
          self._convert_dimensions(
              semantic_model_name=semantic_model.name,
              dimensions=semantic_model.dimensions,
              entity_links=entity_links,
              table_alias=from_source_alias,
          )
          for entity_links in possible_entity_links
      ]
  
      all_dimension_instances.extend(
          [
              dimension_instance
              for conversion_result in conversion_results
              for dimension_instance in conversion_result.dimension_instances
          ]
      )
  
      all_time_dimension_instances.extend(
          [
              time_dimension_instance
              for conversion_result in conversion_results
              for time_dimension_instance in conversion_result.time_dimension_instances
          ]
      )
  
      all_select_columns.extend(
          [
              select_column
              for conversion_result in conversion_results
              for select_column in conversion_result.select_columns
          ]
      )
  
      # Handle entities
      for entity_links in possible_entity_links:
          (
              entity_instances,
              select_columns,
          ) = self._create_entity_instances(
              semantic_model_name=semantic_model.name,
              entities=semantic_model.entities,
              entity_links=entity_links,
              table_alias=from_source_alias,
          )
          all_entity_instances.extend(entity_instances)
          all_select_columns.extend(select_columns)
  
      # Generate the "from" clause depending on whether it's an SQL query or an SQL table.
      from_source: Optional[SqlQueryPlanNode] = None
      from_source = SqlTableFromClauseNode(
          sql_table=SqlTable.from_string(
              semantic_model.node_relation.relation_name
          )
      )
  
      select_statement_node = SqlSelectStatementNode(
          description=f"Read Elements From Semantic Model '{semantic_model.name}'",
          select_columns=tuple(all_select_columns),
          from_source=from_source,
          from_source_alias=from_source_alias,
          joins_descs=(),
          where=None,
          group_bys=(),
          order_bys=(),
      )
  
      return SemanticModelDataSet(
          semantic_model_reference=SemanticModelReference(
              semantic_model_name=semantic_model.name
          ),
          instance_set=InstanceSet(
              measure_instances=tuple(all_measure_instances),
              dimension_instances=tuple(all_dimension_instances),
              time_dimension_instances=tuple(
                  all_time_dimension_instances
              ),
              entity_instances=tuple(all_entity_instances),
              metric_instances=(),
          ),
          sql_select_node=select_statement_node,
      )
  
imports: from __future__ import annotations
  import logging
  import re
  from dataclasses import dataclass
  from typing import List, Optional, Sequence, Tuple
  from dbt_semantic_interfaces.protocols.dimension import Dimension, DimensionType
  from dbt_semantic_interfaces.protocols.entity import Entity
  from dbt_semantic_interfaces.protocols.measure import Measure
  from dbt_semantic_interfaces.protocols.semantic_model import SemanticModel
  from dbt_semantic_interfaces.references import SemanticModelElementReference, SemanticModelReference
  from dbt_semantic_interfaces.type_enums.date_part import DatePart
  from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
  from metricflow.aggregation_properties import AggregationState
  from metricflow.dag.id_generation import IdGeneratorRegistry
  from metricflow.dataflow.sql_table import SqlTable
  from metricflow.dataset.semantic_model_adapter import SemanticModelDataSet
  from metricflow.instances import DimensionInstance, EntityInstance, InstanceSet, MeasureInstance, TimeDimensionInstance
  from metricflow.model.semantics.semantic_model_lookup import SemanticModelLookup
  from metricflow.model.spec_converters import MeasureConverter
  from metricflow.specs.column_assoc import ColumnAssociationResolver
  from metricflow.specs.specs import DEFAULT_TIME_GRANULARITY, DimensionSpec, EntityReference, EntitySpec, TimeDimensionSpec
  from metricflow.sql.sql_exprs import SqlColumnReference, SqlColumnReferenceExpression, SqlDateTruncExpression, SqlExpressionNode, SqlExtractExpression, SqlStringExpression
  from metricflow.sql.sql_plan import SqlQueryPlanNode, SqlSelectColumn, SqlSelectStatementNode, SqlTableFromClauseNode
label_desc: Use image node_id 10 for calling the SemanticModelToDataSetConverter obj's underlying member method code with example usage: obj.create_sql_source_data_set(semantic_model) and returns: SemanticModelDataSet