<?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 Re: How do I specify column types when writing to a MSSQL server using the JDBC driver ( in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-do-i-specify-column-types-when-writing-to-a-mssql-server/m-p/50666#M28858</link>
    <description>&lt;P&gt;It's happenging to me too!&lt;/P&gt;&lt;P&gt;Did you find any solution&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/78292"&gt;@jonathan-dufaul&lt;/a&gt;&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2023 15:50:13 GMT</pubDate>
    <dc:creator>dasanro</dc:creator>
    <dc:date>2023-11-08T15:50:13Z</dc:date>
    <item>
      <title>How do I specify column types when writing to a MSSQL server using the JDBC driver (</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-specify-column-types-when-writing-to-a-mssql-server/m-p/16842#M10944</link>
      <description>&lt;P&gt;I have a pyspark dataframe that I'm writing to an on-prem MSSQL server--it's a stopgap while we convert data warehousing jobs over to databricks. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The processes that use those tables in the on-prem server rely on the tables maintaining the identical structure. I have a structure, for instance, like below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SOURCE	VARCHAR(3)
LOCATION_NO	VARCHAR(3)
SKU_NO	LONG
CASE_SKU_NO	LONG
ITEM_TYPE	VARCHAR(3)
SYSTEM	VARCHAR(MAX)
PRICE	DOUBLE&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;when I've just done vanilla &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  (my_dataframe.write.format("jdbc") 
    .option("url",sqlsUrl) 
    .option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") 
    .option("dbtable", table_name )
    .option("user", username) 
    .option("password", password) 
    .save(mode=mode)
  )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get a different structure, biggest difference being varchar becomes nvarchar(max). Since the jobs on the server join to other tables that have varchar type, it means that jobs take hours that used to take minutes. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ideally I'd like to specify the schema type and then save the table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Follow up question. Am I using the most recent/correct JDBC driver?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope that makes sense. &lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 17:50:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-specify-column-types-when-writing-to-a-mssql-server/m-p/16842#M10944</guid>
      <dc:creator>jonathan-dufaul</dc:creator>
      <dc:date>2022-12-14T17:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I specify column types when writing to a MSSQL server using the JDBC driver (</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-specify-column-types-when-writing-to-a-mssql-server/m-p/50666#M28858</link>
      <description>&lt;P&gt;It's happenging to me too!&lt;/P&gt;&lt;P&gt;Did you find any solution&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/78292"&gt;@jonathan-dufaul&lt;/a&gt;&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 15:50:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-specify-column-types-when-writing-to-a-mssql-server/m-p/50666#M28858</guid>
      <dc:creator>dasanro</dc:creator>
      <dc:date>2023-11-08T15:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I specify column types when writing to a MSSQL server using the JDBC driver (</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-specify-column-types-when-writing-to-a-mssql-server/m-p/101107#M40544</link>
      <description>&lt;P&gt;I think I ended up doing a truncate and mode = "append" so the structure stayed the same.&lt;/P&gt;&lt;P&gt;For truncate I had to get some direct access from the sparkcontext/sc variable&lt;/P&gt;&lt;PRE&gt;driver_manager = spark._sc._gateway.jvm.java.sql.DriverManager
connection = driver_manager.getConnection(mssql_url, mssql_user, mssql_pass)
connection.prepareCall(&lt;SPAN class=""&gt;"TRUNCATE TABLE my_table"&lt;/SPAN&gt;).execute()
connection.close()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 16:58:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-specify-column-types-when-writing-to-a-mssql-server/m-p/101107#M40544</guid>
      <dc:creator>jonathan-dufaul</dc:creator>
      <dc:date>2024-12-05T16:58:20Z</dc:date>
    </item>
  </channel>
</rss>

