Skip to content
Open
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 @@ -46,6 +46,10 @@ public class CalcitePlanContext {
/** This thread local variable is only used to skip script encoding in script pushdown. */
public static final ThreadLocal<Boolean> skipEncoding = ThreadLocal.withInitial(() -> false);

/** When true, disables the OpenSearch shard request cache for the current query. */
public static final ThreadLocal<Boolean> disableRequestCache =
ThreadLocal.withInitial(() -> false);

/** When true, the execution engine strips all-null columns from the result (used by timewrap). */
public static final ThreadLocal<Boolean> stripNullColumns = ThreadLocal.withInitial(() -> false);

Expand Down Expand Up @@ -124,22 +128,6 @@ public class CalcitePlanContext {
/** Whether we're currently inside a lambda context. */
@Getter @Setter private boolean inLambdaContext = false;

/**
* When enabled, tracks which RelNode ids were produced by each AST command. Each entry maps an
* AST node class name to the list of RelNode ids it produced (excluding children).
*/
@Getter @Setter private boolean trackingEnabled = false;

@Getter private final List<NodeIdMapping> nodeIdMappings = new ArrayList<>();

/** Records a mapping from an AST command to the RelNode ids it produced. */
public void recordMapping(String astNodeType, List<Integer> relNodeIds) {
nodeIdMappings.add(new NodeIdMapping(astNodeType, relNodeIds));
}

/** A mapping from one AST command to the RelNode ids it produced. */
public record NodeIdMapping(String astNodeType, List<Integer> relNodeIds) {}

private CalcitePlanContext(FrameworkConfig config, SysLimit sysLimit, QueryType queryType) {
this.config = config;
this.sysLimit = sysLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,45 +234,11 @@ public CalciteRelNodeVisitor(DataSourceService dataSourceService) {
}

public RelNode analyze(UnresolvedPlan unresolved, CalcitePlanContext context) {
if (context.isTrackingEnabled()) {
int idBefore = context.relBuilder.size() > 0 ? context.relBuilder.peek().getId() : -1;
RelNode result = unresolved.accept(this, context);
int idAfter = context.relBuilder.peek().getId();
List<Integer> producedIds = new ArrayList<>();
for (int id = idBefore + 1; id <= idAfter; id++) {
producedIds.add(id);
}
context.recordMapping(unresolved.getClass().getSimpleName(), producedIds);
return result;
}
return unresolved.accept(this, context);
}

@Override
public RelNode visitChildren(Node node, CalcitePlanContext context) {
if (context.isTrackingEnabled() && node instanceof UnresolvedPlan) {
// Track each child's total contribution (the subtree it produces)
RelNode result = null;
for (Node child : node.getChild()) {
int idBefore = context.relBuilder.size() > 0 ? context.relBuilder.peek().getId() : -1;
RelNode childResult = child.accept(this, context);
result = childResult;
// After child.accept returns, the child's visit* method has fully completed,
// so all RelNodes produced by that child (including ITS children) are on the stack.
int idAfter = context.relBuilder.peek().getId();
if (child instanceof UnresolvedPlan) {
List<Integer> producedIds = new ArrayList<>();
for (int id = idBefore + 1; id <= idAfter; id++) {
producedIds.add(id);
}
context.recordMapping(child.getClass().getSimpleName(), producedIds);
}
}
if (node instanceof UnresolvedPlan plan) {
mapPathMaterializer.materializePaths(plan, context);
}
return result;
}
RelNode result = super.visitChildren(node, context);
if (node instanceof UnresolvedPlan plan) {
mapPathMaterializer.materializePaths(plan, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@
@Data
@Builder
public class AnalyzeResponse {

private final String query;
private final List<QuerySegment> querySegments;
// private final String ast;
// private final String query;
private final List<String> logicalPlan;
private final List<String> physicalPlan;
private final QueryProfile profile;
private final List<OperatorNode> operator_tree;
private final List<String> recommendations;
private final List<Recommendation> recommendations;
private final List<SchemaColumn> schema;
private final Object[][] datarows;
private final long total;
private final long size;
private final boolean possibleCacheHit;

@Data
@Builder
Expand All @@ -34,23 +31,19 @@ public static class SchemaColumn {
private final String type;
}

@Data
@Builder
public static class QuerySegment {
private final String nodeType;
private final String source;
public enum RecommendationSeverityLevel {
INFO,
WARNING,
CRITICAL
}

@Data
@Builder
public static class OperatorNode {
private final String source;
private final List<String> node_type;
private final List<String> description;
private final String estimated_cost;
private final Long estimated_rows;
private final String actual_time_ms;
private final Long actual_rows;
private final Boolean is_pushed_down;
public static class Recommendation {
private final RecommendationSeverityLevel severity;
private final String rule;
private final String message;
private final String affected_node;
private final String suggestion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ default void explain(
explain(plan, mode, context, listener);
}

/**
* Get the cumulative request cache hit count for the given indices. Returns -1 if not supported
* by this engine.
*/
default long getRequestCacheHitCount(String... indexNames) {
return -1;
}

/** Data class that encapsulates ExprValue. */
@Data
class QueryResponse {
Expand Down
Loading
Loading