original_docstring: 
      Give the sql to query the given model
      :param dialect: SQL Dialect
      :param model: model to convert to sql
      :param compiler_cache: Dictionary mapping model hashes to already compiled results
      :return: executable select query
      
docstring: Give the sql to query the given model
docstring_tokens: Give the sql to query the given model
code: def _to_sql_materialized_node(
          dialect: Dialect,
          model: SqlModel,
          compiler_cache: Dict[str, List['SemiCompiledTuple']],
  ) -> str:
      """
      Give the sql to query the given model
      :param dialect: SQL Dialect
      :param model: model to convert to sql
      :param compiler_cache: Dictionary mapping model hashes to already compiled results
      :return: executable select query
      """
      queries = _to_cte_sql(dialect=dialect, compiler_cache=compiler_cache, model=model)
      queries = _filter_duplicate_ctes(queries)
      if len(queries) == 0:
          # _to_cte_sql should never return an empty list, but this make it clear we have a len > 0 below.
          raise Exception('Internal error. No models to compile')
  
      if len(queries) == 1:
          return _materialize(dialect=dialect, sql_query=queries[0].sql, model=model)
  
      # case: len(result) > 1
      sql = 'with '
      sql += ',\n'.join(f'{row.quoted_cte_name} as ({row.sql})' for row in queries[:-1])
      sql += '\n' + queries[-1].sql
      return _materialize(dialect=dialect, sql_query=sql, model=model)
code_tokens: def _to_sql_materialized_node ( dialect : Dialect , model : SqlModel , compiler_cache : Dict [ str , List [ 'SemiCompiledTuple' ] ] , ) -> str : queries = _to_cte_sql ( dialect = dialect , compiler_cache = compiler_cache , model = model ) queries = _filter_duplicate_ctes ( queries ) if len ( queries ) == 0 : raise Exception ( 'Internal error. No models to compile' ) if len ( queries ) == 1 : return _materialize ( dialect = dialect , sql_query = queries [ 0 ] . sql , model = model ) sql = 'with ' sql += ',\n' . join ( f'{row.quoted_cte_name} as ({row.sql})' for row in queries [ : - 1 ] ) sql += '\n' + queries [ - 1 ] . sql return _materialize ( dialect = dialect , sql_query = sql , model = model )
short_docstring: Give the sql to query the given model
short_docstring_tokens: Give the sql to query the given model
comment: """
      Give the sql to query the given model
      :param dialect: SQL Dialect
      :param model: model to convert to sql
      :param compiler_cache: Dictionary mapping model hashes to already compiled results
      :return: executable select query
      """$SEP$# _to_cte_sql should never return an empty list, but this make it clear we have a len > 0 below.$SEP$# case: len(result) > 1