Skip to content
Merged
Show file tree
Hide file tree
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 @@ -30,7 +30,6 @@
import org.apache.druid.data.input.Row;
import org.apache.druid.java.util.common.DateTimes;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.server.ServerTestHelper;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -43,6 +42,8 @@

public class HashBasedNumberedShardSpecTest
{
private final ObjectMapper objectMapper = ShardSpecTestUtils.initObjectMapper();

@Test
public void testEquals()
{
Expand All @@ -56,16 +57,15 @@ public void testEquals()
@Test
public void testSerdeRoundTrip() throws Exception
{

final ShardSpec spec = ServerTestHelper.MAPPER.readValue(
ServerTestHelper.MAPPER.writeValueAsBytes(
final ShardSpec spec = objectMapper.readValue(
objectMapper.writeValueAsBytes(
new HashBasedNumberedShardSpec(
1,
2,
1,
3,
ImmutableList.of("visitor_id"),
ServerTestHelper.MAPPER
objectMapper
)
),
ShardSpec.class
Expand All @@ -80,14 +80,14 @@ public void testSerdeRoundTrip() throws Exception
@Test
public void testSerdeBackwardsCompat() throws Exception
{
final ShardSpec spec = ServerTestHelper.MAPPER.readValue(
final ShardSpec spec = objectMapper.readValue(
"{\"type\": \"hashed\", \"partitions\": 2, \"partitionNum\": 1}",
ShardSpec.class
);
Assert.assertEquals(1, spec.getPartitionNum());
Assert.assertEquals(2, spec.getNumCorePartitions());

final ShardSpec specWithPartitionDimensions = ServerTestHelper.MAPPER.readValue(
final ShardSpec specWithPartitionDimensions = objectMapper.readValue(
"{\"type\": \"hashed\", \"partitions\": 2, \"partitionNum\": 1, \"partitionDimensions\":[\"visitor_id\"]}",
ShardSpec.class
);
Expand All @@ -104,9 +104,9 @@ public void testSerdeBackwardsCompat() throws Exception
public void testPartitionChunks()
{
final List<ShardSpec> specs = ImmutableList.of(
new HashBasedNumberedShardSpec(0, 3, 0, 3, null, ServerTestHelper.MAPPER),
new HashBasedNumberedShardSpec(1, 3, 1, 3, null, ServerTestHelper.MAPPER),
new HashBasedNumberedShardSpec(2, 3, 2, 3, null, ServerTestHelper.MAPPER)
new HashBasedNumberedShardSpec(0, 3, 0, 3, null, objectMapper),
new HashBasedNumberedShardSpec(1, 3, 1, 3, null, objectMapper),
new HashBasedNumberedShardSpec(2, 3, 2, 3, null, objectMapper)
);

final List<PartitionChunk<String>> chunks = Lists.transform(
Expand Down Expand Up @@ -208,7 +208,7 @@ public void testSharePartitionSpace()
1,
3,
ImmutableList.of("visitor_id"),
ServerTestHelper.MAPPER
objectMapper
);
Assert.assertTrue(shardSpec.sharePartitionSpace(NumberedPartialShardSpec.instance()));
Assert.assertTrue(shardSpec.sharePartitionSpace(new HashBasedNumberedPartialShardSpec(null, 0, 1)));
Expand All @@ -226,11 +226,11 @@ public boolean assertExistsInOneSpec(List<ShardSpec> specs, InputRow row)
throw new ISE("None of the partition matches");
}

public static class HashOverridenShardSpec extends HashBasedNumberedShardSpec
public class HashOverridenShardSpec extends HashBasedNumberedShardSpec
{
public HashOverridenShardSpec(int partitionNum, int partitions)
{
super(partitionNum, partitions, partitionNum, partitions, null, ServerTestHelper.MAPPER);
super(partitionNum, partitions, partitionNum, partitions, null, objectMapper);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,19 @@
* under the License.
*/

package org.apache.druid.server.shard;
package org.apache.druid.timeline.partition;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.druid.java.util.common.Intervals;
import org.apache.druid.server.ServerTestHelper;
import org.apache.druid.timeline.Overshadowable;
import org.apache.druid.timeline.TimelineObjectHolder;
import org.apache.druid.timeline.VersionedIntervalTimeline;
import org.apache.druid.timeline.partition.HashBasedNumberedPartialShardSpec;
import org.apache.druid.timeline.partition.NumberedOverwritePartialShardSpec;
import org.apache.druid.timeline.partition.NumberedPartialShardSpec;
import org.apache.druid.timeline.partition.NumberedShardSpec;
import org.apache.druid.timeline.partition.PartitionChunk;
import org.apache.druid.timeline.partition.ShardSpec;
import org.apache.druid.timeline.partition.SingleDimensionPartialShardSpec;
import org.joda.time.Interval;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -58,8 +51,9 @@ public void testEquals()
@Test
public void testSerdeRoundTrip() throws Exception
{
final ShardSpec spec = ServerTestHelper.MAPPER.readValue(
ServerTestHelper.MAPPER.writeValueAsBytes(new NumberedShardSpec(1, 2)),
final ObjectMapper objectMapper = ShardSpecTestUtils.initObjectMapper();
final ShardSpec spec = objectMapper.readValue(
objectMapper.writeValueAsBytes(new NumberedShardSpec(1, 2)),
ShardSpec.class
);
Assert.assertEquals(1, spec.getPartitionNum());
Expand All @@ -69,7 +63,8 @@ public void testSerdeRoundTrip() throws Exception
@Test
public void testSerdeBackwardsCompat() throws Exception
{
final ShardSpec spec = ServerTestHelper.MAPPER.readValue(
final ObjectMapper objectMapper = ShardSpecTestUtils.initObjectMapper();
final ShardSpec spec = objectMapper.readValue(
"{\"type\": \"numbered\", \"partitions\": 2, \"partitionNum\": 1}",
ShardSpec.class
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.druid.timeline.partition;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.InjectableValues.Std;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
Expand All @@ -30,6 +31,7 @@ public static ObjectMapper initObjectMapper()
{
// Copied configurations from org.apache.druid.jackson.DefaultObjectMapper
final ObjectMapper mapper = new ObjectMapper();
mapper.setInjectableValues(new Std().addValue(ObjectMapper.class, mapper));
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
// See https://github.com/FasterXML/jackson-databind/issues/170
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.druid.server.shard;
package org.apache.druid.timeline.partition;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand All @@ -30,12 +30,6 @@
import org.apache.druid.data.input.MapBasedInputRow;
import org.apache.druid.java.util.common.Pair;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.timeline.partition.HashBasedNumberedPartialShardSpec;
import org.apache.druid.timeline.partition.NumberedOverwritePartialShardSpec;
import org.apache.druid.timeline.partition.NumberedPartialShardSpec;
import org.apache.druid.timeline.partition.ShardSpec;
import org.apache.druid.timeline.partition.SingleDimensionPartialShardSpec;
import org.apache.druid.timeline.partition.SingleDimensionShardSpec;
import org.junit.Assert;
import org.junit.Test;

Expand Down