<?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: Is there a Databricks spark connector for java? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119296#M46398</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/154481"&gt;@Shua42&lt;/a&gt;.&lt;BR /&gt;&lt;BR /&gt;I am using the&amp;nbsp;&lt;SPAN&gt;JDBC URL of a running SQL warehouse to write data directly to a Databricks table from my local machine. But its write performance is inferior. I tried adding `batchSize` and `numPartitions`, but the performance still did not improve at all. Below is the snippet I am using.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;spark = SparkSession.builder()
    .appName("JsonToDatabricksLocalJDBC")
    .master("local[*]")
    .config("spark.driver.memory", driverMemory)
    .config("spark.sql.warehouse.dir", "spark-warehouse-" + System.currentTimeMillis())
    .getOrCreate();

Dataset&amp;lt;Row&amp;gt; rawDf = spark.read().schema(expectedSchema).json(inputJsonPath);

Dataset&amp;lt;Row&amp;gt; transformedDf = rawDf.select(
        coalesce(col("app_name"), lit("UnknownApp")).alias("APP_NAME"),
        coalesce(col("event.event_name"), lit("UnknownEvent")).alias("EVENT_NAME"),
        coalesce(col("event.event_code"), lit("")).alias("EVENT_CODE"),
        to_json(col("event.event_attributes")).alias("EVENT_ATTRIBUTES"),
        to_json(col("event.user_attributes")).alias("USER_ATTRIBUTES"),
        to_json(col("event.device_attributes")).alias("DEVICE_ATTRIBUTES")
    );

Properties dfWriteJdbcProperties = new Properties();
    dfWriteJdbcProperties.put("user", "token");
    dfWriteJdbcProperties.put("password", dbToken);

transformedDf.write()
    .mode(SaveMode.Append)
    .option("batchsize", String.valueOf(jdbcBatchSize))
    .option("numPartitions", String.valueOf(jdbcNumPartitionsForWrite))
    .jdbc(jdbcUrl, fullTableNameInDb, dfWriteJdbcProperties);&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Please suggest how can I increase its performance, since I have to insert a large volume of data into the Databricks table. Also I have attached the screenshot of the SQL Warehouse&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 15 May 2025 10:03:15 GMT</pubDate>
    <dc:creator>I-am-Biplab</dc:creator>
    <dc:date>2025-05-15T10:03:15Z</dc:date>
    <item>
      <title>Is there a Databricks spark connector for java?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119121#M46396</link>
      <description>&lt;P&gt;Is there a Databricks Spark connector for Java, just like we have for Snowflake (reference of Snowflake spark connector - &lt;A href="https://docs.snowflake.com/en/user-guide/spark-connector-use)" target="_blank"&gt;https://docs.snowflake.com/en/user-guide/spark-connector-use)&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Essentially, the use case is to transfer data from S3 to a Databricks table. In the current implementation, I am using Spark to read data from S3 and JDBC to write data to Databricks. But I want to use Spark instead to write data to Databricks.&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 06:25:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119121#M46396</guid>
      <dc:creator>I-am-Biplab</dc:creator>
      <dc:date>2025-05-14T06:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Databricks spark connector for java?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119236#M46397</link>
      <description>&lt;P&gt;Hey there&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/164381"&gt;@I-am-Biplab&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I'm a bit confused on the ask here. I'm assuming your code isn't running on a databricks cluster, in which case you can use the JDBC url of a running SQL warehouse to write data directly to a Databricks table. See the example code below:&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;        Properties connectionProperties = new Properties();
        connectionProperties.setProperty("user", "token");
        connectionProperties.setProperty("password", "&amp;lt;DATABRICKS_PERSONAL_ACCESS_TOKEN&amp;gt;");

        String jdbcUrl = "jdbc:databricks://&amp;lt;workspace-hostname&amp;gt;:443/default;transportMode=http;ssl=1;httpPath=&amp;lt;sql-warehouse-http-path&amp;gt;";

        // Write to Databricks table
        df.write()
                .mode("append") // or "overwrite"
                .jdbc(jdbcUrl, "your_table_name", connectionProperties);&lt;/LI-CODE&gt;
&lt;P&gt;If you are running on a Databricks cluster, you should be able to write directly to a table with:&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;Dataset&amp;lt;Row&amp;gt; df = spark.read()
    .format("parquet") // or "csv", "json", etc., depending on your data format
    .load("s3a://your-bucket/path/to/data");

df.write()
    .format("delta")
    .mode("append") // or "overwrite" as per your requirement
    .saveAsTable("your_catalog.your_schema.your_table");&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Let me know if I'm understanding your ask correctly.&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 16:14:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119236#M46397</guid>
      <dc:creator>Shua42</dc:creator>
      <dc:date>2025-05-14T16:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Databricks spark connector for java?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119296#M46398</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/154481"&gt;@Shua42&lt;/a&gt;.&lt;BR /&gt;&lt;BR /&gt;I am using the&amp;nbsp;&lt;SPAN&gt;JDBC URL of a running SQL warehouse to write data directly to a Databricks table from my local machine. But its write performance is inferior. I tried adding `batchSize` and `numPartitions`, but the performance still did not improve at all. Below is the snippet I am using.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;spark = SparkSession.builder()
    .appName("JsonToDatabricksLocalJDBC")
    .master("local[*]")
    .config("spark.driver.memory", driverMemory)
    .config("spark.sql.warehouse.dir", "spark-warehouse-" + System.currentTimeMillis())
    .getOrCreate();

Dataset&amp;lt;Row&amp;gt; rawDf = spark.read().schema(expectedSchema).json(inputJsonPath);

Dataset&amp;lt;Row&amp;gt; transformedDf = rawDf.select(
        coalesce(col("app_name"), lit("UnknownApp")).alias("APP_NAME"),
        coalesce(col("event.event_name"), lit("UnknownEvent")).alias("EVENT_NAME"),
        coalesce(col("event.event_code"), lit("")).alias("EVENT_CODE"),
        to_json(col("event.event_attributes")).alias("EVENT_ATTRIBUTES"),
        to_json(col("event.user_attributes")).alias("USER_ATTRIBUTES"),
        to_json(col("event.device_attributes")).alias("DEVICE_ATTRIBUTES")
    );

Properties dfWriteJdbcProperties = new Properties();
    dfWriteJdbcProperties.put("user", "token");
    dfWriteJdbcProperties.put("password", dbToken);

transformedDf.write()
    .mode(SaveMode.Append)
    .option("batchsize", String.valueOf(jdbcBatchSize))
    .option("numPartitions", String.valueOf(jdbcNumPartitionsForWrite))
    .jdbc(jdbcUrl, fullTableNameInDb, dfWriteJdbcProperties);&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Please suggest how can I increase its performance, since I have to insert a large volume of data into the Databricks table. Also I have attached the screenshot of the SQL Warehouse&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 10:03:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119296#M46398</guid>
      <dc:creator>I-am-Biplab</dc:creator>
      <dc:date>2025-05-15T10:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Databricks spark connector for java?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119369#M46399</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/164381"&gt;@I-am-Biplab&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;If running locally, it is going to be difficult to tune the performance up that much, but there are a few things you can try:&lt;/P&gt;
&lt;P&gt;1. Up the partitions and batch size, as much as your machine will allow. Also, running repartition() could help ensure the data is actually partitioned.&lt;/P&gt;
&lt;P&gt;2. You can up the SQL Warehouse size in case the throughput on that is the bottleneck. You could up it, write the data and then vertically scale it back down.&lt;/P&gt;
&lt;P&gt;3. If you're writing from files, you could copy the files from your local machine to a Volume using the CLI, and then process the data from there which will allow more parallelized writes with Spark.&lt;/P&gt;
&lt;P&gt;The bottleneck could be your machine configs, so I would also evaluate your architecture and see if there's any opportunities to stage the data in it's original format in Databricks or cloud storage first, since JDBC isn't best suited for large scale writes.&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 16:40:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-databricks-spark-connector-for-java/m-p/119369#M46399</guid>
      <dc:creator>Shua42</dc:creator>
      <dc:date>2025-05-15T16:40:18Z</dc:date>
    </item>
  </channel>
</rss>

