Skip to content
Merged
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 @@ -58,18 +58,24 @@
{#if "nodeAttributes" in value}
{@const { nodeAttributes } = value}
<table>
<!-- Header row with worker names -->
<thead>
<!-- Header row with node name -->
<tr>
<th
><label
<th colspan={nodeAttributes.columns.length + 1}
>{nodeAttributes.title}
&nbsp;
<label
><input
type="checkbox"
id="show-advanced"
bind:checked={showAdvanced}
/> show advanced</label
/>show advanced&nbsp;</label
></th
>
</tr>
<!-- Header row with worker names -->
<tr>
<th></th>
{#each nodeAttributes.columns as column}
<th>{column}</th>
{/each}
Expand Down
9 changes: 8 additions & 1 deletion js-packages/profiler-lib/src/cytograph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ export class CytographRendering {
let visible = false;

const tooltipData: NodeAttributes = {
title: "",
columns: [],
rows: [],
attributes: new Map()
Expand Down Expand Up @@ -1040,7 +1041,13 @@ export class CytographRendering {
if (attributes.kv.size !== 0) {
visible = true;
for (const [key, value] of attributes.kv.entries()) {
tooltipData.attributes.set(key, value);
if (key == "id") {
tooltipData.title = value + tooltipData.title;
} else if (key == "operation") {
tooltipData.title = tooltipData.title + " " + value;
} else {
tooltipData.attributes.set(key, value);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions js-packages/profiler-lib/src/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface TooltipRow {

/** Tooltip data structure */
export interface NodeAttributes {
title: string;
/** Column headers */
columns: string[];
/** Rows of metrics with values */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.dbsp.sqlCompiler.circuit.annotation.Annotations;
import org.dbsp.sqlCompiler.compiler.backend.JsonDecoder;
import org.dbsp.sqlCompiler.compiler.errors.InternalCompilerError;
import org.dbsp.sqlCompiler.compiler.errors.SourcePositionRange;
import org.dbsp.sqlCompiler.compiler.frontend.calciteCompiler.ProgramIdentifier;
import org.dbsp.sqlCompiler.compiler.frontend.calciteObject.CalciteEmptyRel;
import org.dbsp.sqlCompiler.compiler.frontend.calciteObject.CalciteRelNode;
Expand Down Expand Up @@ -57,6 +58,14 @@ public boolean hasOutput(int outputNumber) {
return this.internalOutputs.get(outputNumber) != null;
}

@Override
public List<SourcePositionRange> getSourcePositions() {
ArrayList<SourcePositionRange> result = new ArrayList<>();
for (DBSPOperator op: this.allOperators)
result.addAll(op.getSourcePositions());
return result;
}

public boolean contains(DBSPOperator operator) {
return this.operators.contains(operator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.dbsp.sqlCompiler.circuit.annotation.Annotations;
import org.dbsp.sqlCompiler.circuit.annotation.CompactName;
import org.dbsp.sqlCompiler.circuit.annotation.OperatorHash;
import org.dbsp.sqlCompiler.compiler.errors.SourcePositionRange;
import org.dbsp.sqlCompiler.ir.expression.DBSPClosureExpression;
import org.dbsp.sqlCompiler.ir.expression.DBSPExpression;
import org.dbsp.sqlCompiler.ir.type.user.DBSPTypeStream;
Expand Down Expand Up @@ -213,4 +214,8 @@ public OutputPort getOutput(int outputNo) {
public CalciteRelNode getRelNode() {
return this.node.to(CalciteRelNode.class);
}

public List<SourcePositionRange> getSourcePositions() {
return this.getRelNode().getSourcePositions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ public final class DBSPWindowOperator extends DBSPBinaryOperator implements ICon
public final boolean lowerInclusive;
public final boolean upperInclusive;

public DBSPWindowOperator(
CalciteRelNode node, CalciteObject object,
boolean lowerInclusive, boolean upperInclusive,
public DBSPWindowOperator(CalciteRelNode node, boolean lowerInclusive, boolean upperInclusive,
OutputPort data, OutputPort control) {
super(node, "window", new NoExpression(DBSPTypeVoid.INSTANCE), data.outputType(),
data.isMultiset(), data, control);
super(node, "window", null, data.outputType(), data.isMultiset(), data, control);
// Check that the left input and output are indexed ZSets
this.getOutputIndexedZSetType();
this.lowerInclusive = lowerInclusive;
Expand All @@ -48,7 +45,7 @@ public DBSPSimpleOperator with(
Utilities.enforce(newInputs.size() == 2, () -> "Expected 2 inputs, got " + newInputs.size());
if (force || this.inputsDiffer(newInputs))
return new DBSPWindowOperator(
this.getRelNode(), this.getFunction().getNode(), this.lowerInclusive, this.upperInclusive,
this.getRelNode(), this.lowerInclusive, this.upperInclusive,
newInputs.get(0), newInputs.get(1)).copyAnnotations(this);
}
return this;
Expand All @@ -68,7 +65,7 @@ public static DBSPWindowOperator fromJson(JsonNode node, JsonDecoder decoder) {
DBSPSimpleOperator.CommonInfo info = commonInfoFromJson(node, decoder);
boolean lowerInclusive = Utilities.getBooleanProperty(node, "lowerInclusive");
boolean upperInclusive = Utilities.getBooleanProperty(node, "upperInclusive");
return new DBSPWindowOperator(CalciteEmptyRel.INSTANCE, CalciteObject.EMPTY,
return new DBSPWindowOperator(CalciteEmptyRel.INSTANCE,
lowerInclusive, upperInclusive, info.getInput(0), info.getInput(1))
.addAnnotations(info.annotations(), DBSPWindowOperator.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,16 @@ String getFunction(DBSPSimpleOperator node) {
String chain = node.to(DBSPChainOperator.class).chain.toString();
return rustToDot(chain);
}
if (expression == null)
return "";
if (expression == null) {
if (this.details >= 3) {
StringBuilder builder = new StringBuilder();
for (SourcePositionRange pos: node.getSourcePositions())
builder.append(pos.toShortString());
return builder.toString();
} else {
return "";
}
}
if (node.is(DBSPFlatMapOperator.class)) {
if (expression.is(DBSPFlatmap.class)) {
expression = LowerCircuitVisitor.rewriteFlatmap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
/** Represents a CalciteObject that does not exist.
* Similar to {@link CalciteObject#EMPTY}, but this is a subclass of {@link CalciteRelNode}. */
public class CalciteEmptyRel extends CalciteRelNode {
@Override
public CalciteRelNode copy() {
return INSTANCE;
}

private CalciteEmptyRel() {}

public static final CalciteEmptyRel INSTANCE = new CalciteEmptyRel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,35 @@
import org.dbsp.util.IHasId;
import org.dbsp.util.IIndentStream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public abstract class CalciteRelNode extends CalciteObject implements IHasId {
// Not clear these should be here
public static final SqlDialect DIALECT = SqlDialect.DatabaseProduct.UNKNOWN.getDialect();
static final RelToSqlConverter CONVERTER = new RelToSqlConverter(DIALECT);
final List<SourcePositionRange> positions = new ArrayList<>();

public List<SourcePositionRange> getSourcePositions() {
return this.positions;
}

protected CalciteRelNode(SourcePositionRange pos) {
super(pos);
if (pos.isValid())
this.positions.add(pos);
}

public CalciteRelNode addSourcePositions(Iterable<SourcePositionRange> positions) {
for (var pos: positions)
if (pos.isValid())
this.positions.add(pos);
return this;
}

public abstract CalciteRelNode copy();

protected CalciteRelNode() { this(SourcePositionRange.INVALID); }

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public String toString() {
return this.getId() + " PartOf(" + this.relNode.getDigest() + ")";
}

@Override
public CalciteRelNode copy() {
return new IntermediateRel(this.relNode).addSourcePositions(this.positions);
}

@Override
public IIndentStream asJson(IIndentStream stream, Map<RelNode, Integer> idRemap) {
return stream.append("{").increase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public String toString() {
return this.getId() + " Last(" + this.relNode.getDigest() + ")";
}

@Override
public CalciteRelNode copy() {
return new LastRel(this.relNode, super.position).addSourcePositions(this.positions);
}

@Override
public IIndentStream asJson(IIndentStream stream, Map<RelNode, Integer> idRemap) {
return stream.append("{").increase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public class RelAnd extends CalciteRelNode {
final Set<LastRel> nodes;
SourcePositionRange position = SourcePositionRange.INVALID;

@Override
public CalciteRelNode copy() {
RelAnd result = new RelAnd();
for (var last: this.nodes)
result.add(last);
return result.addSourcePositions(this.positions);
}

public RelAnd() {
this.nodes = new HashSet<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public RelSequence(List<CalciteRelNode> nodes) {
this.nodes = toUse;
}

@Override
public CalciteRelNode copy() {
return new RelSequence(this.nodes).addSourcePositions(this.positions);
}

@Override
public IIndentStream asJson(IIndentStream stream, Map<RelNode, Integer> idRemap) {
stream.append("{").increase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,7 @@ public void postorder(DBSPWindowOperator operator) {
List<OutputPort> sources = Linq.map(operator.inputs, this::mapped);
DBSPSimpleOperator result = operator;
if (Linq.different(sources, operator.inputs))
result = new DBSPWindowOperator(operator.getRelNode(), operator.getFunctionNode(),
operator.lowerInclusive, operator.upperInclusive,
result = new DBSPWindowOperator(operator.getRelNode(), operator.lowerInclusive, operator.upperInclusive,
sources.get(0), sources.get(1))
.copyAnnotations(operator);
this.map(operator, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ToJsonVisitor extends CircuitVisitor {
final Map<RelNode, Integer> relId;

public static class FindSourcePositions extends InnerVisitor {
private final Set<SourcePositionRange> positions;
public final Set<SourcePositionRange> positions;
private final boolean reset;

public FindSourcePositions(DBSPCompiler compiler, boolean reset) {
Expand Down Expand Up @@ -88,7 +88,7 @@ public ToJsonVisitor(DBSPCompiler compiler, IIndentStream builder, int verbosity
SourcePositionRanges getPositions(DBSPOperator operator) {
FindSourcePositions positions = new FindSourcePositions(this.compiler, true);
operator.accept(positions);
positions.positions.add(operator.getSourcePosition());
positions.positions.addAll(operator.getSourcePositions());
return positions.getPositions();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ public void postorder(DBSPSourceMultisetOperator operator) {
fields.get(0).getType(), dataType), true, replacement.getOutput(0));
this.addOperator(ix);
DBSPWindowOperator window = new DBSPWindowOperator(
operator.getRelNode(), t.getNode(),true, true, ix.outputPort(), apply.outputPort());
operator.getRelNode(), true, true, ix.outputPort(), apply.outputPort());
this.addOperator(window);
replacement = new DBSPDeindexOperator(operator.getRelNode(), operator.getNode(), window.outputPort());
}
Expand Down Expand Up @@ -2096,7 +2096,7 @@ public void postorder(DBSPSinkOperator operator) {
this.addOperator(ix);
// The upper bound must be exclusive
DBSPWindowOperator window = new DBSPWindowOperator(
operator.getRelNode(), t.getNode(), true, false, ix.outputPort(), apply.outputPort());
operator.getRelNode(), true, false, ix.outputPort(), apply.outputPort());
this.addOperator(window);
// GC for window: the waterline delayed
PartiallyMonotoneTuple projection = new PartiallyMonotoneTuple(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.dbsp.sqlCompiler.compiler.visitors.inner.ReferenceMap;
import org.dbsp.sqlCompiler.compiler.visitors.inner.ResolveReferences;
import org.dbsp.sqlCompiler.compiler.visitors.outer.CircuitCloneVisitor;
import org.dbsp.sqlCompiler.compiler.visitors.outer.ToJsonVisitor;
import org.dbsp.sqlCompiler.compiler.visitors.outer.monotonicity.InsertLimiters;
import org.dbsp.sqlCompiler.ir.DBSPParameter;
import org.dbsp.sqlCompiler.ir.IDBSPDeclaration;
Expand Down Expand Up @@ -318,6 +319,7 @@ DBSPSimpleOperator implementTemporalFilter(DBSPFilterOperator operator,
DBSPSimpleOperator source,
TemporalFilterList comparisons) {
// Now input comes from here
CalciteRelNode relNode = operator.getRelNode();
DBSPSimpleOperator scalarNow = this.scalarNow();
WindowBounds bounds = comparisons.getWindowBounds(this.compiler());
DBSPClosureExpression makeWindow = bounds.makeWindow();
Expand All @@ -333,7 +335,7 @@ DBSPSimpleOperator implementTemporalFilter(DBSPFilterOperator operator,
if (bounds.common().getType().mayBeNull) {
DBSPClosureExpression nonNull =
bounds.common().is_null().not().closure(param);
DBSPFilterOperator filter = new DBSPFilterOperator(operator.getRelNode(), nonNull, source.outputPort());
DBSPFilterOperator filter = new DBSPFilterOperator(relNode, nonNull, source.outputPort());
this.addOperator(filter);
source = filter;
}
Expand All @@ -352,19 +354,22 @@ DBSPSimpleOperator implementTemporalFilter(DBSPFilterOperator operator,
this.addOperator(index);

// Apply window function. Operator is incremental, so add D & I around it
DBSPDifferentiateOperator diffIndex = new DBSPDifferentiateOperator(operator.getRelNode(), index.outputPort());
DBSPDifferentiateOperator diffIndex = new DBSPDifferentiateOperator(relNode, index.outputPort());
this.addOperator(diffIndex);
boolean lowerInclusive = bounds.lower() == null || bounds.lower().inclusive();
boolean upperInclusive = bounds.upper() == null || bounds.upper().inclusive();
CalciteRelNode windowNode = relNode.copy();
ToJsonVisitor.FindSourcePositions finder = new ToJsonVisitor.FindSourcePositions(this.compiler, false);
finder.apply(makeWindow);
windowNode.addSourcePositions(finder.positions);
DBSPSimpleOperator window = new DBSPWindowOperator(
operator.getRelNode(), makeWindow.getNode(),
lowerInclusive, upperInclusive, diffIndex.outputPort(), windowBounds.outputPort());
windowNode, lowerInclusive, upperInclusive, diffIndex.outputPort(), windowBounds.outputPort());
this.addOperator(window);
DBSPSimpleOperator winInt = new DBSPIntegrateOperator(operator.getRelNode(), window.outputPort());
DBSPSimpleOperator winInt = new DBSPIntegrateOperator(relNode, window.outputPort());
this.addOperator(winInt);

// Deindex result of window
DBSPSimpleOperator deindex = new DBSPDeindexOperator(operator.getRelNode(), window.getFunctionNode(),
DBSPSimpleOperator deindex = new DBSPDeindexOperator(relNode, window.getFunctionNode(),
winInt.outputPort());
this.addOperator(deindex);
return deindex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public void postorder(DBSPMapIndexOperator operator) {
this.addOperator(pre);

DBSPWindowOperator newWindow = new DBSPWindowOperator(
window.getRelNode(), window.getFunctionNode(),
window.lowerInclusive, window.upperInclusive, pre.outputPort(), window.right());
window.getRelNode(), window.lowerInclusive, window.upperInclusive, pre.outputPort(), window.right());
newWindow.setDerivedFrom(window);
this.addOperator(newWindow);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,33 @@ public void lineageTest() throws SQLException, IOException {
}
}

@Test
public void windowPositionTest() throws SQLException, IOException {
// Check that the window operator carries position information
String sql = """
CREATE TABLE T(x TIMESTAMP);
CREATE VIEW V AS SELECT * FROM T WHERE x < NOW() - INTERVAL 1 MINUTE;
""";
File file = createInputScript(sql);
File json = this.createTempJsonFile();
CompilerMain.execute("--dataflow", json.getPath(), "--noRust", file.getPath());
ObjectMapper mapper = Utilities.deterministicObjectMapper();
JsonNode parsed = mapper.readTree(json);
ObjectNode df = (ObjectNode)parsed.get("mir");
boolean found = false;
for (var prop: df.properties()) {
var node = prop.getValue();
JsonNode op = node.get("operation");
if (op != null && op.isTextual() && op.asText().equalsIgnoreCase("window")) {
found = true;
Assert.assertTrue(node.get("positions").isArray());
// At least one position exists
Assert.assertTrue(node.get("positions").elements().hasNext());
}
}
Assert.assertTrue(found);
}

@Test
public void issue3341() {
String sql = """
Expand Down
Loading
Loading