Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Fix s3 base path and partition operation (#74)
Browse files Browse the repository at this point in the history
* Fix s3 base path and partition operation

* Fix testGetEvaluatedPartitionsStatic
  • Loading branch information
stlava authored and diranged committed May 23, 2018
1 parent e0c9646 commit 73d4331
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
Expand Up @@ -59,11 +59,7 @@ protected LinkedHashMap<String, String> getPartitions(DeserializedEvent devent)
}
}

if (key != null) {
partitions.put(spec.getName(), spec.interpret(key));
} else {
throw new OperationException("unable to find value for partition " + spec.getName());
}
partitions.put(spec.getName(), spec.interpret(key));
}

return partitions;
Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDefault;
import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDescription;
import com.nextdoor.bender.operation.OperationException;
import com.nextdoor.bender.utils.Time;

public class PartitionSpec {
Expand Down Expand Up @@ -151,7 +152,7 @@ public String interpret(String input) {

protected String getFormattedString(String input) {
if (input == null) {
return input;
throw new OperationException("unable to find value for partition '" + this.getName() +"'");
}

switch (this.stringFormat) {
Expand Down
Expand Up @@ -23,6 +23,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Stream;
Expand Down Expand Up @@ -63,8 +64,7 @@ public void testGetEvaluatedPartitionsString() throws FieldNotFoundException {
@Test
public void testGetEvaluatedPartitionsStatic() {
List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
List<String> sources = Arrays.asList("foo");
PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STATIC, "123", 0);
PartitionSpec spec = new PartitionSpec("foo", Collections.emptyList(), PartitionSpec.Interpreter.STATIC, "123", 0);
partitionSpecs.add(spec);

PartitionOperation op = new PartitionOperation(partitionSpecs);
Expand Down Expand Up @@ -119,7 +119,7 @@ public void testGetEvaluatedPartitionsStringMultipleFieldsNull() throws FieldNot
try {
op.perform(ievent);
} catch (OperationException e) {
assertEquals("unable to find value for partition foo", e.getMessage());
assertEquals("unable to find value for partition 'foo'", e.getMessage());
throw e;
}
}
Expand All @@ -141,7 +141,7 @@ public void testGetEvaluatedPartitionsFieldNotFoundException() throws FieldNotFo
try {
op.perform(ievent);
} catch (OperationException e) {
assertEquals("unable to find value for partition foo", e.getMessage());
assertEquals("unable to find value for partition 'foo'", e.getMessage());
throw e;
}
}
Expand Down
Expand Up @@ -153,7 +153,7 @@ public void sendBatch(TransportBuffer buffer, LinkedHashMap<String, String> part

if (this.basePath.endsWith("/")) {
key = this.basePath + key;
} else {
} else if (!this.basePath.equals("")) {
key = this.basePath + '/' + key;
}

Expand Down
Expand Up @@ -38,7 +38,7 @@ public class S3TransportConfig extends RegionalTransportConfig {

@JsonSchemaDescription("Path to append to S3 keys.")
@JsonProperty(required = false)
private String basePath;
private String basePath = "";

@JsonSchemaDescription("Compress files with bz2 compression.")
@JsonSchemaDefault("true")
Expand Down

0 comments on commit 73d4331

Please sign in to comment.