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 @@ -87,13 +87,28 @@ public LocalInputSource(File baseDir, String filter)
}

@Nullable
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_NULL)
public File getBaseDir()
{
return baseDir;
}

/**
* Returns the base directory for serialization. This is better than returning {@link File} directly, because
* Jackson serializes {@link File} using {@link File#getAbsolutePath()}, and we'd prefer to not force relative
* path resolution as part of serialization.
*/
@Nullable
@JsonProperty("baseDir")
@JsonInclude(JsonInclude.Include.NON_NULL)
private String getBaseDirForSerialization()
{
if (baseDir == null) {
return null;
} else {
return baseDir.getPath();
}
}

@Nullable
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand All @@ -102,13 +117,23 @@ public String getFilter()
return filter;
}

@JsonProperty
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public List<File> getFiles()
{
return files;
}

/**
* Returns the list of file paths for serialization. This is better than returning {@link File} directly, because
* Jackson serializes {@link File} using {@link File#getAbsolutePath()}, and we'd prefer to not force relative
* path resolution as part of serialization.
*/
@JsonProperty("files")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<String> getFilesForSerialization()
{
return getFiles().stream().map(File::getPath).collect(Collectors.toList());
}

@Override
public Stream<InputSplit<List<File>>> createSplits(InputFormat inputFormat, @Nullable SplitHintSpec splitHintSpec)
{
Expand Down Expand Up @@ -233,9 +258,9 @@ public int hashCode()
public String toString()
{
return "LocalInputSource{" +
"baseDir=\"" + baseDir +
"\", filter=" + filter +
", files=" + files +
"}";
"baseDir=\"" + baseDir +
"\", filter=" + filter +
", files=" + files +
"}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.druid.data.input.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.druid.data.input.InputSource;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class LocalInputSourceTest
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Test
public void testSerde() throws IOException
public void testSerdeAbsoluteBaseDir() throws IOException
{
final ObjectMapper mapper = new ObjectMapper();
final LocalInputSource source = new LocalInputSource(new File("myFile").getAbsoluteFile(), "myFilter");
Expand All @@ -60,6 +61,33 @@ public void testSerde() throws IOException
Assert.assertEquals(source, fromJson);
}

@Test
public void testSerdeRelativeBaseDir() throws IOException
{
final ObjectMapper mapper = new ObjectMapper();
final LocalInputSource source = new LocalInputSource(new File("myFile"), "myFilter");
final byte[] json = mapper.writeValueAsBytes(source);
final LocalInputSource fromJson = (LocalInputSource) mapper.readValue(json, InputSource.class);
Assert.assertEquals(source, fromJson);
}

@Test
public void testSerdeMixedAbsoluteAndRelativeFiles() throws IOException
{
final ObjectMapper mapper = new ObjectMapper();
final LocalInputSource source = new LocalInputSource(
null,
null,
ImmutableList.of(
new File("myFile1"),
new File("myFile2").getAbsoluteFile()
)
);
final byte[] json = mapper.writeValueAsBytes(source);
final LocalInputSource fromJson = (LocalInputSource) mapper.readValue(json, InputSource.class);
Assert.assertEquals(source, fromJson);
}

@Test
public void testEquals()
{
Expand Down
4 changes: 0 additions & 4 deletions docs/multi-stage-query/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ You must either provide the `baseDir` or the list of `files`. You can provide bo
the files are assumed relative to the `baseDir`. If you provide a `filter`, you must provide the
`baseDir`.

Note that, due to [Issue #13359](https://github.com/apache/druid/issues/13359), the functionality
described above is broken. Until that issue is resolved, you must provide one or more absolute
file paths in the `files` property and the other two properties are unavailable.

#### Table Function Format

Each of the table functions above requires that you specify a format.
Expand Down