-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Kinesis Input Format for timestamp, and payload parsing #16813
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
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ccdbc74
SQL syntax error should target USER persona
zachjsh 3173bb9
Merge remote-tracking branch 'apache/master' into fix-sql-syntax-erro…
zachjsh abe1092
* revert change to queryHandler and related tests, based on review co…
zachjsh 5d73047
* add test
zachjsh f30b5cd
Merge remote-tracking branch 'apache/master'
zachjsh ec3fe8a
Merge remote-tracking branch 'apache/master'
zachjsh d9fd4e4
Introduce KinesisRecordEntity to support Kinesis headers in InputFormats
zachjsh ba4d447
* add kinesisInputFormat and Reader, and tests
zachjsh 90e0f12
* bind KinesisInputFormat class to module
zachjsh 709fd16
* improve test coverage
zachjsh 2eaf0fe
* remove references to kafka
zachjsh 1dfd25e
* resolve review comments
zachjsh 67f99e9
* remove comment
zachjsh 72580ea
* fix grammer of comment
zachjsh 4c889a0
* fix comment again
zachjsh e16524b
* fix comment again
zachjsh 517c68e
* more review comments
zachjsh 238f80e
* add partitionKey
zachjsh 3abd8ad
* add check for same timestamp and partitionKey column name
zachjsh a5bcf72
* fix intellij inspection
zachjsh 84f5f54
Merge remote-tracking branch 'apache/master' into kinesis-input-format
zachjsh 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
157 changes: 157 additions & 0 deletions
157
...ndexing-service/src/main/java/org/apache/druid/data/input/kinesis/KinesisInputFormat.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,157 @@ | ||
| /* | ||
| * 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.kinesis; | ||
|
|
||
| import com.amazonaws.services.kinesis.model.Record; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Preconditions; | ||
| import org.apache.druid.data.input.InputEntity; | ||
| import org.apache.druid.data.input.InputEntityReader; | ||
| import org.apache.druid.data.input.InputFormat; | ||
| import org.apache.druid.data.input.InputRowSchema; | ||
| import org.apache.druid.data.input.impl.JsonInputFormat; | ||
| import org.apache.druid.data.input.impl.TimestampSpec; | ||
| import org.apache.druid.indexing.seekablestream.SettableByteEntity; | ||
| import org.apache.druid.java.util.common.DateTimes; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.io.File; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Kinesis aware InputFormat. Allows for reading kinesis specific values that are stored in the {@link Record}. At | ||
| * this time, this input format only supports reading data from the following record components | ||
| * <p> | ||
| * - {@link Record#data} | ||
| * - {@link Record#approximateArrivalTimestamp} | ||
| * - {@link Record#partitionKey} | ||
| * <p> | ||
| * This class can be extended easily to read other fields available in the kinesis record. | ||
| */ | ||
| public class KinesisInputFormat implements InputFormat | ||
| { | ||
| private static final String DEFAULT_TIMESTAMP_COLUMN_NAME = "kinesis.timestamp"; | ||
| private static final String DEFAULT_PARTITION_KEY_COLUMN_NAME = "kinesis.partitionKey"; | ||
|
|
||
| // Since KinesisInputFormat blends data from record properties, and payload, timestamp spec can be pointing to an | ||
| // attribute within one of these 2 sections. To handle scenarios where there is no timestamp value in the payload, we | ||
| // induce an artificial timestamp value to avoid unnecessary parser barf out. Users in such situations can use the | ||
| // inputFormat's kinesis record timestamp as its primary timestamp. | ||
| public static final String DEFAULT_AUTO_TIMESTAMP_STRING = "__kif_auto_timestamp"; | ||
| private final TimestampSpec dummyTimestampSpec = new TimestampSpec(DEFAULT_AUTO_TIMESTAMP_STRING, "auto", DateTimes.EPOCH); | ||
|
|
||
| private final InputFormat valueFormat; | ||
| private final String timestampColumnName; | ||
| private final String partitionKeyColumnName; | ||
|
|
||
| public KinesisInputFormat( | ||
| @JsonProperty("valueFormat") InputFormat valueFormat, | ||
| @JsonProperty("partitionKeyColumnName") @Nullable String partitionKeyColumnName, | ||
| @JsonProperty("timestampColumnName") @Nullable String timestampColumnName | ||
| ) | ||
| { | ||
| this.valueFormat = Preconditions.checkNotNull(valueFormat, "valueFormat must not be null"); | ||
| Preconditions.checkState( | ||
| !(timestampColumnName != null && timestampColumnName.equals(partitionKeyColumnName)), | ||
| "timestampColumnName and partitionKeyColumnName must be different" | ||
| ); | ||
| this.partitionKeyColumnName = partitionKeyColumnName != null | ||
| ? partitionKeyColumnName | ||
| : DEFAULT_PARTITION_KEY_COLUMN_NAME; | ||
| this.timestampColumnName = timestampColumnName != null ? timestampColumnName : DEFAULT_TIMESTAMP_COLUMN_NAME; | ||
|
zachjsh marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean isSplittable() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public InputEntityReader createReader(InputRowSchema inputRowSchema, InputEntity source, File temporaryDirectory) | ||
| { | ||
| final SettableByteEntity<KinesisRecordEntity> settableByteEntitySource; | ||
| if (source instanceof SettableByteEntity) { | ||
| settableByteEntitySource = (SettableByteEntity<KinesisRecordEntity>) source; | ||
| } else { | ||
| settableByteEntitySource = new SettableByteEntity<>(); | ||
| settableByteEntitySource.setEntity((KinesisRecordEntity) source); | ||
| } | ||
| InputRowSchema newInputRowSchema = new InputRowSchema( | ||
| dummyTimestampSpec, | ||
| inputRowSchema.getDimensionsSpec(), | ||
| inputRowSchema.getColumnsFilter(), | ||
| inputRowSchema.getMetricNames() | ||
| ); | ||
| return new KinesisInputReader( | ||
| inputRowSchema, | ||
| settableByteEntitySource, | ||
| JsonInputFormat.withLineSplittable(valueFormat, false).createReader( | ||
| newInputRowSchema, | ||
| source, | ||
| temporaryDirectory | ||
| ), | ||
| partitionKeyColumnName, | ||
| timestampColumnName | ||
| ); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public InputFormat getValueFormat() | ||
| { | ||
| return valueFormat; | ||
| } | ||
|
|
||
| @Nullable | ||
| @JsonProperty | ||
| public String getTimestampColumnName() | ||
| { | ||
| return timestampColumnName; | ||
| } | ||
|
|
||
| @Nullable | ||
| @JsonProperty | ||
| public String getPartitionKeyColumnName() | ||
| { | ||
| return partitionKeyColumnName; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) | ||
| { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| KinesisInputFormat that = (KinesisInputFormat) o; | ||
| return Objects.equals(valueFormat, that.valueFormat) | ||
| && Objects.equals(timestampColumnName, that.timestampColumnName) | ||
| && Objects.equals(partitionKeyColumnName, that.partitionKeyColumnName); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() | ||
| { | ||
| return Objects.hash(valueFormat, timestampColumnName, partitionKeyColumnName); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.