Skip to content

Commit

Permalink
Add new configuration to select desired output type of boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
trung-huynh committed Jan 5, 2022
1 parent c3e147e commit 58c0c21
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- **additional_http_headers**: add additional headers to the requests (a key & value map, default: null)
- **port**: set port for Http requests. By default will connect to port 443 or 80 if `use_ssl: false` (int, optional)
- **ignore_alternative_time_if_time_exists**: ignore `time_column` and `time_value` in the configuration if a `time` column exists in the input schema. (boolean, default: false)
- **default_boolean_type_convert_to**: configure output type of boolean column. Available options are "long" (convert boolean to long) and "string" (convert boolean to string). (string, default: `"long"`)

## Modes
* **append**:
Expand Down
36 changes: 35 additions & 1 deletion src/main/java/org/embulk/output/td/TdOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ public interface PluginTask
Optional<Integer> getPort();
void setPort(Optional<Integer> port);

@Config("default_boolean_type_convert_to")
@ConfigDefault("\"long\"")
ConvertBooleanType getConvertBooleanType();

boolean getDoUpload();
void setDoUpload(boolean doUpload);

Expand Down Expand Up @@ -339,6 +343,36 @@ public String toString()
}
}

public static enum ConvertBooleanType
{
STRING(TDColumnType.STRING),
LONG(TDColumnType.LONG);

private final TDColumnType outputColumnType;

private ConvertBooleanType(TDColumnType outputColumnType)
{
this.outputColumnType = outputColumnType;
}

public TDColumnType getOutputColumnType()
{
return outputColumnType;
}

@JsonCreator
public static ConvertBooleanType of(String value)
{
final String loweredCaseValue = value.toLowerCase();
switch (loweredCaseValue) {
case "string": return STRING;
case "long": return LONG;
default:
throw new ConfigException(String.format("Unknown convert_boolean_type '%s'. Supported types are [string, long]", loweredCaseValue));
}
}
}

public static enum UnixTimestampUnit
{
SEC(1),
Expand Down Expand Up @@ -756,7 +790,7 @@ Map<String, TDColumnType> updateSchema(TDClient client, Schema inputSchema, Plug
inputSchema.visitColumns(new ColumnVisitor() {
public void booleanColumn(Column column)
{
guessedSchema.put(column.getName(), TDColumnType.LONG);
guessedSchema.put(column.getName(), task.getConvertBooleanType().getOutputColumnType());
}

public void longColumn(Column column)
Expand Down

0 comments on commit 58c0c21

Please sign in to comment.