-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add inline firehose #8056
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
Merged
Merged
Add inline firehose #8056
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,33 +24,33 @@ title: "Apache Druid (incubating) Firehoses" | |
|
|
||
| # Apache Druid (incubating) Firehoses | ||
|
|
||
| Firehoses are used in [native batch ingestion tasks](../ingestion/native_tasks.html), stream push tasks automatically created by [Tranquility](../ingestion/stream-push.html) ingestion model. | ||
| Firehoses are used in [native batch ingestion tasks](../ingestion/native_tasks.html) and stream push tasks automatically created by [Tranquility](../ingestion/stream-push.html). | ||
|
|
||
| They are pluggable and thus the configuration schema can and will vary based on the `type` of the firehose. | ||
| They are pluggable, and thus the configuration schema can and will vary based on the `type` of the Firehose. | ||
|
|
||
| | Field | Type | Description | Required | | ||
| |-------|------|-------------|----------| | ||
| | type | String | Specifies the type of firehose. Each value will have its own configuration schema, firehoses packaged with Druid are described below. | yes | | ||
| | type | String | Specifies the type of Firehose. Each value will have its own configuration schema. Firehoses packaged with Druid are described below. | yes | | ||
|
|
||
| ## Additional Firehoses | ||
|
|
||
| There are several firehoses readily available in Druid, some are meant for examples, others can be used directly in a production environment. | ||
| There are several Firehoses readily available in Druid. Some are meant for examples, and others can be used directly in a production environment. | ||
|
|
||
| For additional firehoses, please see our [extensions list](../development/extensions.html). | ||
| For additional Firehoses, please see our [extensions list](../development/extensions.html). | ||
|
|
||
| ### LocalFirehose | ||
|
|
||
| This Firehose can be used to read the data from files on local disk. | ||
| It can be used for POCs to ingest data on disk. | ||
| This firehose is _splittable_ and can be used by [native parallel index tasks](./native_tasks.html#parallel-index-task). | ||
| Since each split represents a file in this firehose, each worker task of `index_parallel` will read a file. | ||
| A sample local firehose spec is shown below: | ||
| This Firehose is _splittable_ and can be used by [native parallel index tasks](./native_tasks.html#parallel-index-task). | ||
| Since each split represents a file in this Firehose, each worker task of `index_parallel` will read a file. | ||
| A sample local Firehose spec is shown below: | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "local", | ||
| "filter" : "*.csv", | ||
| "baseDir" : "/data/directory" | ||
| "type": "local", | ||
| "filter" : "*.csv", | ||
| "baseDir": "/data/directory" | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -63,14 +63,14 @@ A sample local firehose spec is shown below: | |
| ### HttpFirehose | ||
|
|
||
| This Firehose can be used to read the data from remote sites via HTTP. | ||
| This firehose is _splittable_ and can be used by [native parallel index tasks](./native_tasks.html#parallel-index-task). | ||
| Since each split represents a file in this firehose, each worker task of `index_parallel` will read a file. | ||
| A sample http firehose spec is shown below: | ||
| This Firehose is _splittable_ and can be used by [native parallel index tasks](./native_tasks.html#parallel-index-task). | ||
| Since each split represents a file in this Firehose, each worker task of `index_parallel` will read a file. | ||
| A sample HTTP Firehose spec is shown below: | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "http", | ||
| "uris" : ["http://example.com/uri1", "http://example2.com/uri2"] | ||
| "type": "http", | ||
| "uris": ["http://example.com/uri1", "http://example2.com/uri2"] | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -107,61 +107,61 @@ You can also use the other existing Druid PasswordProviders. Here is an example | |
| } | ||
| ``` | ||
|
|
||
| The below configurations can be optionally used for tuning the firehose performance. | ||
| The below configurations can be optionally used for tuning the Firehose performance. | ||
|
|
||
| |property|description|default| | ||
| |--------|-----------|-------| | ||
| |maxCacheCapacityBytes|Maximum size of the cache space in bytes. 0 means disabling cache. Cached files are not removed until the ingestion task completes.|1073741824| | ||
| |maxFetchCapacityBytes|Maximum size of the fetch space in bytes. 0 means disabling prefetch. Prefetched files are removed immediately once they are read.|1073741824| | ||
| |prefetchTriggerBytes|Threshold to trigger prefetching http objects.|maxFetchCapacityBytes / 2| | ||
| |fetchTimeout|Timeout for fetching a http object.|60000| | ||
| |maxFetchRetry|Maximum retry for fetching a http object.|3| | ||
| |prefetchTriggerBytes|Threshold to trigger prefetching HTTP objects.|maxFetchCapacityBytes / 2| | ||
| |fetchTimeout|Timeout for fetching an HTTP object.|60000| | ||
| |maxFetchRetry|Maximum retries for fetching an HTTP object.|3| | ||
|
|
||
| ### IngestSegmentFirehose | ||
|
|
||
| This Firehose can be used to read the data from existing druid segments. | ||
| It can be used to ingest existing druid segments using a new schema and change the name, dimensions, metrics, rollup, etc. of the segment. | ||
| This firehose is _splittable_ and can be used by [native parallel index tasks](./native_tasks.html#parallel-index-task). | ||
| A sample ingest firehose spec is shown below - | ||
| This Firehose is _splittable_ and can be used by [native parallel index tasks](./native_tasks.html#parallel-index-task). | ||
| A sample ingest Firehose spec is shown below: | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "ingestSegment", | ||
| "dataSource" : "wikipedia", | ||
| "interval" : "2013-01-01/2013-01-02" | ||
| "type": "ingestSegment", | ||
| "dataSource": "wikipedia", | ||
| "interval": "2013-01-01/2013-01-02" | ||
| } | ||
| ``` | ||
|
|
||
| |property|description|required?| | ||
| |--------|-----------|---------| | ||
| |type|This should be "ingestSegment".|yes| | ||
| |dataSource|A String defining the data source to fetch rows from, very similar to a table in a relational database|yes| | ||
| |interval|A String representing ISO-8601 Interval. This defines the time range to fetch the data over.|yes| | ||
| |interval|A String representing the ISO-8601 interval. This defines the time range to fetch the data over.|yes| | ||
| |dimensions|The list of dimensions to select. If left empty, no dimensions are returned. If left null or not defined, all dimensions are returned. |no| | ||
| |metrics|The list of metrics to select. If left empty, no metrics are returned. If left null or not defined, all metrics are selected.|no| | ||
| |filter| See [Filters](../querying/filters.html)|no| | ||
| |maxInputSegmentBytesPerTask|When used with the native parallel index task, the maximum number of bytes of input segments to process in a single task. If a single segment is larger than this number, it will be processed by itself in a single task (input segments are never split across tasks). Defaults to 150MB.|no| | ||
|
|
||
| #### SqlFirehose | ||
| ### SqlFirehose | ||
|
|
||
| SqlFirehoseFactory can be used to ingest events residing in RDBMS. The database connection information is provided as part of the ingestion spec. For each query, the results are fetched locally and indexed. If there are multiple queries from which data needs to be indexed, queries are prefetched in the background upto `maxFetchCapacityBytes` bytes. | ||
| This Firehose can be used to ingest events residing in RDBMS. The database connection information is provided as part of the ingestion spec. For each query, the results are fetched locally and indexed. If there are multiple queries from which data needs to be indexed, queries are prefetched in the background upto `maxFetchCapacityBytes` bytes. | ||
|
|
||
| Requires one of the following extensions: | ||
| * [MySQL Metadata Store](../development/extensions-core/mysql.html). | ||
| * [PostgreSQL Metadata Store](../development/extensions-core/postgresql.html). | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "sql", | ||
| "type": "sql", | ||
| "database": { | ||
| "type": "mysql", | ||
| "connectorConfig" : { | ||
| "connectURI" : "jdbc:mysql://host:port/schema", | ||
| "user" : "user", | ||
| "password" : "password" | ||
| "connectorConfig": { | ||
| "connectURI": "jdbc:mysql://host:port/schema", | ||
| "user": "user", | ||
| "password": "password" | ||
| } | ||
| }, | ||
| "sqls" : ["SELECT * FROM table1", "SELECT * FROM table2"] | ||
| "sqls": ["SELECT * FROM table1", "SELECT * FROM table2"] | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -176,39 +176,56 @@ Requires one of the following extensions: | |
| |foldCase|Toggle case folding of database column names. This may be enabled in cases where the database returns case insensitive column names in query results.|false|No| | ||
| |sqls|List of SQL queries where each SQL query would retrieve the data to be indexed.||Yes| | ||
|
|
||
| #### Database | ||
| ### Database | ||
|
|
||
| |property|description|default|required?| | ||
| |--------|-----------|-------|---------| | ||
| |type|The type of database to query. Valid values are `mysql` and `postgresql`_||Yes| | ||
| |connectorConfig|specify the database connection properties via `connectURI`, `user` and `password`||Yes| | ||
| |connectorConfig|Specify the database connection properties via `connectURI`, `user` and `password`||Yes| | ||
|
|
||
| ### InlineFirehose | ||
|
|
||
| This Firehose can be used to read the data inlined in its own spec. | ||
| It can be used for demos or for quickly testing out parsing and schema. | ||
| A sample inline Firehose spec is shown below: | ||
|
|
||
| ```json | ||
| { | ||
| "type": "inline", | ||
| "data": "0,values,formatted\n1,as,CSV" | ||
| } | ||
| ``` | ||
|
|
||
| |property|description|required?| | ||
| |--------|-----------|---------| | ||
| |type|This should be "inline".|yes| | ||
| |data|Inlined data to ingest.|yes| | ||
|
|
||
| ### CombiningFirehose | ||
|
|
||
| This firehose can be used to combine and merge data from a list of different firehoses. | ||
| This can be used to merge data from more than one firehose. | ||
| This Firehose can be used to combine and merge data from a list of different Firehoses. | ||
| This can be used to merge data from more than one Firehose. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing about not writing, but this 2nd sentence seems redundant |
||
|
|
||
| ```json | ||
| { | ||
| "type" : "combining", | ||
| "delegates" : [ { firehose1 }, { firehose2 }, ..... ] | ||
| "type": "combining", | ||
| "delegates": [ { firehose1 }, { firehose2 }, ... ] | ||
| } | ||
| ``` | ||
|
|
||
| |property|description|required?| | ||
| |--------|-----------|---------| | ||
| |type|This should be "combining"|yes| | ||
| |delegates|list of firehoses to combine data from|yes| | ||
| |delegates|List of Firehoses to combine data from|yes| | ||
|
|
||
|
|
||
| ### Streaming Firehoses | ||
|
|
||
| The EventReceiverFirehose is used in tasks automatically generated by [Tranquility stream push](../ingestion/stream-push.html). These firehoses are not suitable for batch ingestion. | ||
| The EventReceiverFirehose is used in tasks automatically generated by [Tranquility stream push](../ingestion/stream-push.html). These Firehoses are not suitable for batch ingestion. | ||
|
|
||
| #### EventReceiverFirehose | ||
|
|
||
| EventReceiverFirehoseFactory can be used to ingest events using an http endpoint. | ||
| This Firehose can be used to ingest events using an HTTP endpoint. | ||
|
|
||
| ```json | ||
| { | ||
|
|
@@ -217,42 +234,42 @@ EventReceiverFirehoseFactory can be used to ingest events using an http endpoint | |
| "bufferSize": 10000 | ||
| } | ||
| ``` | ||
| When using this firehose, events can be sent by submitting a POST request to the http endpoint: | ||
| When using this Firehose, events can be sent by submitting a POST request to the HTTP endpoint: | ||
|
|
||
| `http://<peonHost>:<port>/druid/worker/v1/chat/<eventReceiverServiceName>/push-events/` | ||
|
|
||
| |property|description|required?| | ||
| |--------|-----------|---------| | ||
| |type|This should be "receiver"|yes| | ||
| |serviceName|Name used to announce the event receiver service endpoint|yes| | ||
| |maxIdleTime|A firehose is automatically shut down after not receiving any events for this period of time, in milliseconds. If not specified, a firehose is never shut down due to being idle. Zero and negative values have the same effect.|no| | ||
| |bufferSize|Size of buffer used by firehose to store events|no, default is 100000| | ||
| |maxIdleTime|A Firehose is automatically shut down after not receiving any events for this period of time, in milliseconds. If not specified, a Firehose is never shut down due to being idle. Zero and negative values have the same effect.|no| | ||
| |bufferSize|Size of buffer used by Firehose to store events|no, default is 100000| | ||
|
|
||
| Shut down time for EventReceiverFirehose can be specified by submitting a POST request to | ||
|
|
||
| `http://<peonHost>:<port>/druid/worker/v1/chat/<eventReceiverServiceName>/shutdown?shutoffTime=<shutoffTime>` | ||
|
|
||
| If shutOffTime is not specified, the firehose shuts off immediately. | ||
| If shutOffTime is not specified, the Firehose shuts off immediately. | ||
|
|
||
| #### TimedShutoffFirehose | ||
|
|
||
| This can be used to start a firehose that will shut down at a specified time. | ||
| This can be used to start a Firehose that will shut down at a specified time. | ||
| An example is shown below: | ||
|
|
||
| ```json | ||
| { | ||
| "type" : "timed", | ||
| "type": "timed", | ||
| "shutoffTime": "2015-08-25T01:26:05.119Z", | ||
| "delegate": { | ||
| "type": "receiver", | ||
| "serviceName": "eventReceiverServiceName", | ||
| "bufferSize": 100000 | ||
| "type": "receiver", | ||
| "serviceName": "eventReceiverServiceName", | ||
| "bufferSize": 100000 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| |property|description|required?| | ||
| |--------|-----------|---------| | ||
| |type|This should be "timed"|yes| | ||
| |shutoffTime|time at which the firehose should shut down, in ISO8601 format|yes| | ||
| |delegate|firehose to use|yes| | ||
| |shutoffTime|Time at which the Firehose should shut down, in ISO8601 format|yes| | ||
| |delegate|Firehose to use|yes| | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
server/src/main/java/org/apache/druid/segment/realtime/firehose/InlineFirehose.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| * 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.segment.realtime.firehose; | ||
|
|
||
| import org.apache.commons.io.IOUtils; | ||
| import org.apache.commons.io.LineIterator; | ||
| import org.apache.druid.data.input.Firehose; | ||
| import org.apache.druid.data.input.InputRow; | ||
| import org.apache.druid.data.input.InputRowPlusRaw; | ||
| import org.apache.druid.data.input.impl.StringInputRowParser; | ||
| import org.apache.druid.java.util.common.StringUtils; | ||
| import org.apache.druid.java.util.common.parsers.ParseException; | ||
| import org.apache.druid.utils.Runnables; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.Charset; | ||
| import java.util.NoSuchElementException; | ||
|
|
||
| /** | ||
| * Firehose that produces data from its own spec | ||
| */ | ||
| public class InlineFirehose implements Firehose | ||
| { | ||
| private final StringInputRowParser parser; | ||
| private final LineIterator lineIterator; | ||
|
|
||
| InlineFirehose(String data, StringInputRowParser parser) throws IOException | ||
| { | ||
| this.parser = parser; | ||
|
|
||
| Charset charset = Charset.forName(parser.getEncoding()); | ||
| InputStream stream = new ByteArrayInputStream(data.getBytes(charset)); | ||
| lineIterator = IOUtils.lineIterator(stream, charset); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasMore() | ||
| { | ||
| return lineIterator.hasNext(); | ||
| } | ||
|
|
||
| @Override | ||
| public InputRow nextRow() | ||
| { | ||
| return parser.parse(nextRaw()); | ||
| } | ||
|
|
||
| private String nextRaw() | ||
| { | ||
| if (!hasMore()) { | ||
| throw new NoSuchElementException(); | ||
| } | ||
|
|
||
| return lineIterator.next(); | ||
| } | ||
|
|
||
| @Override | ||
| public InputRowPlusRaw nextRowWithRaw() | ||
| { | ||
| String raw = nextRaw(); | ||
| try { | ||
| return InputRowPlusRaw.of(parser.parse(raw), StringUtils.toUtf8(raw)); | ||
| } | ||
| catch (ParseException e) { | ||
| return InputRowPlusRaw.of(StringUtils.toUtf8(raw), e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Runnable commit() | ||
| { | ||
| return Runnables.getNoopRunnable(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException | ||
| { | ||
| lineIterator.close(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i know you didn't write this, but maybe it should be "an RDBMS."?