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 @@ -46,7 +46,7 @@ public class InputEntityIteratingReader implements InputSourceReader
private final Iterator<InputEntity> sourceIterator;
private final File temporaryDirectory;

InputEntityIteratingReader(
public InputEntityIteratingReader(
InputRowSchema inputRowSchema,
InputFormat inputFormat,
Stream<InputEntity> sourceStream,
Expand Down
28 changes: 28 additions & 0 deletions docs/development/extensions-core/google.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ Deep storage can be written to Google Cloud Storage either via this extension or
|`druid.google.prefix`||GCS prefix.|No-prefix|


<a name="input-source"></a>

## Google cloud storage batch ingestion input source

This extension also provides an input source for Druid native batch ingestion to support reading objects directly from Google Cloud Storage. Objects can be specified as list of Google Cloud Storage URI strings. The Google Cloud Storage input source is splittable and can be used by [native parallel index tasks](../../ingestion/native-batch.md#parallel-task), where each worker task of `index_parallel` will read a single object.

```json
...
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "google",
"uris": ["gs://foo/bar/file.json", "gs://bar/foo/file2.json"]
},
"inputFormat": {
"type": "json"
},
...
},
...
```

|property|description|default|required?|
|--------|-----------|-------|---------|
|type|This should be `google`.|N/A|yes|
|uris|JSON array of URIs where Google Cloud Storage files to be ingested are located.|N/A|yes|


## Firehose

<a name="firehose"></a>
Expand Down
7 changes: 6 additions & 1 deletion extensions-core/google-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@
<artifactId>google-api-client</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.apache.druid</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.google;

import com.google.common.base.Predicate;
import org.apache.druid.data.input.InputEntity;
import org.apache.druid.storage.google.GoogleByteSource;
import org.apache.druid.storage.google.GoogleStorage;
import org.apache.druid.storage.google.GoogleUtils;
import org.apache.druid.utils.CompressionUtils;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

public class GoogleCloudStorageEntity implements InputEntity
{
private final GoogleStorage storage;
private final URI uri;

GoogleCloudStorageEntity(GoogleStorage storage, URI uri)
{
this.storage = storage;
this.uri = uri;
}

@Nullable
@Override
public URI getUri()
{
return uri;
}

@Override
public InputStream open() throws IOException
{
// Get data of the given object and open an input stream
final String bucket = uri.getAuthority();
final String key = GoogleUtils.extractGoogleCloudStorageObjectKey(uri);
final GoogleByteSource byteSource = new GoogleByteSource(storage, bucket, key);
return CompressionUtils.decompress(byteSource.openStream(), uri.getPath());
}

@Override
public Predicate<Throwable> getFetchRetryCondition()
{
return GoogleUtils.GOOGLE_RETRY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* 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.google;

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import org.apache.druid.data.input.AbstractInputSource;
import org.apache.druid.data.input.InputFormat;
import org.apache.druid.data.input.InputRowSchema;
import org.apache.druid.data.input.InputSourceReader;
import org.apache.druid.data.input.InputSplit;
import org.apache.druid.data.input.SplitHintSpec;
import org.apache.druid.data.input.impl.InputEntityIteratingReader;
import org.apache.druid.data.input.impl.SplittableInputSource;
import org.apache.druid.storage.google.GoogleStorage;

import javax.annotation.Nullable;
import java.io.File;
import java.net.URI;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

public class GoogleCloudStorageInputSource extends AbstractInputSource implements SplittableInputSource<URI>
{
private final GoogleStorage storage;
private final List<URI> uris;

@JsonCreator
public GoogleCloudStorageInputSource(
@JacksonInject GoogleStorage storage,
@JsonProperty("uris") List<URI> uris
)
{
this.storage = storage;
this.uris = uris;
}

@JsonProperty("uris")
public List<URI> getUris()
{
return uris;
}


@Override
public Stream<InputSplit<URI>> createSplits(InputFormat inputFormat, @Nullable SplitHintSpec splitHintSpec)
{
return uris.stream().map(InputSplit::new);
}

@Override
public int getNumSplits(InputFormat inputFormat, @Nullable SplitHintSpec splitHintSpec)
{
return uris.size();
}

@Override
public SplittableInputSource<URI> withSplit(InputSplit<URI> split)
{
return new GoogleCloudStorageInputSource(storage, ImmutableList.of(split.get()));
}

@Override
public boolean needsFormat()
{
return true;
}

@Override
protected InputSourceReader formattableReader(
InputRowSchema inputRowSchema,
InputFormat inputFormat,
@Nullable File temporaryDirectory
)
{
return new InputEntityIteratingReader(
inputRowSchema,
inputFormat,
createSplits(inputFormat, null).map(split -> new GoogleCloudStorageEntity(storage, split.get())),
temporaryDirectory
);
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
GoogleCloudStorageInputSource that = (GoogleCloudStorageInputSource) o;
return Objects.equals(uris, that.uris);
}

@Override
public int hashCode()
{
return Objects.hash(uris);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.collect.ImmutableList;
import com.google.inject.Binder;
import com.google.inject.Provides;
import org.apache.druid.data.input.google.GoogleCloudStorageInputSource;
import org.apache.druid.firehose.google.StaticGoogleBlobStoreFirehoseFactory;
import org.apache.druid.guice.Binders;
import org.apache.druid.guice.JsonConfigProvider;
Expand All @@ -41,7 +42,7 @@

public class GoogleStorageDruidModule implements DruidModule
{
public static final String SCHEME = "google";
static final String SCHEME = "google";
private static final Logger LOG = new Logger(GoogleStorageDruidModule.class);
private static final String APPLICATION_NAME = "druid-google-extensions";

Expand Down Expand Up @@ -72,7 +73,9 @@ public void setupModule(SetupContext context)
}
},
new SimpleModule().registerSubtypes(
new NamedType(StaticGoogleBlobStoreFirehoseFactory.class, "static-google-blobstore"))
new NamedType(StaticGoogleBlobStoreFirehoseFactory.class, "static-google-blobstore"),
new NamedType(GoogleCloudStorageInputSource.class, SCHEME)
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
package org.apache.druid.storage.google;

import com.google.api.client.http.HttpResponseException;
import com.google.common.base.Predicate;

import java.io.IOException;
import java.net.URI;

public class GoogleUtils
{

public static boolean isRetryable(Throwable t)
{
if (t instanceof HttpResponseException) {
Expand All @@ -34,4 +35,11 @@ public static boolean isRetryable(Throwable t)
}
return t instanceof IOException;
}

public static String extractGoogleCloudStorageObjectKey(URI uri)
{
return uri.getPath().startsWith("/") ? uri.getPath().substring(1) : uri.getPath();
}

public static final Predicate<Throwable> GOOGLE_RETRY = e -> isRetryable(e);
}
Loading