<?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>topic Authentication issue in HiveMetastore in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/authentication-issue-in-hivemetastore/m-p/119292#M45830</link>
    <description>&lt;P&gt;Problem Statement:&lt;BR /&gt;When I execute the below code as a part of the notebook both manually and in workflow it works as expected&lt;BR /&gt;df.write.mode("overwrite") \&lt;BR /&gt;.format('delta') \&lt;BR /&gt;.option('path',ext_path) \&lt;BR /&gt;.saveAsTable("tbl_schema.Table_name")&lt;/P&gt;&lt;P&gt;but when I integrate the same code within the function and execute it still writs to the target but does not get recognised by HiveMetastore.&lt;/P&gt;</description>
    <pubDate>Thu, 15 May 2025 09:24:49 GMT</pubDate>
    <dc:creator>Prajit0710</dc:creator>
    <dc:date>2025-05-15T09:24:49Z</dc:date>
    <item>
      <title>Authentication issue in HiveMetastore</title>
      <link>https://community.databricks.com/t5/data-engineering/authentication-issue-in-hivemetastore/m-p/119292#M45830</link>
      <description>&lt;P&gt;Problem Statement:&lt;BR /&gt;When I execute the below code as a part of the notebook both manually and in workflow it works as expected&lt;BR /&gt;df.write.mode("overwrite") \&lt;BR /&gt;.format('delta') \&lt;BR /&gt;.option('path',ext_path) \&lt;BR /&gt;.saveAsTable("tbl_schema.Table_name")&lt;/P&gt;&lt;P&gt;but when I integrate the same code within the function and execute it still writs to the target but does not get recognised by HiveMetastore.&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 09:24:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/authentication-issue-in-hivemetastore/m-p/119292#M45830</guid>
      <dc:creator>Prajit0710</dc:creator>
      <dc:date>2025-05-15T09:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication issue in HiveMetastore</title>
      <link>https://community.databricks.com/t5/data-engineering/authentication-issue-in-hivemetastore/m-p/119338#M45843</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/164569"&gt;@Prajit0710&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an interesting issue where your Delta table write operation works as expected when run directly,&lt;BR /&gt;but when executed within a function, the table doesn't get recognized by the HiveMetastore.&lt;/P&gt;&lt;P&gt;The key difference is likely related to how Spark interacts with the HiveMetastore when registering tables&lt;BR /&gt;from within functions versus at the notebook level.&lt;BR /&gt;Here are a few potential causes and solutions:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Spark Session Context:&lt;/STRONG&gt; Functions might be executing in a different Spark context/session than your main notebook code.&lt;BR /&gt;&lt;STRONG&gt;2. Catalog Registration:&lt;/STRONG&gt; The table metadata might not be properly registering with the Hive metastore within the function context.&lt;BR /&gt;&lt;STRONG&gt;3. Transaction Boundaries:&lt;/STRONG&gt; Function execution might affect how transactions are handled.&lt;/P&gt;&lt;P&gt;Try these solutions:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Pass the SparkSession explicitly to your function:&lt;/STRONG&gt;&lt;BR /&gt;def write_delta_table(spark, dataframe, ext_path, table_name):&lt;BR /&gt;dataframe.write.mode("overwrite") \&lt;BR /&gt;.format('delta') \&lt;BR /&gt;.option('path', ext_path) \&lt;BR /&gt;.saveAsTable(table_name)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Use catalog commands explicitly:&lt;/STRONG&gt;&lt;BR /&gt;def write_delta_table(dataframe, ext_path, table_name):&lt;BR /&gt;# Write data first&lt;BR /&gt;dataframe.write.mode("overwrite") \&lt;BR /&gt;.format('delta') \&lt;BR /&gt;.option('path', ext_path) \&lt;BR /&gt;.save()&lt;BR /&gt;&lt;BR /&gt;# Then explicitly register with metastore&lt;BR /&gt;spark.sql(f"CREATE TABLE IF NOT EXISTS {table_name} USING DELTA LOCATION '{ext_path}'")&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3. Check for schema conflicts:&lt;/STRONG&gt;&lt;BR /&gt;Make sure your function isn't creating schema conflicts with existing tables. Try adding before your table creation.&lt;BR /&gt;:&lt;BR /&gt;spark.sql(f"DROP TABLE IF EXISTS {table_name}")&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;4. Ensure proper database context:&lt;/STRONG&gt;&lt;BR /&gt;Explicitly set the database context within your function:&lt;BR /&gt;spark.sql("USE schema_name")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 14:17:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/authentication-issue-in-hivemetastore/m-p/119338#M45843</guid>
      <dc:creator>lingareddy_Alva</dc:creator>
      <dc:date>2025-05-15T14:17:39Z</dc:date>
    </item>
  </channel>
</rss>

