-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef123cb
commit a49987d
Showing
145 changed files
with
12,924 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
75 changes: 75 additions & 0 deletions
75
engine/processor/src/main/java/io/deephaven/processor/NamedObjectProcessor.java
This file contains 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,75 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.processor; | ||
|
||
import io.deephaven.annotations.BuildableStyle; | ||
import org.immutables.value.Value.Check; | ||
import org.immutables.value.Value.Immutable; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
@Immutable | ||
@BuildableStyle | ||
public abstract class NamedObjectProcessor<T> { | ||
|
||
public static <T> Builder<T> builder() { | ||
return ImmutableNamedObjectProcessor.builder(); | ||
} | ||
|
||
public static <T> NamedObjectProcessor<T> of(ObjectProcessor<T> processor, String... names) { | ||
return NamedObjectProcessor.<T>builder().processor(processor).addColumnNames(names).build(); | ||
} | ||
|
||
public static <T> NamedObjectProcessor<T> of(ObjectProcessor<T> processor, Iterable<String> names) { | ||
return NamedObjectProcessor.<T>builder().processor(processor).addAllColumnNames(names).build(); | ||
} | ||
|
||
public static <T> NamedObjectProcessor<T> prefix(ObjectProcessor<T> processor, String prefix) { | ||
final int size = processor.size(); | ||
if (size == 1) { | ||
return of(processor, prefix); | ||
} | ||
return of(processor, IntStream.range(0, size).mapToObj(ix -> prefix + "_" + ix).collect(Collectors.toList())); | ||
} | ||
|
||
public abstract ObjectProcessor<T> processor(); | ||
|
||
public abstract List<String> columnNames(); | ||
|
||
public interface Builder<T> { | ||
Builder<T> processor(ObjectProcessor<T> processor); | ||
|
||
Builder<T> addColumnNames(String element); | ||
|
||
Builder<T> addColumnNames(String... elements); | ||
|
||
Builder<T> addAllColumnNames(Iterable<String> elements); | ||
|
||
NamedObjectProcessor<T> build(); | ||
} | ||
|
||
|
||
public interface Provider { | ||
|
||
/** | ||
* Creates a named object processor that can process the input type {@code inputType}. | ||
* | ||
* @param inputType the input type | ||
* @return the named object processor | ||
* @param <T> the input type | ||
*/ | ||
<T> NamedObjectProcessor<? super T> named(Class<T> inputType); | ||
} | ||
|
||
@Check | ||
final void checkSizes() { | ||
if (columnNames().size() != processor().size()) { | ||
throw new IllegalArgumentException( | ||
String.format("Unmatched sizes; columnNames().size()=%d, processor().size()=%d", | ||
columnNames().size(), processor().size())); | ||
} | ||
} | ||
} |
This file contains 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
69 changes: 69 additions & 0 deletions
69
engine/processor/src/main/java/io/deephaven/processor/ObjectProcessorCombined.java
This file contains 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,69 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.processor; | ||
|
||
import io.deephaven.chunk.ObjectChunk; | ||
import io.deephaven.chunk.WritableChunk; | ||
import io.deephaven.qst.type.Type; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
final class ObjectProcessorCombined<T> implements ObjectProcessor<T> { | ||
|
||
public static <T> ObjectProcessor<T> of(List<ObjectProcessor<? super T>> processors) { | ||
final List<ObjectProcessor<? super T>> actual = processors.stream() | ||
.flatMap(ObjectProcessorCombined::destructure) | ||
.collect(Collectors.toUnmodifiableList()); | ||
if (actual.isEmpty()) { | ||
return ObjectProcessor.empty(); | ||
} | ||
if (actual.size() == 1) { | ||
// noinspection unchecked | ||
return (ObjectProcessor<T>) actual.get(0); | ||
} | ||
return new ObjectProcessorCombined<>(actual); | ||
} | ||
|
||
private static <T> Stream<ObjectProcessor<? super T>> destructure(ObjectProcessor<T> processor) { | ||
return processor instanceof ObjectProcessorCombined | ||
? ((ObjectProcessorCombined<T>) processor).processors.stream() | ||
: (processor instanceof ObjectProcessorEmpty | ||
? Stream.empty() | ||
: Stream.of(processor)); | ||
} | ||
|
||
|
||
private final List<ObjectProcessor<? super T>> processors; | ||
|
||
private ObjectProcessorCombined(List<ObjectProcessor<? super T>> processors) { | ||
this.processors = Objects.requireNonNull(processors); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return processors.stream().mapToInt(ObjectProcessor::size).sum(); | ||
} | ||
|
||
@Override | ||
public List<Type<?>> outputTypes() { | ||
return processors.stream() | ||
.map(ObjectProcessor::outputTypes) | ||
.flatMap(Collection::stream) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public void processAll(ObjectChunk<? extends T, ?> in, List<WritableChunk<?>> out) { | ||
int outIx = 0; | ||
for (ObjectProcessor<? super T> processor : processors) { | ||
final int toIx = outIx + processor.size(); | ||
processor.processAll(in, out.subList(outIx, toIx)); | ||
outIx = toIx; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
engine/processor/src/main/java/io/deephaven/processor/ObjectProcessorEmpty.java
This file contains 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,29 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.processor; | ||
|
||
import io.deephaven.chunk.ObjectChunk; | ||
import io.deephaven.chunk.WritableChunk; | ||
import io.deephaven.qst.type.Type; | ||
|
||
import java.util.List; | ||
|
||
enum ObjectProcessorEmpty implements ObjectProcessor<Object> { | ||
OBJECT_PROCESSOR_EMPTY; | ||
|
||
public static <T> ObjectProcessor<T> of() { | ||
// noinspection unchecked | ||
return (ObjectProcessor<T>) OBJECT_PROCESSOR_EMPTY; | ||
} | ||
|
||
@Override | ||
public List<Type<?>> outputTypes() { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public void processAll(ObjectChunk<?, ?> in, List<WritableChunk<?>> out) { | ||
|
||
} | ||
} |
Oops, something went wrong.