Skip to content

Fixed plan tab, added some docs #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2017
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
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [Canvas](console/graph/canvas.md)
* [Table](console/table.md)
* [Parameters](console/parameters.md)
* [Plan](console/plan.md)
* [Cypher](cypher/index.md)
* [Syntax](cypher/syntax.md)
* [Autocompletion](cypher/autocompletion.md)
Expand Down
11 changes: 11 additions & 0 deletions docs/console/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Console - Plan

When any `EXPLAIN` or `PROFILE` queries are executed, plugin creates a closeable tab in console, which contains the plan
of query, rendered as tree table.

![EXPLAIN plan](../screenshots/explain_plan.png)

The plan tab consists of label with an executed query, tree table with plan and label with metadata.
Note, that `PROFILE` plan table has more columns, because the query is actually executed.

![PROFILE plan](../screenshots/profile_plan.png)
12 changes: 11 additions & 1 deletion docs/cypher/inspections.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@

### EXPLAIN warnings

TODO
Graph database plugin provides a functionality to automatically find any problems with your queries,
using `EXPLAIN` queries. Then, all database notifications are displayed as warnings, highlighting problematic parts of
query.

![explain warning screenshot](../screenshots/explain_warning.png)

Under the hood, IntelliJ platform launches inspection for a query without syntax errors, inspection prepends to the
query an `EXPLAIN` keyword and executes it against the active data-source silently.
After all results have been received, database notifications are displayed as warnings.

Inspection is enabled by default, but you can disable it at any time.
Binary file added docs/screenshots/explain_plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/explain_warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/profile_plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.plan;

import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.treeStructure.treetable.TreeTableModel;
import com.intellij.util.ui.ColumnInfo;
import com.neueda.jetbrains.plugin.graphdb.database.api.query.GraphQueryPlan;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.tree.DefaultMutableTreeNode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
Expand All @@ -19,23 +23,25 @@ class ColumnDefinitions {
static ColumnInfo[] getQueryPlanColumns() {
return new ColumnInfo[]{
OPERATOR_COL,
ESTIMATED_ROWS_COL,
ARGUMENTS_COL,
ESTIMATED_ROWS_COL,
IDENTIFIERS_COL
};
}

static ColumnInfo[] getProfileQueryPlanColumns() {
return new ColumnInfo[]{
OPERATOR_COL,
ARGUMENTS_COL,
ROWS_COL,
DB_HITS_COL,
ESTIMATED_ROWS_COL,
ARGUMENTS_COL,
IDENTIFIERS_COL
};
}

private static final NumberFormat FORMATTER = new DecimalFormat("#0.00");

private static final Set<String> RESERVED_KEYS = Stream.of(QueryPlanArgumentKeys.values())
.map(QueryPlanArgumentKeys::getKey)
.collect(toSet());
Expand All @@ -52,16 +58,22 @@ public Class<?> getColumnClass() {
public String valueOf(DefaultMutableTreeNode o) {
return ((GraphQueryPlan) o.getUserObject()).getOperatorType();
}

@Override
@NonNls
public String getPreferredStringValue() {
return StringUtil.repeatSymbol('m', 25);
}
};

private static final ColumnInfo<DefaultMutableTreeNode, String> ESTIMATED_ROWS_COL =
getArgumentColumn("Estimated rows", ESTIMATED_ROWS.getKey(), "0");
getArgumentColumn("Estimated rows", ESTIMATED_ROWS.getKey());

private static final ColumnInfo<DefaultMutableTreeNode, String> DB_HITS_COL =
getArgumentColumn("DB Hits", DB_HITS.getKey(), "0");
getArgumentColumn("DB Hits", DB_HITS.getKey());

private static final ColumnInfo<DefaultMutableTreeNode, String> ROWS_COL =
getArgumentColumn("Rows", ROWS.getKey(), "0");
getArgumentColumn("Rows", ROWS.getKey());

private static final ColumnInfo<DefaultMutableTreeNode, String> ARGUMENTS_COL =
new ColumnInfo<DefaultMutableTreeNode, String>("Arguments") {
Expand All @@ -74,6 +86,12 @@ public String valueOf(DefaultMutableTreeNode o) {
.map(Object::toString)
.collect(joining(", "));
}

@Override
@NonNls
public String getPreferredStringValue() {
return StringUtil.repeatSymbol('m', 15);
}
};

private static final ColumnInfo<DefaultMutableTreeNode, String> IDENTIFIERS_COL =
Expand All @@ -84,21 +102,38 @@ public String valueOf(DefaultMutableTreeNode o) {
return ((GraphQueryPlan) o.getUserObject()).getIdentifiers().stream()
.collect(joining(", "));
}

@Override
@NonNls
public String getPreferredStringValue() {
return StringUtil.repeatSymbol('m', 12);
}
};

@NotNull
private static <T> ColumnInfo<DefaultMutableTreeNode, T> getArgumentColumn(String title, String argumentKey,
T defaultValue) {
return new ColumnInfo<DefaultMutableTreeNode, T>(title) {
private static ColumnInfo<DefaultMutableTreeNode, String> getArgumentColumn(String title, String argumentKey) {
return new ColumnInfo<DefaultMutableTreeNode, String>(title) {
@Nullable
@Override
public T valueOf(DefaultMutableTreeNode o) {
public String valueOf(DefaultMutableTreeNode o) {
return ((GraphQueryPlan) o.getUserObject()).getArguments().entrySet().stream()
.filter(e -> e.getKey().equalsIgnoreCase(argumentKey))
.map(Map.Entry::getValue)
.findFirst()
.map(a -> (T) a)
.orElse(defaultValue);
.map(val -> {
if (val instanceof Double) {
return FORMATTER.format(val);
}

return val.toString();
})
.orElse("0");
}

@Override
@NonNls
public String getPreferredStringValue() {
return StringUtil.repeatSymbol('m', 5);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public void initialize(Container container) {
ListTreeTableModelOnColumns model = createModel(graphQueryPlan, result.isProfilePlan());

treeTable = new TreeTableView(model);
treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
treeTable.setAutoCreateColumnsFromModel(true);
treeTable.setRootVisible(true);
treeTable.setCellSelectionEnabled(false);
treeTable.setAutoResizeMode(TreeTableView.AUTO_RESIZE_OFF);

treeTable.getTree().setShowsRootHandles(true);

Expand All @@ -72,7 +72,8 @@ public void initialize(Container container) {

container.add(new JBScrollPane(queryLabel), BorderLayout.NORTH);
// scroll pane is needed to correctly fit all the tree content and to show table header
container.add(new JBScrollPane(treeTable), BorderLayout.CENTER);
container.add(new JBScrollPane(treeTable, JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JBScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
container.add(infoLabel, BorderLayout.SOUTH);
}

Expand Down