class_docstr: Expression renderer for the DuckDB engine.
class_docstr_tok: ["Expression","renderer","for","the","DuckDB","engine","."]
docstr: Render a percentile expression for DuckDB.
docstr_tok: ["Render","a","percentile","expression","for","DuckDB","."]
code: def visit_percentile_expr(
      self, node: SqlPercentileExpression
  ) -> SqlExpressionRenderResult:
      """Render a percentile expression for DuckDB."""
      arg_rendered = self.render_sql_expr(node.order_by_arg)
      params = arg_rendered.bind_parameters
      percentile = node.percentile_args.percentile
  
      if (
          node.percentile_args.function_type
          is SqlPercentileFunctionType.CONTINUOUS
      ):
          function_str = "PERCENTILE_CONT"
      elif (
          node.percentile_args.function_type
          is SqlPercentileFunctionType.DISCRETE
      ):
          function_str = "PERCENTILE_DISC"
      elif (
          node.percentile_args.function_type
          is SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS
      ):
          return SqlExpressionRenderResult(
              sql=f"approx_quantile({arg_rendered.sql}, {percentile})",
              bind_parameters=params,
          )
      elif (
          node.percentile_args.function_type
          is SqlPercentileFunctionType.APPROXIMATE_DISCRETE
      ):
          raise RuntimeError(
              "Approximate discrete percentile aggregatew not supported for DuckDB. Set "
              + "use_discrete_percentile and/or use_approximate_percentile to false in all percentile measures."
          )
      else:
          assert_values_exhausted(node.percentile_args.function_type)
  
      return SqlExpressionRenderResult(
          sql=f"{function_str}({percentile}) WITHIN GROUP (ORDER BY ({arg_rendered.sql}))",
          bind_parameters=params,
      )
  
file_path: metricflow/metricflow/sql/render/duckdb_renderer.py
imports: from __future__ import annotations
  from typing import Collection
  from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
  from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
  from typing_extensions import override
  from metricflow.sql.render.expr_renderer import DefaultSqlExpressionRenderer, SqlExpressionRenderer, SqlExpressionRenderResult
  from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
  from metricflow.sql.sql_bind_parameters import SqlBindParameters
  from metricflow.sql.sql_exprs import SqlGenerateUuidExpression, SqlPercentileExpression, SqlPercentileFunctionType, SqlSubtractTimeIntervalExpression
label_desc: Use image node_id 4 for calling the DuckDbSqlExpressionRenderer obj's underlying member method code with example usage: obj.visit_percentile_expr(node) and returns: SqlExpressionRenderResult, SqlExpressionRenderResult