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 e34e353 commit 15c247c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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)
- **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
20 changes: 15 additions & 5 deletions src/main/java/org/embulk/input/DatabricksInputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import org.embulk.config.ConfigException;
Expand All @@ -12,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 @@ -42,8 +42,18 @@ public interface DatabricksPluginTask extends PluginTask {
public Optional<String> getSchemaName();

@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 @@ -82,8 +92,8 @@ protected JdbcInputConnection newConnection(PluginTask task) throws SQLException
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

0 comments on commit 15c247c

Please sign in to comment.