Skip to content

Commit

Permalink
add user-agent parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-kioo committed Aug 7, 2024
1 parent 61cecf3 commit c725715
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Databricks output plugin for Embulk loads records to Databricks Delta Table.

- **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 and SDK 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)
- **product_version**: product version of user agent (string)
- **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
12 changes: 12 additions & 0 deletions src/main/java/org/embulk/output/DatabricksOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public interface DatabricksPluginTask extends PluginTask {
@Config("delete_stage_on_error")
@ConfigDefault("false")
public boolean getDeleteStageOnError();

@Config("user_agent")
@ConfigDefault("null")
public Optional<Map<String, String>> getUserAgent();
}

@Override
Expand Down Expand Up @@ -92,6 +96,14 @@ protected JdbcOutputConnector getConnector(PluginTask task, boolean retryableMet
props.put("ConnCatalog", t.getCatalogName());
props.put("ConnSchema", t.getSchemaName());
props.putAll(t.getOptions());
// overwrite UserAgentEntry property if the same property is set in options
if (t.getUserAgent().isPresent()) {
String product_name = t.getUserAgent().get().get("product_name");
String product_version = t.getUserAgent().get().get("product_version");

props.put("UserAgentEntry", product_name + "/" + product_version);
}

logConnectionProperties(url, props);
return new DatabricksOutputConnector(
url, props, t.getTransactionIsolation(), t.getCatalogName(), t.getSchemaName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.databricks.sdk.WorkspaceClient;
import com.databricks.sdk.core.DatabricksConfig;
import com.databricks.sdk.core.UserAgent;
import com.databricks.sdk.service.catalog.VolumeType;
import java.io.InputStream;
import java.text.SimpleDateFormat;
Expand All @@ -11,9 +12,18 @@

public class DatabricksAPIClient {
public static DatabricksAPIClient create(DatabricksOutputPlugin.DatabricksPluginTask task) {
SetUserAgent(task);

return new DatabricksAPIClient(createDatabricksConfig(task));
}

private static void SetUserAgent(DatabricksOutputPlugin.DatabricksPluginTask task) {
String name = task.getUserAgent().get().get("product_name");
String version = task.getUserAgent().get().get("product_version");

UserAgent.withProduct(name, version);
}

private final WorkspaceClient workspaceClient;

public DatabricksAPIClient(DatabricksConfig config) {
Expand Down

0 comments on commit c725715

Please sign in to comment.