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

implement FiniteFirehoseFactory in InlineFirehose #8682

Merged
merged 2 commits into from
Oct 17, 2019
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 @@ -22,19 +22,21 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import org.apache.druid.data.input.FiniteFirehoseFactory;
import org.apache.druid.data.input.Firehose;
import org.apache.druid.data.input.FirehoseFactory;
import org.apache.druid.data.input.InputSplit;
import org.apache.druid.data.input.impl.StringInputRowParser;

import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.stream.Stream;

/**
* Creates firehose that produces data inlined in its own spec
*/
public class InlineFirehoseFactory implements FirehoseFactory<StringInputRowParser>
public class InlineFirehoseFactory implements FiniteFirehoseFactory<StringInputRowParser, String>
{
private final String data;

Expand Down Expand Up @@ -74,4 +76,28 @@ public int hashCode()
{
return Objects.hash(data);
}

@Override
public boolean isSplittable()
{
return false;
}

@Override
public Stream<InputSplit<String>> getSplits()
{
return Stream.of(new InputSplit<>(data));
}

@Override
public int getNumSplits()
{
return 1;
}

@Override
public FiniteFirehoseFactory<StringInputRowParser, String> withSplit(InputSplit<String> split)
{
return new InlineFirehoseFactory(split.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package org.apache.druid.segment.realtime.firehose;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.druid.data.input.FiniteFirehoseFactory;
import org.apache.druid.data.input.Firehose;
import org.apache.druid.data.input.InputRow;
import org.apache.druid.data.input.InputSplit;
import org.apache.druid.data.input.impl.CSVParseSpec;
import org.apache.druid.data.input.impl.DimensionsSpec;
import org.apache.druid.data.input.impl.StringInputRowParser;
Expand All @@ -37,6 +39,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@SuppressWarnings({"NullableProblems", "ConstantConditions"})
public class InlineFirehoseFactoryTest
Expand Down Expand Up @@ -77,6 +80,14 @@ public void setUp()
target = new InlineFirehoseFactory(DATA);
}

@Test
public void testInterfaceImplementation()
{
Assert.assertTrue(target instanceof FiniteFirehoseFactory);
Assert.assertFalse(target.isSplittable());
Assert.assertEquals(1, target.getNumSplits());
}

@Test(expected = NullPointerException.class)
public void testContstructorDataRequired()
{
Expand All @@ -101,6 +112,16 @@ public void testConnect() throws IOException
Assert.assertEquals(VALUE, values.get(0));
}

@Test
public void testForcedSplitAndClone()
{
Optional<InputSplit<String>> inputSplitOptional = target.getSplits().findFirst();
Assert.assertTrue(inputSplitOptional.isPresent());
FiniteFirehoseFactory<StringInputRowParser, String> cloneWithSplit = target.withSplit(inputSplitOptional.get());
Assert.assertTrue(cloneWithSplit instanceof InlineFirehoseFactory);
Assert.assertEquals(DATA, ((InlineFirehoseFactory) cloneWithSplit).getData());
}

@Test
public void testSerde() throws IOException
{
Expand Down