|
4 | 4 | package io.deephaven.engine.table.impl;
|
5 | 5 |
|
6 | 6 | import io.deephaven.UncheckedDeephavenException;
|
7 |
| -import io.deephaven.api.util.NameValidator; |
8 | 7 | import io.deephaven.engine.context.ExecutionContext;
|
9 | 8 | import io.deephaven.engine.context.QueryCompiler;
|
10 | 9 | import io.deephaven.engine.context.QueryCompilerRequest;
|
11 |
| -import io.deephaven.engine.context.QueryScope; |
12 | 10 | import io.deephaven.engine.table.impl.perf.QueryPerformanceRecorder;
|
| 11 | +import io.deephaven.engine.table.impl.select.codegen.FormulaAnalyzer; |
13 | 12 | import io.deephaven.util.MultiException;
|
14 | 13 | import io.deephaven.util.SafeCloseable;
|
15 | 14 | import io.deephaven.util.CompletionStageFuture;
|
|
18 | 17 | import org.jetbrains.annotations.VisibleForTesting;
|
19 | 18 |
|
20 | 19 | import java.util.ArrayList;
|
21 |
| -import java.util.Collections; |
22 | 20 | import java.util.List;
|
23 |
| -import java.util.Map; |
24 | 21 | import java.util.concurrent.ExecutionException;
|
25 | 22 | import java.util.concurrent.TimeUnit;
|
26 | 23 | import java.util.concurrent.TimeoutException;
|
27 | 24 |
|
28 |
| -public interface QueryCompilerRequestProcessor { |
| 25 | +public abstract class QueryCompilerRequestProcessor { |
29 | 26 |
|
30 | 27 | /**
|
31 | 28 | * @return An immediate QueryCompilerRequestProcessor
|
32 | 29 | */
|
33 |
| - static QueryCompilerRequestProcessor.ImmediateProcessor immediate() { |
| 30 | + public static QueryCompilerRequestProcessor.ImmediateProcessor immediate() { |
34 | 31 | return new ImmediateProcessor();
|
35 | 32 | }
|
36 | 33 |
|
37 | 34 | /**
|
38 | 35 | * @return A batch QueryCompilerRequestProcessor
|
39 | 36 | */
|
40 |
| - static QueryCompilerRequestProcessor.BatchProcessor batch() { |
| 37 | + public static QueryCompilerRequestProcessor.BatchProcessor batch() { |
41 | 38 | return new BatchProcessor();
|
42 | 39 | }
|
43 | 40 |
|
44 | 41 | /**
|
45 |
| - * @return a CachingSupplier that supplies a snapshot of the current query scope variables |
| 42 | + * @return a CachingSupplier that supplies a snapshot of current query scope variables and query library imports |
46 | 43 | */
|
47 | 44 | @VisibleForTesting
|
48 |
| - static CachingSupplier<Map<String, Object>> newQueryScopeVariableSupplier() { |
49 |
| - final QueryScope queryScope = ExecutionContext.getContext().getQueryScope(); |
50 |
| - return new CachingSupplier<>(() -> Collections.unmodifiableMap( |
51 |
| - queryScope.toMap((name, value) -> NameValidator.isValidQueryParameterName(name)))); |
| 45 | + public static CachingSupplier<FormulaAnalyzer.Imports> newFormulaImportsSupplier() { |
| 46 | + return new CachingSupplier<>(FormulaAnalyzer.Imports::new); |
52 | 47 | }
|
53 | 48 |
|
| 49 | + private final CachingSupplier<FormulaAnalyzer.Imports> formulaImportsSupplier = newFormulaImportsSupplier(); |
| 50 | + |
54 | 51 | /**
|
55 |
| - * @return a lazily cached snapshot of the current query scope variables |
| 52 | + * @return a lazily cached snapshot of current query scope variables and query library imports |
56 | 53 | */
|
57 |
| - Map<String, Object> getQueryScopeVariables(); |
| 54 | + public final FormulaAnalyzer.Imports getFormulaImports() { |
| 55 | + return formulaImportsSupplier.get(); |
| 56 | + } |
58 | 57 |
|
59 | 58 | /**
|
60 | 59 | * Submit a request for compilation. The QueryCompilerRequestProcessor is not required to immediately compile this
|
61 | 60 | * request.
|
62 | 61 | *
|
63 | 62 | * @param request the request to compile
|
64 | 63 | */
|
65 |
| - CompletionStageFuture<Class<?>> submit(@NotNull QueryCompilerRequest request); |
| 64 | + public abstract CompletionStageFuture<Class<?>> submit(@NotNull QueryCompilerRequest request); |
66 | 65 |
|
67 | 66 | /**
|
68 | 67 | * A QueryCompilerRequestProcessor that immediately compiles requests.
|
69 | 68 | */
|
70 |
| - class ImmediateProcessor implements QueryCompilerRequestProcessor { |
71 |
| - |
72 |
| - private final CachingSupplier<Map<String, Object>> queryScopeVariableSupplier = newQueryScopeVariableSupplier(); |
73 |
| - |
| 69 | + public static class ImmediateProcessor extends QueryCompilerRequestProcessor { |
74 | 70 | private ImmediateProcessor() {
|
75 | 71 | // force use of static factory method
|
76 | 72 | }
|
77 | 73 |
|
78 |
| - @Override |
79 |
| - public Map<String, Object> getQueryScopeVariables() { |
80 |
| - return queryScopeVariableSupplier.get(); |
81 |
| - } |
82 |
| - |
83 | 74 | @Override
|
84 | 75 | public CompletionStageFuture<Class<?>> submit(@NotNull final QueryCompilerRequest request) {
|
85 | 76 | final String desc = "Compile: " + request.description();
|
@@ -108,20 +99,14 @@ public CompletionStageFuture<Class<?>> submit(@NotNull final QueryCompilerReques
|
108 | 99 | * <p>
|
109 | 100 | * The compile method must be called to actually compile the requests.
|
110 | 101 | */
|
111 |
| - class BatchProcessor implements QueryCompilerRequestProcessor { |
| 102 | + public static class BatchProcessor extends QueryCompilerRequestProcessor { |
112 | 103 | private final List<QueryCompilerRequest> requests = new ArrayList<>();
|
113 | 104 | private final List<CompletionStageFuture.Resolver<Class<?>>> resolvers = new ArrayList<>();
|
114 |
| - private final CachingSupplier<Map<String, Object>> queryScopeVariableSupplier = newQueryScopeVariableSupplier(); |
115 | 105 |
|
116 | 106 | private BatchProcessor() {
|
117 | 107 | // force use of static factory method
|
118 | 108 | }
|
119 | 109 |
|
120 |
| - @Override |
121 |
| - public Map<String, Object> getQueryScopeVariables() { |
122 |
| - return queryScopeVariableSupplier.get(); |
123 |
| - } |
124 |
| - |
125 | 110 | @Override
|
126 | 111 | public CompletionStageFuture<Class<?>> submit(@NotNull final QueryCompilerRequest request) {
|
127 | 112 | final CompletionStageFuture.Resolver<Class<?>> resolver = CompletionStageFuture.make();
|
|
0 commit comments