Skip to content

Commit

Permalink
move definition
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-yzou committed Oct 4, 2024
1 parent fd2c840 commit f1d4b34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ def __repr__(self) -> str:


class PlanState(Enum):
"""
This is an enum class for the state that are extracted for a given SnowflakePlan
or SelectStatement.
"""

# the height of the given plan
PLAN_HEIGHT = "plan_height"
# the number of SelectStatement nodes in the plan that have
# _merge_projection_complexity_with_subquery set to True
NUM_SELECTS_WITH_COMPLEXITY_MERGED = "num_selects_with_complexity_merged"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@


class CompilationStageTelemetryField(Enum):
# dataframe query stats
QUERY_PLAN_HEIGHT = "query_plan_height"
QUERY_PLAN_NUM_SELECTS_WITH_COMPLEXITY_MERGED = (
"query_plan_num_selects_with_complexity_merged"
)
QUERY_PLAN_NUM_DUPLICATE_NODES = "query_plan_num_duplicate_nodes"
QUERY_PLAN_COMPLEXITY = "query_plan_complexity"

# types
TYPE_LARGE_QUERY_BREAKDOWN_OPTIMIZATION_SKIPPED = (
"snowpark_large_query_breakdown_optimization_skipped"
Expand Down
19 changes: 6 additions & 13 deletions src/snowflake/snowpark/_internal/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ class TelemetryField(Enum):
SQL_SIMPLIFIER_ENABLED = "sql_simplifier_enabled"
CTE_OPTIMIZATION_ENABLED = "cte_optimization_enabled"
LARGE_QUERY_BREAKDOWN_ENABLED = "large_query_breakdown_enabled"
# dataframe query stats
QUERY_PLAN_HEIGHT = "query_plan_height"
QUERY_PLAN_NUM_SELECTS_WITH_COMPLEXITY_MERGED = (
"query_plan_num_selects_with_complexity_merged"
)
QUERY_PLAN_NUM_DUPLICATE_NODES = "query_plan_num_duplicate_nodes"
QUERY_PLAN_COMPLEXITY = "query_plan_complexity"
# temp table cleanup
TYPE_TEMP_TABLE_CLEANUP = "snowpark_temp_table_cleanup"
NUM_TEMP_TABLES_CLEANED = "num_temp_tables_cleaned"
Expand Down Expand Up @@ -185,21 +178,21 @@ def wrap(*args, **kwargs):
0
]._session.sql_simplifier_enabled
try:
api_calls[0][TelemetryField.QUERY_PLAN_HEIGHT.value] = plan.plan_state[
PlanState.PLAN_HEIGHT
]
api_calls[0][
TelemetryField.QUERY_PLAN_NUM_SELECTS_WITH_COMPLEXITY_MERGED.value
CompilationStageTelemetryField.QUERY_PLAN_HEIGHT.value
] = plan.plan_state[PlanState.PLAN_HEIGHT]
api_calls[0][
CompilationStageTelemetryField.QUERY_PLAN_NUM_SELECTS_WITH_COMPLEXITY_MERGED.value
] = plan.plan_state[PlanState.NUM_SELECTS_WITH_COMPLEXITY_MERGED]
# The uuid for df._select_statement can be different from df._plan. Since plan
# can take both values, we cannot use plan.uuid. We always use df._plan.uuid
# to track the queries.
uuid = args[0]._plan.uuid
api_calls[0][CompilationStageTelemetryField.PLAN_UUID.value] = uuid
api_calls[0][
TelemetryField.QUERY_PLAN_NUM_DUPLICATE_NODES.value
CompilationStageTelemetryField.QUERY_PLAN_NUM_DUPLICATE_NODES.value
] = plan.num_duplicate_nodes
api_calls[0][TelemetryField.QUERY_PLAN_COMPLEXITY.value] = {
api_calls[0][CompilationStageTelemetryField.QUERY_PLAN_COMPLEXITY.value] = {
key.value: value
for key, value in plan.cumulative_node_complexity.items()
}
Expand Down

0 comments on commit f1d4b34

Please sign in to comment.