Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added int64 customer formatter #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand All @@ -31,6 +33,8 @@

public class FieldPartitioner<T> extends DefaultPartitioner<T> {
private static final Logger log = LoggerFactory.getLogger(FieldPartitioner.class);
private static final SimpleDateFormat SIMPLE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

private List<String> fieldNames;


Expand Down Expand Up @@ -60,10 +64,12 @@ public String encodePartition(SinkRecord sinkRecord) {
case INT8:
case INT16:
case INT32:
case INT64:
Number record = (Number) partitionKey;
builder.append(fieldName + "=" + record.toString());
break;
case INT64:
builder.append(fieldName + "=" + formatInt64(partitionKey));
break;
case STRING:
builder.append(fieldName + "=" + (String) partitionKey);
break;
Expand Down Expand Up @@ -92,4 +98,13 @@ public List<T> partitionFields() {
}
return partitionFields;
}

private String formatInt64(Object partitionKey) {
if (partitionKey instanceof Date) {
Date record = (Date) partitionKey;
return SIMPLE_FORMAT.format(record);
}
Number record = (Number) partitionKey;
return record.toString();
}
}