Skip to content

Commit

Permalink
Fix count column family (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmafo authored Apr 12, 2021
1 parent 3436e30 commit 4ea787a
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,25 @@ private Aggregation createAggregationEntry(AggregationExpression aggregationExpr
}

private double getDouble(BigtableCell cell) {
if (valueConverter.isNumberCellDefinition(cell)) {
return ((Number)valueConverter.convert(cell)).doubleValue();
} else {
return 0;
}
return valueConverter.isNumberCellDefinition(cell) ? ((Number)valueConverter.convert(cell)).doubleValue() : 0;
}

private boolean matches(@NotNull Field field, @NotNull RowCell cell) {
return field.isAsterisk() || (field.hasQualifier()
&& cell.getFamily().equalsIgnoreCase(field.getFamily())
&& cell.getQualifier().toStringUtf8().equalsIgnoreCase(field.getQualifier()));
if (field.isAsterisk()) {
return true;
}

return field.hasQualifier()
? matchesFamily(field, cell) && matchesQualifier(field, cell)
: matchesFamily(field, cell);
}

private boolean matchesFamily(@NotNull Field field, @NotNull RowCell cell) {
return cell.getFamily().equalsIgnoreCase(field.getFamily());
}

private boolean matchesQualifier(@NotNull Field field, @NotNull RowCell cell) {
return cell.getQualifier().toStringUtf8().equalsIgnoreCase(field.getQualifier());
}

private List<BigtableCell> getBigtableCells(@NotNull Row row) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/erikmafo/btviewer/sql/Field.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.erikmafo.btviewer.sql;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class Field {
Expand Down Expand Up @@ -64,6 +67,8 @@ public int hashCode() {
return Objects.hash(name);
}

@NotNull
@Contract(pure = true)
private String[] getFamilyAndQualifier() {
return name.split("\\.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.erikmafo.btviewer.sql.Field;
import com.erikmafo.btviewer.sql.SqlToken;
import org.jetbrains.annotations.NotNull;

/**
* Represents an aggregation of a field in a sql query.
Expand All @@ -26,7 +27,7 @@ public enum Type {
* @return an {@link AggregationExpression}
* @throws IllegalArgumentException if the sql token cannot be evaluated into an AggregationExpression.
*/
public static AggregationExpression from(SqlToken token) {
public static AggregationExpression from(@NotNull SqlToken token) {
return AggregationExpressionParser.parse(token.getSubTokens());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;
import java.nio.file.Path;
Expand Down Expand Up @@ -58,7 +59,7 @@ private void displaySpecifyCredentialsDialog(Path currentPath) {
.whenComplete(this::onCredentialsPathDialogComplete);
}

private void onCredentialsPathDialogComplete(Path path, Throwable throwable) {
private void onCredentialsPathDialogComplete(@Nullable Path path, @Nullable Throwable throwable) {
if (throwable != null) {
displayError(throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.control.TextField;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.CompletableFuture;

Expand All @@ -30,7 +31,7 @@ public static CompletableFuture<BigtableInstance> displayAndAwaitResult() {
}

@NotNull
public static CompletableFuture<BigtableInstance> displayAndAwaitResult(String projectId) {
public static CompletableFuture<BigtableInstance> displayAndAwaitResult(@Nullable String projectId) {
CompletableFuture<BigtableInstance> future = new CompletableFuture<>();

Dialog<BigtableInstance> dialog = new Dialog<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

public class InstanceTreeItem extends TreeItem<TreeItemData> {

@NotNull
private final ListTablesService listTablesService;
private boolean loadedChildren;

@Inject
public InstanceTreeItem(ListTablesService listTablesService) {
public InstanceTreeItem(@NotNull ListTablesService listTablesService) {
this.listTablesService = listTablesService;
this.expandedProperty().addListener((observable, prev, isExpanded) -> {
if (isExpanded && !loadedChildren && !listTablesService.isRunning()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;

Expand All @@ -31,7 +32,9 @@ public class ProjectExplorerController {

private final Provider<RootTreeItem> rootTreeItemProvider;

@NotNull
private final SimpleObjectProperty<BigtableTable> selectedTableProperty;
@NotNull
private final SimpleObjectProperty<BigtableInstance> selectedInstanceProperty;

private final SaveInstanceService saveInstanceService;
Expand All @@ -55,7 +58,7 @@ public void initialize() {

treeView.setCellFactory(tableInfoTreeView -> new TreeCell<>() {
@Override
protected void updateItem(TreeItemData item, boolean empty) {
protected void updateItem(@Nullable TreeItemData item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
Expand Down Expand Up @@ -91,14 +94,17 @@ protected void updateItem(TreeItemData item, boolean empty) {
addInstanceButton.setOnAction(this::handleAddInstanceAction);
}

@NotNull
public ReadOnlyObjectProperty<BigtableInstance> selectedInstanceProperty() {
return selectedInstanceProperty;
}

@NotNull
public ReadOnlyObjectProperty<BigtableTable> selectedTableProperty() {
return selectedTableProperty;
}

@Nullable
public ContextMenu createContextMenu(@NotNull TreeItemData item){
ContextMenu menu = null;
if (item.isProject()) {
Expand Down Expand Up @@ -129,7 +135,7 @@ private void handleAddInstanceAction(ActionEvent ignore) {
AddInstanceDialog.displayAndAwaitResult().whenComplete(this::handleAddInstanceResult);
}

private void handleAddInstanceResult(BigtableInstance instance, Throwable throwable) {
private void handleAddInstanceResult(@Nullable BigtableInstance instance, Throwable throwable) {
if (instance == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

public class ProjectTreeItem extends TreeItem<TreeItemData> {

@NotNull
private final LoadInstancesService loadInstancesService;
private final Provider<InstanceTreeItem> instanceTreeItemProvider;

private boolean loadedChildren;

@Inject
public ProjectTreeItem(LoadInstancesService loadInstancesService,
public ProjectTreeItem(@NotNull LoadInstancesService loadInstancesService,
Provider<InstanceTreeItem> instanceTreeItemProvider) {
this.loadInstancesService = loadInstancesService;
this.instanceTreeItemProvider = instanceTreeItemProvider;
Expand Down Expand Up @@ -53,7 +54,7 @@ private void onLoadInstancesSucceeded(WorkerStateEvent event) {
}

@NotNull
private InstanceTreeItem createChild(TreeItemData treeItemData) {
private InstanceTreeItem createChild(@NotNull TreeItemData treeItemData) {
var instanceItem = instanceTreeItemProvider.get();
instanceItem.setValue(treeItemData);
treeItemData.setTreeItem(instanceItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

public class RootTreeItem extends TreeItem<TreeItemData> {

@NotNull
private final LoadProjectsService loadProjectsService;
private final Provider<ProjectTreeItem> projectTreeItemProvider;

@Inject
public RootTreeItem(
LoadProjectsService loadProjectsService,
@NotNull LoadProjectsService loadProjectsService,
Provider<ProjectTreeItem> projectTreeItemProvider) {
this.projectTreeItemProvider = projectTreeItemProvider;
this.loadProjectsService = loadProjectsService;
Expand Down Expand Up @@ -44,7 +45,7 @@ public boolean isLeaf() {
return false;
}

private void loadChildren(LoadProjectsService loadProjectsService) {
private void loadChildren(@NotNull LoadProjectsService loadProjectsService) {
this.loadProjectsService.setOnSucceeded(event -> {
var children = loadProjectsService
.getValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.TreeItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

Expand Down Expand Up @@ -74,10 +75,12 @@ public String getDisplayName() {
return displayName;
}

@NotNull
public BigtableTable toTable() {
return new BigtableTable(projectId, instanceId, tableId);
}

@NotNull
public BigtableInstance toInstance() {
return new BigtableInstance(projectId, instanceId);
}
Expand All @@ -91,7 +94,7 @@ public String getInstanceId() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Expand All @@ -114,6 +117,7 @@ public boolean isLoading() {
return loading.get();
}

@NotNull
public BooleanProperty loadingProperty() {
return loading;
}
Expand All @@ -126,6 +130,7 @@ public TreeItem<TreeItemData> getTreeItem() {
return treeItem.get();
}

@NotNull
public ObjectProperty<TreeItem<TreeItemData>> treeItemProperty() {
return treeItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ public void initialize() {
bigtableQueryService.runningProperty().addListener((obs, wasRunning, isRunning) -> updateTimer(isRunning));
}

@NotNull
public ObjectProperty<BigtableTable> tableProperty() { return table; }

@NotNull
public ObservableList<QueryResultRow> getQueryResult() { return queryResult; }

public void setQuery(String sql) {
codeArea.clear();
codeArea.replaceText(0, 0, sql);
}

@NotNull
public ObjectProperty<BigtableInstance> instanceProperty() {
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SyntaxHighlightingUtil {
private static final String FUNCTION_STYLE_CLASS = "function";
private static final String OPERATOR_STYLE_CLASS = "logical-operator";

public static StyleSpans<Collection<String>> computeSyntaxHighlighting(String queryText) {
public static StyleSpans<Collection<String>> computeSyntaxHighlighting(@NotNull String queryText) {
var sqlTokenizer = new SqlTokenizer(queryText);
var token = sqlTokenizer.next();
int lastHighlightEnd = 0;
Expand All @@ -35,7 +35,7 @@ public static StyleSpans<Collection<String>> computeSyntaxHighlighting(String qu
return spansBuilder.create();
}

private static int applyStyleClass(SqlToken token, int lastHighlightEnd, StyleSpansBuilder<Collection<String>> spansBuilder) {
private static int applyStyleClass(@NotNull SqlToken token, int lastHighlightEnd, @NotNull StyleSpansBuilder<Collection<String>> spansBuilder) {
var styleClass = getStyleClass(token);
if (styleClass != null) {
spansBuilder.add(Collections.emptyList(), token.getStart() - lastHighlightEnd);
Expand All @@ -46,7 +46,7 @@ private static int applyStyleClass(SqlToken token, int lastHighlightEnd, StyleSp
}

@NotNull
private static List<SqlToken> getTokenAndSubTokens(SqlToken token) {
private static List<SqlToken> getTokenAndSubTokens(@NotNull SqlToken token) {
var tokens = new ArrayList<SqlToken>();
tokens.add(token);
if (token.getSubTokens() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import org.jetbrains.annotations.NotNull;

import java.time.Instant;
import java.time.ZoneId;
Expand Down Expand Up @@ -53,10 +54,12 @@ public boolean getDisplayTimestamp() {
return displayTimestamp.get();
}

@NotNull
public BooleanProperty displayTimestampProperty() {
return displayTimestamp;
}

@NotNull
public ObjectProperty<BigtableValueConverter> valueConverterProperty() { return valueConverter; }

private String getDisplayValue() {
Expand Down
Loading

0 comments on commit 4ea787a

Please sign in to comment.