0

In pyspark I have the following:

import pyspark.sql.functions as F
cc = F.lit(1).alias("A")

print(cc)
print(cc._jc.toString())

I get :

Column<b'1 AS `A`'>
1 AS `A`

Is there any way for me to just print "A" from cc ? it seems I'm unable to extract the alias easily.

Also I think that in spark-sql in scala, if I print "cc" it would just print "A" instead

lezebulon
  • 7,607
  • 11
  • 42
  • 73
  • This post will guide you in the right direction https://stackoverflow.com/questions/39746752/how-to-get-name-of-dataframe-column-in-pyspark. However,based on the docs and this answer it seems like there is no way to do this without parsing the "AS" etc. – Nadim Younes Mar 07 '19 at 00:59

1 Answers1

0

This goes deep into the Column Scala data model which is not mapped to Python:

cc._jc.named().name()

This is the name argument of the Alias instance.

Manu Valdés
  • 2,343
  • 1
  • 19
  • 28