Skip to content

Commit 496add2

Browse files
committed
updated to use pyspark.sql functions
1 parent 3888ab4 commit 496add2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/sempy_labs/_helper_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ def _get_column_aggregate(
12501250

12511251
from pyspark.sql import SparkSession
12521252
from pyspark.sql.functions import approx_count_distinct
1253+
from pyspark.sql import functions as F
12531254

12541255
function = function.upper()
12551256
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
@@ -1260,7 +1261,7 @@ def _get_column_aggregate(
12601261
df = spark.read.format("delta").load(path)
12611262

12621263
if function in {"COUNTDISTINCT", "DISTINCTCOUNT"}:
1263-
result = df.selectExpr(f"COUNT(DISTINCT {column_name})")
1264+
result = df.select(F.count_distinct(F.col(column_name)))
12641265
elif "APPROX" in function:
12651266
result = df.select(approx_count_distinct(column_name))
12661267
else:

0 commit comments

Comments
 (0)