Skip to content

Commit

Permalink
Merge pull request #5 from trocco-io/add-user-agent-parameter-to-config
Browse files Browse the repository at this point in the history
Add user-agent parameter to config
  • Loading branch information
yu-kioo authored Aug 16, 2024
2 parents 6d4cfd1 + a7cff7b commit 91d572e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Databricks input plugin for Embulk loads records from Databricks.

- **driver_path**: path to the jar file of the JDBC driver. If not set, [the bundled JDBC driver](https://docs.databricks.com/en/integrations/jdbc/index.html) will be used. (string, optional)
- **options**: extra JDBC properties (hash, default: {})
- **user_agent**: set user agent property to JDBC connection. If 'UserAgentEntry' property is specified in the **options**, it will be overwritten by this value. (hash, optional)
- **product_name**: product name of user agent (string, default: "unknown")
- **product_version**: product version of user agent (string, default: "0.0.0")
- **server_hostname**: The Databricks compute resource’s Server Hostname value, see [Compute settings for the Databricks JDBC Driver](https://docs.databricks.com/en/integrations/jdbc/compute.html). (string, required)
- **http_path**: The Databricks compute resource’s HTTP Path value, see [Compute settings for the Databricks JDBC Driver](https://docs.databricks.com/en/integrations/jdbc/compute.html). (string, required)
- **personal_access_token**: The Databaricks personal_access_token, see [Authentication settings for the Databricks JDBC Driver](https://docs.databricks.com/en/integrations/jdbc/authentication.html#authentication-pat). (string, required)
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/embulk/input/DatabricksInputPlugin.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.embulk.spi.Schema;
import org.embulk.util.config.Config;
import org.embulk.util.config.ConfigDefault;
import org.embulk.util.config.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -39,6 +40,20 @@ public interface DatabricksPluginTask extends PluginTask {
@Config("schema_name")
@ConfigDefault("null")
public Optional<String> getSchemaName();

@Config("user_agent")
@ConfigDefault("{}")
public UserAgentEntry getUserAgentEntry();

public interface UserAgentEntry extends Task {
@Config("product_name")
@ConfigDefault("\"unknown\"")
public String getProductName();

@Config("product_version")
@ConfigDefault("\"0.0.0\"")
public String getProductVersion();
}
}

@Override
Expand Down Expand Up @@ -76,6 +91,11 @@ protected JdbcInputConnection newConnection(PluginTask task) throws SQLException
}
props.putAll(t.getOptions());

// overwrite UserAgentEntry property if the same property is set in options
String productName = t.getUserAgentEntry().getProductName();
String productVersion = t.getUserAgentEntry().getProductVersion();
props.put("UserAgentEntry", productName + "/" + productVersion);

logConnectionProperties(url, props);
Connection c = DriverManager.getConnection(url, props);
return new DatabricksInputConnection(
Expand Down

0 comments on commit 91d572e

Please sign in to comment.