if(partitionByFields != null) {
partitionBySchemaFields = new Field[partitionByFields.length];
int i = 0;
for(String partitionByField : partitionByFields) {
partitionByField = partitionByField.trim();
Field partitionField = schema.getField(partitionByField);
if(partitionField == null) {
throw new TableBuilderException("Invalid partition field: " + partitionByField
+ " not present in its Schema: " + schema + ".");
}
partitionBySchemaFields[i] = partitionField;
i++;
}
}
} else {
if(partitionByFields != null) {
throw new TableBuilderException(
"Replicated table with partition fields is an inconsistent specification. Please check if you are doing something wrong.");
}
}
// Indexes
List<FieldIndex> indexes = new ArrayList<FieldIndex>();
for(String fieldToIndex : fieldsToIndex) {
fieldToIndex = fieldToIndex.trim();
// Check that field exists in schema
Field field1 = schema.getField(fieldToIndex);
if(field1 == null) {
throw new TableBuilderException("Invalid field to index: " + fieldToIndex
+ " not present in specified Schema: " + schema + ".");
}
indexes.add(new FieldIndex(field1));
}
// Also, support for compound indexes
for(List<String> compoundIndex : compoundIndexes) {
List<Field> compoundIndexFields = new ArrayList<Field>();
for(String field : compoundIndex) {
field = field.trim();
// Check that each field exists in schema
Field field2 = schema.getField(field);
if(field2 == null) {
throw new TableBuilderException("Invalid compound index: " + compoundIndex + ", field "
+ field + " not present in specified Schema: " + schema + ".");
}
compoundIndexFields.add(field2);