Skip to content

Commit

Permalink
Corey's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Mar 5, 2024
1 parent c894ff0 commit a03abe4
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 140 deletions.
22 changes: 0 additions & 22 deletions Base/src/main/java/io/deephaven/base/Lazy.java

This file was deleted.

2 changes: 1 addition & 1 deletion Util/src/main/java/io/deephaven/util/MultiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;

/**
* An exception to use when a series of operations must all be executed, but may all throw exceptions themselves. This
* An exception to use when a series of operations mus all be executed, but may all throw exceptions themselves. This
* allows for retention of all exception data.
*/
public class MultiException extends Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public final class CachingSupplier<OUTPUT_TYPE> implements Supplier<OUTPUT_TYPE>
private final Supplier<OUTPUT_TYPE> internalSupplier;

private volatile boolean hasCachedResult;
private volatile OUTPUT_TYPE cachedResult;
private OUTPUT_TYPE cachedResult;
private RuntimeException errorResult;

/**
* Construct a {@link Supplier} wrapper.
Expand All @@ -33,12 +34,19 @@ public OUTPUT_TYPE get() {
if (!hasCachedResult) {
synchronized (this) {
if (!hasCachedResult) {
cachedResult = internalSupplier.get();
try {
cachedResult = internalSupplier.get();
} catch (RuntimeException err) {
errorResult = err;
}
hasCachedResult = true;
}
}
}

if (errorResult != null) {
throw errorResult;
}
return cachedResult;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
*/
package io.deephaven.engine.table.impl;

import io.deephaven.UncheckedDeephavenException;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.context.QueryCompiler;
import io.deephaven.engine.context.QueryCompilerRequest;
import io.deephaven.engine.table.impl.perf.QueryPerformanceRecorder;
import io.deephaven.util.MultiException;
import io.deephaven.util.SafeCloseable;
import io.deephaven.util.CompletionStageFuture;
import io.deephaven.util.CompletionStageFutureImpl;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

public interface QueryCompilerRequestProcessor {
/**
Expand Down Expand Up @@ -80,12 +83,25 @@ public void compile() {

try (final SafeCloseable ignored = QueryPerformanceRecorder.getInstance().getCompilationNugget(desc)) {
final QueryCompiler compiler = ExecutionContext.getContext().getQueryCompiler();
if (requests.size() == 1) {
compiler.compile(requests.get(0), resolvers.get(0));
} else {
compiler.compile(
requests.toArray(QueryCompilerRequest[]::new),
resolvers.toArray(CompletionStageFuture.Resolver[]::new));
// noinspection unchecked
compiler.compile(
requests.toArray(QueryCompilerRequest[]::new),
resolvers.toArray(CompletionStageFuture.Resolver[]::new));

final List<Throwable> exceptions = new ArrayList<>();
for (CompletionStageFuture.Resolver<Class<?>> resolver : resolvers) {
try {
Object ignored2 = resolver.getFuture().get();
} catch (ExecutionException err) {
exceptions.add(err.getCause());
} catch (InterruptedException err) {
exceptions.add(err);
}
}
if (!exceptions.isEmpty()) {
throw new UncheckedDeephavenException("Compilation failed",
MultiException.maybeWrapInMultiException("Compilation exceptions for multiple requests",
exceptions));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ protected Future<FormulaFactory> createKernelFormulaFactory(
return formulaKernelFactoryFuture
.thenApply(formulaKernelFactory -> (columnName, rowSet, lazy, columnsToData, params) -> {
// Maybe warn that we ignore "lazy". By the way, "lazy" is the wrong term anyway. "lazy" doesn't
// mean
// "cached", which is how we are using it.
// mean "cached", which is how we are using it.
final Map<String, ColumnSource<?>> netColumnSources = new HashMap<>();
for (final String sourceColumnName : sd.sources) {
final ColumnSource<?> columnSourceToUse = columnsToData.get(sourceColumnName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public enum Mode {

public static Supplier<Map<String, Object>> newQueryScopeVariableSupplier() {
final QueryScope queryScope = ExecutionContext.getContext().getQueryScope();
return new CachingSupplier<>(
() -> queryScope.toMap((name, value) -> NameValidator.isValidQueryParameterName(name)));
return new CachingSupplier<>(() -> Collections.unmodifiableMap(
queryScope.toMap((name, value) -> NameValidator.isValidQueryParameterName(name))));
}

public static void initializeSelectColumns(
Expand Down
1 change: 1 addition & 0 deletions open-api/lang-parser/lang-parser.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
apply from: "$rootDir/gradle/web-common.gradle"

dependencies {
implementation project(':Util')
api project(':open-api-shared-fu')
implementation project(':log-factory')
api project(':proto:proto-backplane-grpc')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/
package io.deephaven.lang.parse;

import io.deephaven.base.Lazy;
import io.deephaven.base.verify.Assert;
import io.deephaven.io.logger.Logger;
import io.deephaven.lang.generated.*;
import io.deephaven.proto.backplane.script.grpc.CompletionItem;
import io.deephaven.proto.backplane.script.grpc.DocumentRange;
import io.deephaven.proto.backplane.script.grpc.Position;
import io.deephaven.proto.backplane.script.grpc.TextEdit;
import io.deephaven.util.datastructures.CachingSupplier;
import io.deephaven.web.shared.fu.MappedIterable;

import java.util.*;
Expand Down Expand Up @@ -100,7 +100,7 @@ public boolean containsIndex(int i) {
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\r?\\n");
private final ChunkerDocument doc;

private final Lazy<Set<ChunkerStatement>> statements;
private final CachingSupplier<Set<ChunkerStatement>> statements;
private final String src;
private String errorSource;
private ParseException error;
Expand All @@ -112,7 +112,7 @@ public ParsedDocument(ChunkerDocument doc, String document) {
this.src = document;
computedPositions = new ConcurrentHashMap<>(4);
assignments = new ConcurrentHashMap<>(12);
statements = new Lazy<>(() -> {
statements = new CachingSupplier<>(() -> {
final LinkedHashSet<ChunkerStatement> stmts = new LinkedHashSet<>();
doc.childrenAccept(new ChunkerDefaultVisitor() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
package io.deephaven.lang.completion;

import io.deephaven.base.Lazy;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.table.TableDefinition;
import io.deephaven.engine.context.QueryLibrary;
import io.deephaven.engine.util.ScriptSession;
import io.deephaven.util.datastructures.CachingSupplier;

import java.util.Collection;
import java.util.Map;
Expand All @@ -26,15 +26,15 @@ public class CompletionLookups {

private static final WeakHashMap<ScriptSession, CompletionLookups> lookups = new WeakHashMap<>();

private final Lazy<Collection<Class<?>>> statics;
private final CachingSupplier<Collection<Class<?>>> statics;
private final Map<String, TableDefinition> referencedTables;
private final Lazy<CustomCompletion> customCompletions;
private final CachingSupplier<CustomCompletion> customCompletions;

public CompletionLookups(Set<CustomCompletion.Factory> customCompletionFactory) {
final QueryLibrary ql = ExecutionContext.getContext().getQueryLibrary();
statics = new Lazy<>(ql::getStaticImports);
statics = new CachingSupplier<>(ql::getStaticImports);
referencedTables = new ConcurrentHashMap<>();
customCompletions = new Lazy<>(() -> new DelegatingCustomCompletion(customCompletionFactory));
customCompletions = new CachingSupplier<>(() -> new DelegatingCustomCompletion(customCompletionFactory));

// This can be slow, so lets start it on a background thread right away.
final ForkJoinPool pool = ForkJoinPool.commonPool();
Expand Down

0 comments on commit a03abe4

Please sign in to comment.