Skip to content

Commit

Permalink
QueryCompiler Batch Formula Compilation (#5070)
Browse files Browse the repository at this point in the history
This PR makes significant changes to the `QueryCompiler` API and behavior.

Highlights:
- introduce `QueryCompiler` as an interface and move implementation to engine-table
- introduce `QueryCompilerRequest`, an builder-style immutable to capture single compilation arguments
- introduce `QueryCompilerRequestProcessor` interface that has an Immediate and Batch based implementations
- introduce `CompletionStageFuture` as a friendly interface for a `CompleteableFuture` that does not expose completion methods to users
- added `SelectColumn#initDef` and `WhereFilter#init` that defer compilation to the provided `QueryCompilerRequestProcessor`
- all call sites that initialized `SelectColumn`s or `WhereFilter`s that might initialize more than one now use a batch processor
- a batch of compilation requests share a single `JavaFileManager` (reducing open file handles and compilation latency)
- the `QueryCompiler` caches at most one `JavaFileManager` to decrease latency of future compilation requests
- if there are enough compilation units, the `QueryCompiler` will compile in parallel using the `OperationInitializer`
- Generated Formulas no longer include the destination column name in the source body; enabling more compiled-formula sharing

Bug Fixes:
- `WhereFilter` and `SelectColumn` formulas now share `FormulaAnalyzer`s logic to ensure variable resolution is well-defined and ordered by: 
	- renamed columns, columns, renamed column array access, column array access, and last query scope variables
- `PartionAwareSourceTable`s `selectDistinct` implementation now behaves like `QueryTable`s implementation w.r.t. result columns as input to latter formulae
- When a formula generates an error it displays the original expression rather than the `QueryLanguageParser` transformed result
  • Loading branch information
nbauernfeind authored Apr 23, 2024
1 parent c6543b2 commit 3f2d095
Show file tree
Hide file tree
Showing 121 changed files with 3,359 additions and 1,749 deletions.
22 changes: 0 additions & 22 deletions Base/src/main/java/io/deephaven/base/Lazy.java

This file was deleted.

6 changes: 3 additions & 3 deletions Plot/src/main/java/io/deephaven/plot/colors/ColorMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.deephaven.base.verify.Require;
import io.deephaven.gui.color.Color;
import io.deephaven.gui.color.Paint;
import io.deephaven.plot.util.functions.SerializableClosure;
import io.deephaven.plot.util.functions.HasClosure;
import io.deephaven.plot.util.Range;
import groovy.lang.Closure;

Expand Down Expand Up @@ -294,13 +294,13 @@ public static <COLOR extends Paint> Function<Double, Paint> closureMap(final Map
for (final Map.Entry<Closure<Boolean>, COLOR> e : map.entrySet()) {
final Closure<Boolean> closure = e.getKey();
final COLOR color = e.getValue();
final SerializableClosure<Boolean> serializableClosure = new SerializableClosure<>(closure);
final HasClosure<Boolean> hasClosure = new HasClosure<>(closure);
final SerializablePredicate<Double> predicate = new SerializablePredicate<Double>() {
private static final long serialVersionUID = 613420989214281949L;

@Override
public boolean test(Double aDouble) {
return serializableClosure.getClosure().call(aDouble);
return hasClosure.getClosure().call(aDouble);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Wraps a {@link SerializableBiFunction} with the API of a function. <br/>
*/
public class ClosureBiFunction<T, U, R> extends SerializableClosure<R> implements SerializableBiFunction<T, U, R> {
public class ClosureBiFunction<T, U, R> extends HasClosure<R> implements SerializableBiFunction<T, U, R> {
private static final long serialVersionUID = 697974379939190730L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* A serializable closure which maps pair of doubles to doubles.
*/
public class ClosureDoubleBinaryOperator<T extends Number> extends SerializableClosure<T>
public class ClosureDoubleBinaryOperator<T extends Number> extends HasClosure<T>
implements DoubleBinaryOperator {

private static final long serialVersionUID = -6533578879266557626L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* A serializable closure which maps doubles to doubles.
*/
public class ClosureDoubleUnaryOperator<T extends Number> extends SerializableClosure<T>
public class ClosureDoubleUnaryOperator<T extends Number> extends HasClosure<T>
implements DoubleUnaryOperator {

private static final long serialVersionUID = -4092987117189101803L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import groovy.lang.Closure;

/**
* Wraps a {@link SerializableClosure} with the API of a function.
* Wraps a {@link HasClosure} with the API of a function.
*/
public class ClosureFunction<T, R> extends SerializableClosure<R> implements SerializableFunction<T, R> {
public class ClosureFunction<T, R> extends HasClosure<R> implements SerializableFunction<T, R> {

private static final long serialVersionUID = 3693316124178311688L;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.plot.util.functions;

import io.deephaven.base.verify.Require;
import groovy.lang.Closure;

/**
* A serializable closure.
*/
public class HasClosure<T> {

private final Closure<T> closure;

/**
* Creates a SerializableClosure instance with the {@code closure}.
*
* @param closure closure
*/
public HasClosure(final Closure<T> closure) {
Require.neqNull(closure, "closure");
this.closure = closure.dehydrate();
this.closure.setResolveStrategy(Closure.DELEGATE_ONLY);
}

/**
* Gets this SerializableClosure's closure.
*
* @return this SerializableClosure's closure
*/
public Closure<T> getClosure() {
return closure;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.plot.util.functions;

import io.deephaven.base.testing.BaseArrayTestCase;
import groovy.lang.Closure;

public class TestHasClosure extends BaseArrayTestCase {

private final String value = "S";

private final Closure<String> closure = new Closure<String>(null) {
@Override
public String call() {
return value;
}

@Override
public String call(Object... args) {
return value;
}

@Override
public String call(Object arguments) {
return value;
}
};

public void testSerializableClosure() {
HasClosure<String> hasClosure = new ClosureFunction<>(closure);

assertEquals(value, hasClosure.getClosure().call());
assertEquals(value, hasClosure.getClosure().call("T"));
assertEquals(value, hasClosure.getClosure().call("A", "B"));
}
}

This file was deleted.

Loading

0 comments on commit 3f2d095

Please sign in to comment.