https://delta.io logo
l

Lucas Zago

04/24/2023, 11:35 PM
hi friends, working with functions on apache 3.3 which you do not need pre define a col to work with functions. However if you chain with .
transform
, it returns that "it not possible to groupBy with .transform method" Here is my code:
def qtd_faturada(col1,col2):
return (sum(when(col1=='S',col2))
.otherwise(-col2))
def with_qtd_faturada(df,col1,col2):
return df.withColumn("qtd_faturada",with_qtd_faturada(col(col1),col(col2)))
df=(df
.select(A,B,C)
.groupBy(C)
.transform(with_qtd_faturada,col1="A",col2="B"))
Am I missing something ? Some advice would be really appreciated, 🙂
j

JosephK (exDatabricks)

04/24/2023, 11:37 PM
Not delta io
l

Lucas Zago

04/24/2023, 11:39 PM
Sorry for that
j

JosephK (exDatabricks)

04/24/2023, 11:39 PM
To answer your questions, group by returns a groupeddata and transform works on a an array. You'd use transform in a select statement
l

Lucas Zago

04/24/2023, 11:41 PM
Thanks for answering, even not being a delta question
5 Views