1

When I am working with Spark 1.6 below code is working fine:

ddl = sqlContext.sql("""show create table {mytable }""".format(mytable="""mytest.my_dummytable"""))
map(''.join, ddl\
.map(lambda my_row: [str(data).replace("`", "'") for data in my_row])\
.collect())

However, when I moved to spark 2.2 I got the following exception:

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)
<ipython-> in <module>()
      1 ddl = sqlContext.sql("""show create table {mytable }""".format(mytable ="""mytest.my_dummytable"""))
----> 2 map(''.join, ddl..map(lambda my_row: [str(data).replace("`", "'") for data in my_row]).collect())

spark2/python/pyspark/sql/dataframe.py in __getattr__(self, name)
            if name not in self.columns:
                raise AttributeError(
->                  "'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
            jc = self._jdf.apply(name)
            return Column(jc)

AttributeError: 'DataFrame' object has no attribute 'map'

1 Answers1

1

You have to call .rdd first. Spark 2.0 stopped aliasing df.map() to df.rdd.map(). See this.

Justin
  • 348
  • 3
  • 14