Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ public InputFormatProvider getInputFormatProvider(ConnectorContext context, Samp
String tableQuery = getTableQuery(path.getDatabase(), path.getSchema(), path.getTable(), request.getLimit(),
request.getProperties().get("sampleType"), request.getProperties().get("strata"), sessionID);
DataDrivenETLDBInputFormat.setInput(connectionConfigAccessor.getConfiguration(), getDBRecordType(),
tableQuery, null, false);
tableQuery, null, isAutoCommitEnabled());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getInputFormatProvider() runs for every DB connector in this repo — MySQL, Postgres, Oracle, SQL Server, Redshift — not just Databricks.

The defaulting looks correct to me (isAutoCommitEnabled() → false reproduces the old hard-coded false, and a null isolation level leaves TransactionIsolationLevel.CONF_KEY unset so getLevel(null) still yields SERIALIZABLE). But nothing asserts that, so a future change to either default would silently alter connection behaviour for every other plugin with no test failing.

Could you add coverage in database-commons for:

  • the base hooks returning false / null;
  • a non-overriding connector leaving AUTO_COMMIT_ENABLED and TransactionIsolationLevel.CONF_KEY exactly as before this change;
    an overriding connector setting both.
    database-commons/src/test/java/io/cdap/plugin/db/source/DataDrivenETLDBInputFormatTest.java is a reasonable place

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit tests in DataDrivenETLDBInputFormatTest to verify the default values of isAutoCommitEnabled() (false) and getTransactionIsolationLevel() (null), as well as getInputFormatProvider() configuration for both default (non-overriding) and overriding connectors.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit tests in DataDrivenETLDBInputFormatTest to verify the default values of isAutoCommitEnabled() (false) and getTransactionIsolationLevel() (null), as well as getInputFormatProvider() configuration for both default (non-overriding) and overriding connectors.

connectionConfigAccessor.setConnectionArguments(Maps.fromProperties(config.getConnectionArgumentsProperties()));
String isolationLevel = getTransactionIsolationLevel();
if (isolationLevel != null) {
connectionConfigAccessor.setTransactionIsolationLevel(isolationLevel);
}
connectionConfigAccessor.getConfiguration().setInt(MRJobConfig.NUM_MAPS, 1);
Map<String, String> additionalArguments = config.getAdditionalArguments();
for (Map.Entry<String, String> argument : additionalArguments.entrySet()) {
Expand Down Expand Up @@ -221,4 +225,19 @@ protected Schema getTableSchema(Connection connection, String database,
protected String generateSessionID() {
return UUID.randomUUID().toString().replace('-', '_');
}

/**
* Returns whether auto-commit should be enabled for this connector.
* By default, it is false.
*/
protected boolean isAutoCommitEnabled() {
return false;
}
/**
* Returns the default transaction isolation level for this connector.
* If null, it falls back to the database driver's default or serializable.
*/
protected String getTransactionIsolationLevel() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@
package io.cdap.plugin.db.source;

import com.google.common.collect.ImmutableList;
import io.cdap.cdap.api.data.batch.InputFormatProvider;
import io.cdap.cdap.api.data.format.StructuredRecord;
import io.cdap.cdap.api.data.schema.Schema;
import io.cdap.cdap.etl.api.connector.ConnectorContext;
import io.cdap.cdap.etl.api.connector.SampleRequest;
import io.cdap.cdap.etl.mock.common.MockConnectorConfigurer;
import io.cdap.cdap.etl.mock.common.MockConnectorContext;
import io.cdap.plugin.common.db.DBConnectorPath;
import io.cdap.plugin.db.ConnectionConfigAccessor;
import io.cdap.plugin.db.DBRecord;
import io.cdap.plugin.db.TransactionIsolationLevel;
import io.cdap.plugin.db.connector.AbstractDBConnectorConfig;
import io.cdap.plugin.db.connector.AbstractDBSpecificConnector;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.lib.db.DBConfiguration;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;
import org.apache.hadoop.mapreduce.lib.db.DataDrivenDBInputFormat;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -30,8 +45,11 @@
import org.mockito.runners.MockitoJUnitRunner;

import java.io.IOException;
import java.sql.Connection;
import java.sql.Driver;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@RunWith(MockitoJUnitRunner.class)
public class DataDrivenETLDBInputFormatTest {
Expand Down Expand Up @@ -118,4 +136,92 @@ public void testGetSplitsDoesNotAddNullSplitIfBaseReturnsEmptyList() throws IOEx
(DataDrivenDBInputFormat.DataDrivenDBInputSplit) finalSplits.get(0);
Assert.assertEquals("1=1", split.getLowerClause());
}

@Test
public void testDefaultConnectorInputFormatConfiguration() throws IOException {
TestDBConnector connector = new TestDBConnector(new TestDBConnectorConfig());

Assert.assertFalse(connector.getBaseAutoCommitEnabled());
Assert.assertNull(connector.getBaseTransactionIsolationLevel());

ConnectorContext context = new MockConnectorContext(new MockConnectorConfigurer());
SampleRequest sampleRequest = SampleRequest.builder(10).setPath("db/table").build();
InputFormatProvider provider = connector.getInputFormatProvider(context, sampleRequest);
Map<String, String> conf = provider.getInputFormatConfiguration();

Assert.assertEquals("false", conf.get(ConnectionConfigAccessor.AUTO_COMMIT_ENABLED));
Assert.assertNull(conf.get(TransactionIsolationLevel.CONF_KEY));
}

@Test
public void testOverridingConnectorInputFormatConfiguration() throws IOException {
TestDBConnector connector = new TestDBConnector(new TestDBConnectorConfig()) {
@Override
protected boolean isAutoCommitEnabled() {
return true;
}

@Override
protected String getTransactionIsolationLevel() {
return TransactionIsolationLevel.Level.TRANSACTION_READ_UNCOMMITTED.name();
}
};

ConnectorContext context = new MockConnectorContext(new MockConnectorConfigurer());
SampleRequest sampleRequest = SampleRequest.builder(10).setPath("db/table").build();
InputFormatProvider provider = connector.getInputFormatProvider(context, sampleRequest);
Map<String, String> conf = provider.getInputFormatConfiguration();

Assert.assertEquals("true", conf.get(ConnectionConfigAccessor.AUTO_COMMIT_ENABLED));
Assert.assertEquals(TransactionIsolationLevel.Level.TRANSACTION_READ_UNCOMMITTED.name(),
conf.get(TransactionIsolationLevel.CONF_KEY));
}

private static class TestDBConnectorConfig extends AbstractDBConnectorConfig {
@Override
public String getConnectionString() {
return "jdbc:test://localhost:1234/db";
}
}

private static class TestDBConnector extends AbstractDBSpecificConnector<DBRecord> {
TestDBConnector(AbstractDBConnectorConfig config) {
super(config);
this.driverClass = Driver.class;
}

@Override
public boolean supportSchema() {
return false;
}

@Override
protected Class<? extends DBWritable> getDBRecordType() {
return DBRecord.class;
}

@Override
public StructuredRecord transform(LongWritable key, DBRecord val) {
return null;
}

@Override
protected Connection getConnection(DBConnectorPath path) {
return null;
}

@Override
protected Schema loadTableSchema(Connection connection, String query,
Integer timeoutSec, String sessionID) {
return Schema.recordOf("outputSchema", Schema.Field.of("id", Schema.of(Schema.Type.INT)));
}

boolean getBaseAutoCommitEnabled() {
return isAutoCommitEnabled();
}

String getBaseTransactionIsolationLevel() {
return getTransactionIsolationLevel();
}
}
}
15 changes: 15 additions & 0 deletions databricks-plugin/docs/Databricks-batchsource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Databricks Batch Source

Description
-----------
Reads data from a Databricks table using a configurable SQL query.

Properties
----------
* **Use Connection**: Whether to use an existing Databricks connection.
* **Host**: Server Hostname of the Databricks cluster or SQL warehouse.
* **Port**: Database port (default is 443).
* **HTTP Path**: The HTTP Path for the Databricks cluster or SQL warehouse.
* **Reference Name**: Name used to identify this source for lineage.
* **Database / Catalog**: Optional catalog or database name.
* **Import Query**: SQL query to execute against Databricks.
15 changes: 15 additions & 0 deletions databricks-plugin/docs/Databricks-connector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Databricks Database Connector

Description
-----------
Connects to Databricks database / Lakehouse via JDBC.

Properties
----------
* **Host**: Server Hostname of the Databricks cluster or SQL warehouse.
* **Port**: Database port (default is 443).
* **HTTP Path**: The HTTP Path for the Databricks cluster or SQL warehouse.
* **Database / Catalog**: Optional catalog or database name to connect to.
* **Username**: Username / token user.
* **Password / Token**: Personal Access Token (PAT) or password.
* **Connection Arguments**: Arbitrary key-value pairs to pass as connection arguments to the JDBC driver (e.g. `AuthMech=11;Auth_Flow=2`).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions databricks-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2026 CDAP

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.13.0-SNAPSHOT</version>
</parent>

<name>Databricks plugin</name>
<artifactId>databricks-plugin</artifactId>
<modelVersion>4.0.0</modelVersion>

<properties>
<databricks-jdbc.version>3.4.3</databricks-jdbc.version>
</properties>

<dependencies>
<dependency>
<groupId>io.cdap.cdap</groupId>
<artifactId>cdap-etl-api</artifactId>
</dependency>
<dependency>
<groupId>io.cdap.plugin</groupId>
<artifactId>database-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cdap.plugin</groupId>
<artifactId>hydrator-common</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency isn't referenced by any test in the PR — nothing loads the driver, so it's currently dead weight in the build.

That's really a symptom of the wider gap: there's no DatabricksPluginTestBase, DatabricksPluginTestSuite, DatabricksSourceTestRun, DatabricksFailedConnectionTest or DatabricksDBRecordUnitTest here. Every other plugin in the repo ships that set — see amazon-redshift-plugin/src/test/.../RedshiftPluginTestBase.java (218 lines) as the closest template. The two unit tests in this PR don't touch DatabricksSource, DatabricksDBRecord, or any connection path.

For a brand-new plugin I'd like at least a DatabricksPluginTestBase following the Redshift pattern, which would also give this dependency a purpose. Separately, could you attach evidence of a real end-to-end run (browse → get schema → sample → pipeline read) against a SQL warehouse, over a table containing TIMESTAMP, TIMESTAMP_NTZ, DATE, DECIMAL(38,10), ARRAY, MAP, STRUCT, VARIANT and a NULL-only column? That's the set most likely to break and none of it is covered today.

<groupId>com.databricks</groupId>
<artifactId>databricks-jdbc</artifactId>
<version>${databricks-jdbc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cdap.plugin</groupId>
<artifactId>database-commons</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cdap.cdap</groupId>
<artifactId>hydrator-test</artifactId>
</dependency>
<dependency>
<groupId>io.cdap.cdap</groupId>
<artifactId>cdap-data-pipeline3_2.12</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cdap.cdap</groupId>
<artifactId>cdap-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.cdap</groupId>
<artifactId>cdap-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<extensions>true</extensions>
<configuration>
<instructions>
<_exportcontents>
io.cdap.plugin.databricks.*;
io.cdap.plugin.db.source.*;
org.apache.commons.lang;
org.apache.commons.logging.*;
org.codehaus.jackson.*
</_exportcontents>
<Embed-Dependency>*;inline=false;scope=compile</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>lib</Embed-Directory>
</instructions>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading