}
return builder.build();
}
private static JsonNode toJson(PartitionStrategy strategy) {
ArrayNode strategyJson = JsonNodeFactory.instance.arrayNode();
for (FieldPartitioner fp : strategy.getFieldPartitioners()) {
ObjectNode partitioner = JsonNodeFactory.instance.objectNode();
partitioner.set(NAME, TextNode.valueOf(fp.getName()));
if (fp instanceof IdentityFieldPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("identity"));
} else if (fp instanceof HashFieldPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("hash"));
partitioner.set(BUCKETS, LongNode.valueOf(fp.getCardinality()));
} else if (fp instanceof YearFieldPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("year"));
} else if (fp instanceof MonthFieldPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("month"));
} else if (fp instanceof DayOfMonthFieldPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("day"));
} else if (fp instanceof HourFieldPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("hour"));
} else if (fp instanceof MinuteFieldPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("minute"));
} else if (fp instanceof DateFormatPartitioner) {
partitioner.set(SOURCE, TextNode.valueOf(fp.getSourceName()));
partitioner.set(TYPE, TextNode.valueOf("dateFormat"));
partitioner.set(FORMAT,
TextNode.valueOf(((DateFormatPartitioner) fp).getPattern()));
} else if (fp instanceof ProvidedFieldPartitioner) {
partitioner.set(TYPE, TextNode.valueOf("provided"));
partitioner.set(VALUES,
TextNode.valueOf(((ProvidedFieldPartitioner) fp).getTypeAsString()));
} else {
throw new ValidationException(
"Unknown partitioner class: " + fp.getClass());
}
strategyJson.add(partitioner);
}
return strategyJson;
}