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

Add InputSource and InputFormat interfaces #8823

Merged
merged 31 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
095bb32
Add InputSource and InputFormat interfaces
jihoonson Nov 5, 2019
f52f967
revert orc dependency
jihoonson Nov 5, 2019
93ab23f
fix dimension exclusions and failing unit tests
jihoonson Nov 5, 2019
e0b80cb
fix tests
jihoonson Nov 5, 2019
b4f041e
fix test
jihoonson Nov 5, 2019
d349db5
fix test
jihoonson Nov 5, 2019
f308f13
fix firehose and inputSource for parallel indexing task
jihoonson Nov 5, 2019
d451582
Merge branch 'master' of github.com:apache/incubator-druid into input…
jihoonson Nov 6, 2019
b7c8b87
fix tc
jihoonson Nov 6, 2019
e942a21
fix tc: remove unused method
jihoonson Nov 6, 2019
08d7872
Formattable
jihoonson Nov 7, 2019
c70af75
add needsFormat(); renamed to ObjectSource; pass metricsName for reader
jihoonson Nov 9, 2019
546d957
address comments
jihoonson Nov 9, 2019
7bb5d5f
fix closing resource
jihoonson Nov 9, 2019
6dba81a
fix checkstyle
jihoonson Nov 9, 2019
ea2c8f9
fix tests
jihoonson Nov 9, 2019
1ea7758
remove verify from csv
jihoonson Nov 10, 2019
218b392
Revert "remove verify from csv"
jihoonson Nov 11, 2019
7098056
address comments
jihoonson Nov 11, 2019
7381277
fix import order and javadoc
jihoonson Nov 12, 2019
2a3b114
flatMap
jihoonson Nov 12, 2019
355777c
sampleLine
jihoonson Nov 13, 2019
e466ea9
Add IntermediateRowParsingReader
jihoonson Nov 14, 2019
87b83fa
Address comments
jihoonson Nov 14, 2019
c1c3fb9
Merge branch 'master' of github.com:apache/incubator-druid into input…
jihoonson Nov 14, 2019
169ab49
move csv reader test
jihoonson Nov 14, 2019
a9d167a
remove test for verify
jihoonson Nov 14, 2019
42a6965
adjust comments
jihoonson Nov 14, 2019
230803b
Fix InputEntityIteratingReader
jihoonson Nov 14, 2019
540759b
rename source -> entity
jihoonson Nov 14, 2019
ce88049
address comments
jihoonson Nov 14, 2019
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 @@ -33,6 +33,7 @@
* @param <T> parser type
* @param <S> input split type
*/
@Deprecated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest adding a link to InputSource to show what's replacing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Added.

public interface FiniteFirehoseFactory<T extends InputRowParser, S> extends FirehoseFactory<T>
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.druid.data.input;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.apache.druid.data.input.impl.InputRowParser;
import org.apache.druid.data.input.impl.prefetch.PrefetchableTextFilesFirehoseFactory;
Expand Down Expand Up @@ -85,6 +86,7 @@ default Firehose connectForSampler(T parser, @Nullable File temporaryDirectory)
return connect(parser, temporaryDirectory);
}

@JsonIgnore
default boolean isSplittable()
{
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.data.input;

import com.google.common.base.Preconditions;
import org.apache.druid.data.input.impl.DimensionsSpec;
import org.apache.druid.data.input.impl.FirehoseToInputSourceReaderAdaptor;
import org.apache.druid.data.input.impl.InputFormat;
import org.apache.druid.data.input.impl.InputRowParser;
import org.apache.druid.data.input.impl.SplittableInputSource;
import org.apache.druid.data.input.impl.TimestampSpec;

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

public class FirehoseFactoryToInputSourceAdaptor implements SplittableInputSource
{
private final FiniteFirehoseFactory firehoseFactory;
private final InputRowParser inputRowParser;

public FirehoseFactoryToInputSourceAdaptor(FiniteFirehoseFactory firehoseFactory, InputRowParser inputRowParser)
{
this.firehoseFactory = firehoseFactory;
this.inputRowParser = Preconditions.checkNotNull(inputRowParser, "inputRowParser");
}

public FiniteFirehoseFactory getFirehoseFactory()
{
return firehoseFactory;
}

@Override
public boolean isSplittable()
{
return firehoseFactory.isSplittable();
}

@Override
public Stream<InputSplit> createSplits(InputFormat inputFormat, @Nullable SplitHintSpec splitHintSpec)
throws IOException
{
if (firehoseFactory.isSplittable()) {
return firehoseFactory.getSplits(splitHintSpec);
} else {
throw new UnsupportedOperationException();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is supporting unsplittable Firehoses future work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, only splittable firehose can create splits.

}
}

@Override
public int getNumSplits(InputFormat inputFormat, @Nullable SplitHintSpec splitHintSpec) throws IOException
{
if (firehoseFactory.isSplittable()) {
return firehoseFactory.getNumSplits(splitHintSpec);
} else {
throw new UnsupportedOperationException();
}
}

@Override
public SplittableInputSource withSplit(InputSplit split)
{
if (firehoseFactory.isSplittable()) {
return new FirehoseFactoryToInputSourceAdaptor(
firehoseFactory.withSplit(split),
inputRowParser
);
} else {
throw new UnsupportedOperationException();
}
}

@Override
public InputSourceReader reader(
TimestampSpec timestampSpec,
DimensionsSpec dimensionsSpec,
@Nullable InputFormat inputFormat, // inputFormat will be ignored
@Nullable File temporaryDirectory
)
{
return new FirehoseToInputSourceReaderAdaptor(firehoseFactory, inputRowParser, temporaryDirectory);
}
}
72 changes: 72 additions & 0 deletions core/src/main/java/org/apache/druid/data/input/InputSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.data.input;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.apache.druid.data.input.impl.DimensionsSpec;
import org.apache.druid.data.input.impl.HttpInputSource;
import org.apache.druid.data.input.impl.InputFormat;
import org.apache.druid.data.input.impl.LocalInputSource;
import org.apache.druid.data.input.impl.TimestampSpec;
import org.apache.druid.guice.annotations.ExtensionPoint;

import javax.annotation.Nullable;
import java.io.File;

/**
* InputSource abstracts the storage system where input data is stored.
* It creates an {@link InputSourceReader} to read data from the given input source.
* The most common use case would be:
*
* <pre>{@code
* InputSourceReader reader = inputSource.reader();
* try (CloseableIterator<InputRow> iterator = reader.read()) {
* while (iterator.hasNext()) {
* InputRow row = iterator.next();
* processRow(row);
* }
* }
* }</pre>
*/
@ExtensionPoint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment re @ExtensionPoint

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(value = {
@Type(name = "local", value = LocalInputSource.class),
@Type(name = "http", value = HttpInputSource.class)
})
public interface InputSource
{
/**
* Returns true if this inputSource can be processed in parallel using ParallelIndexSupervisorTask.
*/
default boolean isSplittable()
{
return false;
}

InputSourceReader reader(
TimestampSpec timestampSpec,
DimensionsSpec dimensionsSpec,
InputFormat inputFormat,
@Nullable File temporaryDirectory
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.data.input;

import org.apache.druid.guice.annotations.ExtensionPoint;
import org.apache.druid.java.util.common.parsers.CloseableIterator;

import java.io.IOException;

/**
* InputSourceReader reads data from {@link InputSource} and returns a {@link CloseableIterator} of
* {@link InputRow}. See {@link InputSource} for an example usage.
*
* Implementations of this class can use {@link SplitSource} and {@link SplitReader}.
*
* See {@link org.apache.druid.data.input.impl.SplitIteratingReader} as an example.
*/
@ExtensionPoint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment re @ExtensionPoint

public interface InputSourceReader
{
CloseableIterator<InputRow> read() throws IOException;

CloseableIterator<InputRowPlusRaw> sample() throws IOException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To handle potential 1:many mapping of raw input records to InputRow, we probably want a new wrapper type that associates a List<InputRow> to the 'raw' data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*
* @see FiniteFirehoseFactory#getSplits(SplitHintSpec)
* @see FiniteFirehoseFactory#getNumSplits(SplitHintSpec)
* @see org.apache.druid.data.input.impl.SplittableInputSource#createSplits
* @see org.apache.druid.data.input.impl.SplittableInputSource#getNumSplits
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(value = {
Expand Down
40 changes: 40 additions & 0 deletions core/src/main/java/org/apache/druid/data/input/SplitReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.data.input;

import org.apache.druid.guice.annotations.ExtensionPoint;
import org.apache.druid.java.util.common.parsers.CloseableIterator;

import java.io.File;
import java.io.IOException;

/**
* SplitReader knows how to parse data into {@link InputRow}.
* This class is <i>stateful</i> and a new SplitReader should be created per {@link InputSplit}.
*
* @see TextReader for text format readers
*/
@ExtensionPoint
public interface SplitReader
{
CloseableIterator<InputRow> read(SplitSource source, File temporaryDirectory) throws IOException;

CloseableIterator<InputRowPlusRaw> sample(SplitSource source, File temporaryDirectory) throws IOException;
}
Loading