Skip to content
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

Fixes #196: Add support for in-operator. #197

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions src/main/java/com/erikmafo/btviewer/model/Aggregation.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.erikmafo.btviewer.model;

import com.erikmafo.btviewer.sql.functions.AggregationExpression;
import com.erikmafo.btviewer.sql.query.AggregationType;
import com.erikmafo.btviewer.util.Check;
import org.jetbrains.annotations.NotNull;

public class Aggregation {

private final AggregationExpression.Type type;
private final AggregationType type;
private final String fieldName;

private int count;
private double sum;

public Aggregation(AggregationExpression.Type type, String fieldName) {
public Aggregation(AggregationType type, String fieldName) {
Check.notNull(type, "type");
Check.notNullOrEmpty(fieldName, "fieldName");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.erikmafo.btviewer.model;

import com.erikmafo.btviewer.sql.ByteStringConverter;
import com.erikmafo.btviewer.sql.Field;
import com.erikmafo.btviewer.sql.Value;
import com.erikmafo.btviewer.sql.convert.FieldValueByteStringConverter;
import com.erikmafo.btviewer.sql.query.Field;
import com.erikmafo.btviewer.sql.query.Value;
import com.erikmafo.btviewer.util.ByteStringConverterUtil;
import com.google.protobuf.ByteString;
import org.jetbrains.annotations.NotNull;
Expand All @@ -11,19 +11,19 @@
import java.util.List;
import java.util.UUID;

public class ByteStringConverterImpl implements ByteStringConverter {
public class FieldValueByteStringConverterImpl implements FieldValueByteStringConverter {
private final List<CellDefinition> cellDefinitions;

public ByteStringConverterImpl(@NotNull BigtableTableSettings config) {
public FieldValueByteStringConverterImpl(@NotNull BigtableTableSettings config) {
this(config.getCellDefinitions() != null ? config.getCellDefinitions() : Collections.emptyList());
}

public ByteStringConverterImpl(List<CellDefinition> cellDefinitions) {
public FieldValueByteStringConverterImpl(List<CellDefinition> cellDefinitions) {
this.cellDefinitions = cellDefinitions;
}

@Override
public ByteString toByteString(@NotNull Field field, Value value) {
public ByteString convert(@NotNull Field field, Value value) {
var valueType = CellDefinitionMatcherUtil
.findBestMatch(cellDefinitions, new BigtableColumn(field.getFamily(), field.getQualifier()))
.map(CellDefinition::getValueType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.erikmafo.btviewer.model.BigtableInstance;
import com.erikmafo.btviewer.model.BigtableTable;
import com.erikmafo.btviewer.model.BigtableValueConverter;
import com.erikmafo.btviewer.model.ByteStringConverterImpl;
import com.erikmafo.btviewer.model.FieldValueByteStringConverterImpl;
import com.erikmafo.btviewer.model.QueryResultRow;
import com.erikmafo.btviewer.services.internal.AppDataStorage;
import com.erikmafo.btviewer.services.internal.BigtableSettingsProvider;
import com.erikmafo.btviewer.sql.QueryConverter;
import com.erikmafo.btviewer.sql.SqlQuery;
import com.erikmafo.btviewer.sql.convert.QueryConverter;
import com.erikmafo.btviewer.sql.query.SqlQuery;
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
import javafx.concurrent.Service;
Expand Down Expand Up @@ -48,16 +48,16 @@ public BigtableQueryService(BigtableSettingsProvider settingsProvider, AppDataSt
protected Task<List<QueryResultRow>> createTask() {
var instance = this.instance;
var sqlQuery = this.query;
var tableId = sqlQuery.getTableName();
var tableId = sqlQuery.tableName();

return new Task<>() {

@Override
protected List<QueryResultRow> call() throws Exception {
var tableSettings = storage.getTableSettings(new BigtableTable(instance, tableId));
var queryConverter = new QueryConverter(sqlQuery, new ByteStringConverterImpl(tableSettings));
var queryConverter = new QueryConverter(new FieldValueByteStringConverterImpl(tableSettings));
var valueConverter = new BigtableValueConverter(tableSettings.getCellDefinitions());
var btQuery = queryConverter.toBigtableQuery();
var btQuery = queryConverter.convert(sqlQuery);
var rows = getOrCreateNewClient(instance).readRows(btQuery);
var rowStream = StreamSupport.stream(rows.spliterator(), true);
return new QueryResultConverter(sqlQuery, valueConverter).toQueryResultRows(rowStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.erikmafo.btviewer.model.BigtableCell;
import com.erikmafo.btviewer.model.BigtableValueConverter;
import com.erikmafo.btviewer.model.QueryResultRow;
import com.erikmafo.btviewer.sql.Field;
import com.erikmafo.btviewer.sql.SqlQuery;
import com.erikmafo.btviewer.sql.functions.AggregationExpression;
import com.erikmafo.btviewer.sql.query.Field;
import com.erikmafo.btviewer.sql.query.SqlQuery;
import com.erikmafo.btviewer.sql.query.AggregationExpression;
import com.google.cloud.bigtable.data.v2.models.Row;
import com.google.cloud.bigtable.data.v2.models.RowCell;
import org.jetbrains.annotations.Contract;
Expand Down Expand Up @@ -55,7 +55,7 @@ private List<QueryResultRow> aggregate(@NotNull Stream<Row> rowStream) {
.reduce(this::combineAggregationEntries)
.map(QueryResultRow::new)
.stream()
.limit(sqlQuery.getLimit())
.limit(sqlQuery.limit())
.collect(Collectors.toList());
}

Expand All @@ -82,11 +82,11 @@ private Aggregation[] combineAggregationEntries(@NotNull Aggregation[] first, @N

@NotNull
private Aggregation[] toAggregationEntries(@NotNull Row row) {
var noOfAggregations = sqlQuery.getAggregations().size();
var noOfAggregations = sqlQuery.aggregationExpressions().size();
var entries = new Aggregation[noOfAggregations];

for (var i=0; i < noOfAggregations; i++) {
entries[i] = createAggregationEntry(row, sqlQuery.getAggregations().get(i));
entries[i] = createAggregationEntry(row, sqlQuery.aggregationExpressions().get(i));
}

return entries;
Expand All @@ -102,9 +102,9 @@ private List<RowCell> getCells(Row row, @NotNull Field field) {

@NotNull
private Aggregation createAggregationEntry(@NotNull Row row, @NotNull AggregationExpression aggregationExpression) {
return getCells(row, aggregationExpression.getField())
return getCells(row, aggregationExpression.field())
.stream()
.filter(c -> matches(aggregationExpression.getField(), c))
.filter(c -> matches(aggregationExpression.field(), c))
.findFirst()
.map(rowCell -> createAggregationEntry(aggregationExpression, rowCell))
.orElseGet(() -> createAggregationEntry(aggregationExpression));
Expand All @@ -113,13 +113,13 @@ private Aggregation createAggregationEntry(@NotNull Row row, @NotNull Aggregatio
@Contract("_ -> new")
@NotNull
private Aggregation createAggregationEntry(@NotNull AggregationExpression aggregationExpression) {
return new Aggregation(aggregationExpression.getType(), aggregationExpression.getField().getName());
return new Aggregation(aggregationExpression.type(), aggregationExpression.field().name());
}

@NotNull
private Aggregation createAggregationEntry(AggregationExpression aggregationExpression, RowCell cell) {
var entry = createAggregationEntry(aggregationExpression);
switch (aggregationExpression.getType()) {
switch (aggregationExpression.type()) {
case AVG:
entry.setSum(getDouble(BigtableCell.from(cell)));
entry.setCount(1);
Expand All @@ -132,7 +132,7 @@ private Aggregation createAggregationEntry(AggregationExpression aggregationExpr
break;
default:
throw new IllegalArgumentException(
String.format("aggregation type: %s is not supported", aggregationExpression.getType()));
String.format("aggregation type: %s is not supported", aggregationExpression.type()));
}
return entry;
}
Expand Down
Loading