<?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 Re: AttributeError in Spark 2.3 in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/AttributeError-in-Spark-2-3/m-p/185507#M80826</link>
    <description>&lt;P&gt;Thanks Felix for your quick response. It worked. Thanks a lot.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jul 2018 20:03:55 GMT</pubDate>
    <dc:creator>debananda_sahoo</dc:creator>
    <dc:date>2018-07-17T20:03:55Z</dc:date>
    <item>
      <title>AttributeError in Spark 2.3</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/AttributeError-in-Spark-2-3/m-p/185505#M80824</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The below code is not working in Spark 2.3 , but its working in 1.7.&lt;/P&gt;&lt;P&gt;Can someone modify the code as per Spark 2.3&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;import os &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from pyspark import SparkConf,SparkContext &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from pyspark.sql import HiveContext &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;conf = (SparkConf()
  .setAppName("data_import")
  .set("spark.dynamicAllocation.enabled","true")
  .set("spark.shuffle.service.enabled","true")) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sc = SparkContext(conf = conf) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sqlctx = HiveContext(sc) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;df = sqlctx.load(
  source="jdbc",
url="jdbc:sqlserver://10.24.40.29;database=CORE;username=user1;password=Passw0rd",
dbtable="test") &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;## this is how to write to an ORC file
df.write.format("orc").save("/tmp/orc_query_output") &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;## this is how to write to a hive table
df.write.mode('overwrite').format('orc').saveAsTable("test")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Error : AttributeError: 'HiveContext' object has no attribute 'load'&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 19:28:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/AttributeError-in-Spark-2-3/m-p/185505#M80824</guid>
      <dc:creator>debananda_sahoo</dc:creator>
      <dc:date>2018-07-17T19:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: AttributeError in Spark 2.3</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/AttributeError-in-Spark-2-3/m-p/185506#M80825</link>
      <description>&lt;P&gt; &lt;A rel="user" href="https://community.cloudera.com/users/75157/debanandasahoo.html" nodeid="75157"&gt;@Debananda Sahoo&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In spark 2 you should leverage spark session instead of spark context. To read jdbc datasource just use the following code:&lt;/P&gt;&lt;PRE&gt;from pyspark.sql import SparkSession
from pyspark.sql import Row

spark = SparkSession \
    .builder \
    .appName("data_import") \
    .config("spark.dynamicAllocation.enabled", "true") \
    .config("spark.shuffle.service.enabled", "true") \
    .enableHiveSupport() \
    .getOrCreate()

jdbcDF2 = spark.read \
    .jdbc("jdbc:sqlserver://10.24.40.29;database=CORE;username=user1;password=Passw0rd", "test")&lt;/PRE&gt;&lt;P&gt;More information and examples on this link:&lt;/P&gt;&lt;P&gt;&lt;A href="https://spark.apache.org/docs/2.1.0/sql-programming-guide.html#jdbc-to-other-databases" target="_blank"&gt;https://spark.apache.org/docs/2.1.0/sql-programming-guide.html#jdbc-to-other-databases&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Please let me know if that works for you.&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 19:51:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/AttributeError-in-Spark-2-3/m-p/185506#M80825</guid>
      <dc:creator>falbani</dc:creator>
      <dc:date>2018-07-17T19:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: AttributeError in Spark 2.3</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/AttributeError-in-Spark-2-3/m-p/185507#M80826</link>
      <description>&lt;P&gt;Thanks Felix for your quick response. It worked. Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:03:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/AttributeError-in-Spark-2-3/m-p/185507#M80826</guid>
      <dc:creator>debananda_sahoo</dc:creator>
      <dc:date>2018-07-17T20:03:55Z</dc:date>
    </item>
  </channel>
</rss>

