snowflake.snowpark.Session.semantic_view

Session.semantic_view(name: Union[str, Sequence[str]], *, dimensions: Optional[Union[str, Sequence[str]]] = None, metrics: Optional[Union[str, Sequence[str]]] = None, facts: Optional[Union[str, Sequence[str]]] = None, where: Optional[Union[str, Sequence[str]]] = None) → DataFrame[source]

Returns a DataFrame for a query against a semantic view.

At least one of dimensions, metrics, or facts is required; where alone is not a valid query.

A clause string is emitted verbatim, so several members and inline AS aliases can be written in one string. Clauses are always emitted in the order DIMENSIONS, METRICS, FACTS, WHERE, which sets the default column order; reorder with DataFrame.select().

Note

The strings passed to dimensions, metrics, facts, and where are emitted verbatim, without any check or escaping. Do not build them from untrusted input.

Parameters:
  • name – A string, or a sequence of strings, that specifies the semantic view name or fully-qualified object identifier (database name, schema name, and semantic view name).

  • dimensions – Members to group by, as a verbatim clause string or a sequence of member strings, which are comma-joined. A member may carry an inline alias, as "orders.revenue AS REV".

  • metrics – Members to aggregate, in the same forms as dimensions.

  • facts – Row-level members, in the same forms as dimensions. The server rejects facts together with metrics.

  • where – A condition applied before aggregation. Pass a string, which is emitted verbatim, or a sequence of conditions, which are AND-joined with each one parenthesized. WHERE takes a single expression, so a sequence is how several conditions compose. A condition may reference dimensions and facts, but not metrics: a metric is filtered after aggregation, with DataFrame.filter() on the returned DataFrame.

Examples:

>>> df = session.semantic_view(
...     "my_semantic_view",
...     dimensions="customers.region",
...     metrics="orders.revenue",
... )  

>>> df = session.semantic_view(
...     "my_db.my_schema.my_semantic_view",
...     dimensions=["customers.region", "customers.customer"],
...     metrics=["orders.revenue", "orders.order_count"],
...     where="customers.region = 'EMEA'",
... )  
>>> from snowflake.snowpark.functions import col  
>>> df.filter(col("REVENUE") > 400).sort(col("REGION")).show()  

This function or method is in public preview since 1.57.0.