<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question py function in pyspark shell in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/py-function-in-pyspark-shell/m-p/342305#M233710</link>
    <description>&lt;P&gt;I have written python function and run in pyspark - cloudera shell but it throwing error while running it. But when I run the same function in my pyspark - local shell it's working perfectly fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Complete Code:&lt;/P&gt;&lt;P&gt;from pyspark.sql.functions import *&lt;BR /&gt;&lt;BR /&gt;df=spark.createDataFrame([&lt;BR /&gt;('America/New_York','2020-02-01 10:00:00')&lt;BR /&gt;,('Europe/Lisbon','2020-02-01 10:00:00')&lt;BR /&gt;,('Europe/Madrid','2020-02-01 10:00:00')&lt;BR /&gt;,('Europe/London', '2020-02-01 10:00:00')&lt;BR /&gt;,('America/Sao_Paulo', '2020-02-01 10:00:00')&lt;BR /&gt;]&lt;BR /&gt;,["OriginTz","Time"])&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;df2=spark.createDataFrame([&lt;BR /&gt;('Africa/Nairobi', '2020-02-01 10:00:00')&lt;BR /&gt;,('Asia/Damascus', '2020-02-01 10:00:00')&lt;BR /&gt;,('Asia/Singapore', '2020-02-01 10:00:00')&lt;BR /&gt;,('Atlantic/Bermuda','2020-02-01 10:00:00')&lt;BR /&gt;,('Canada/Mountain','2020-02-01 10:00:00')&lt;BR /&gt;,('Pacific/Tahiti','2020-02-01 10:00:00')&lt;BR /&gt;]&lt;BR /&gt;,["OriginTz", "Time"])&lt;/P&gt;&lt;P&gt;df.createOrReplaceTempView("test")&lt;BR /&gt;df2.createOrReplaceTempView("test2")&lt;/P&gt;&lt;P&gt;tables = ["test", "test2"]&lt;/P&gt;&lt;P&gt;frames = list(range(0,2))&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;def hive_read_func(tables, frames):&lt;BR /&gt;for table, frame in zip(tables, frames):&lt;BR /&gt;globals()["dtf"+str(frame)] = eval(f'spark.sql("select * from {table}")')&lt;/P&gt;&lt;P&gt;hive_read_func(tables, frames)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;------------------------------------------------------images--------------------------------------------------------------&lt;/P&gt;&lt;P&gt;when I run the function hive_read_func in cloudera getting below error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="function in cloudera" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34251iD44475C588BE66D9/image-size/large?v=v2&amp;amp;px=999" role="button" title="cloudera_error.PNG" alt="function in cloudera" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;function in cloudera&lt;/span&gt;&lt;/span&gt;&amp;nbsp;but when I run in my local system its running perfectly fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="same function in local system" style="width: 771px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34252i3B4E9F5B6672B081/image-size/large?v=v2&amp;amp;px=999" role="button" title="local_sys.PNG" alt="same function in local system" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;same function in local system&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can some one please look into this and help me to solve&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Apr 2026 07:57:13 GMT</pubDate>
    <dc:creator>Surya767</dc:creator>
    <dc:date>2026-04-21T07:57:13Z</dc:date>
    <item>
      <title>py function in pyspark shell</title>
      <link>https://community.cloudera.com/t5/Support-Questions/py-function-in-pyspark-shell/m-p/342305#M233710</link>
      <description>&lt;P&gt;I have written python function and run in pyspark - cloudera shell but it throwing error while running it. But when I run the same function in my pyspark - local shell it's working perfectly fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Complete Code:&lt;/P&gt;&lt;P&gt;from pyspark.sql.functions import *&lt;BR /&gt;&lt;BR /&gt;df=spark.createDataFrame([&lt;BR /&gt;('America/New_York','2020-02-01 10:00:00')&lt;BR /&gt;,('Europe/Lisbon','2020-02-01 10:00:00')&lt;BR /&gt;,('Europe/Madrid','2020-02-01 10:00:00')&lt;BR /&gt;,('Europe/London', '2020-02-01 10:00:00')&lt;BR /&gt;,('America/Sao_Paulo', '2020-02-01 10:00:00')&lt;BR /&gt;]&lt;BR /&gt;,["OriginTz","Time"])&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;df2=spark.createDataFrame([&lt;BR /&gt;('Africa/Nairobi', '2020-02-01 10:00:00')&lt;BR /&gt;,('Asia/Damascus', '2020-02-01 10:00:00')&lt;BR /&gt;,('Asia/Singapore', '2020-02-01 10:00:00')&lt;BR /&gt;,('Atlantic/Bermuda','2020-02-01 10:00:00')&lt;BR /&gt;,('Canada/Mountain','2020-02-01 10:00:00')&lt;BR /&gt;,('Pacific/Tahiti','2020-02-01 10:00:00')&lt;BR /&gt;]&lt;BR /&gt;,["OriginTz", "Time"])&lt;/P&gt;&lt;P&gt;df.createOrReplaceTempView("test")&lt;BR /&gt;df2.createOrReplaceTempView("test2")&lt;/P&gt;&lt;P&gt;tables = ["test", "test2"]&lt;/P&gt;&lt;P&gt;frames = list(range(0,2))&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;def hive_read_func(tables, frames):&lt;BR /&gt;for table, frame in zip(tables, frames):&lt;BR /&gt;globals()["dtf"+str(frame)] = eval(f'spark.sql("select * from {table}")')&lt;/P&gt;&lt;P&gt;hive_read_func(tables, frames)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;------------------------------------------------------images--------------------------------------------------------------&lt;/P&gt;&lt;P&gt;when I run the function hive_read_func in cloudera getting below error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="function in cloudera" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34251iD44475C588BE66D9/image-size/large?v=v2&amp;amp;px=999" role="button" title="cloudera_error.PNG" alt="function in cloudera" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;function in cloudera&lt;/span&gt;&lt;/span&gt;&amp;nbsp;but when I run in my local system its running perfectly fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="same function in local system" style="width: 771px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34252i3B4E9F5B6672B081/image-size/large?v=v2&amp;amp;px=999" role="button" title="local_sys.PNG" alt="same function in local system" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;same function in local system&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can some one please look into this and help me to solve&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2026 07:57:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/py-function-in-pyspark-shell/m-p/342305#M233710</guid>
      <dc:creator>Surya767</dc:creator>
      <dc:date>2026-04-21T07:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: py function in pyspark shell</title>
      <link>https://community.cloudera.com/t5/Support-Questions/py-function-in-pyspark-shell/m-p/342335#M233714</link>
      <description>&lt;P&gt;I got the answer myself: this is because of version f-string is available after python 3.1 but I run it in python version 2.6. so got error, now I rewrite the function with out f-string:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;def hive_read_func(tables, frames):&lt;BR /&gt;for table, frame in zip(tables, frames):&lt;BR /&gt;inner_code = "select * from"+" "+ str(table)&lt;BR /&gt;globals()["dttf"+str(frame)] = spark.sql(inner_code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 09:42:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/py-function-in-pyspark-shell/m-p/342335#M233714</guid>
      <dc:creator>Surya767</dc:creator>
      <dc:date>2022-04-26T09:42:17Z</dc:date>
    </item>
  </channel>
</rss>

