Skip to content

Commit

Permalink
add default value to user-agent parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-kioo committed Aug 8, 2024
1 parent 0a4f81e commit e92dae6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ 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)
- **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
19 changes: 15 additions & 4 deletions src/main/java/org/embulk/output/DatabricksOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 @@ -54,8 +55,18 @@ public interface DatabricksPluginTask extends PluginTask {
public boolean getDeleteStageOnError();

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

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 @@ -98,8 +109,8 @@ protected JdbcOutputConnector getConnector(PluginTask task, boolean retryableMet
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");
String product_name = t.getUserAgent().get().getProductName();
String product_version = t.getUserAgent().get().getProductVersion();

props.put("UserAgentEntry", product_name + "/" + product_version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static DatabricksAPIClient create(DatabricksOutputPlugin.DatabricksPlugin
}

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

UserAgent.withProduct(name, version);
}
Expand Down

0 comments on commit e92dae6

Please sign in to comment.