Skip to content

Commit

Permalink
style: add spotless (#88)
Browse files Browse the repository at this point in the history
* style: add spotless

* chore: fix snyk
  • Loading branch information
aaron-steinfeld authored Oct 1, 2021
1 parent 895ba1b commit c56ccad
Show file tree
Hide file tree
Showing 34 changed files with 1,276 additions and 844 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ The Query Service interfaces with Apache Pinot Data Store

## Description

| ![space-1.jpg](https://hypertrace-docs.s3.amazonaws.com/arch/ht-query.png) |
|:--:|
| ![space-1.jpg](https://hypertrace-docs.s3.amazonaws.com/arch/ht-query.png) |
|:--:|
| *Hypertrace Query Architecture* |

- Query Service serves time series data for attributes/metrics from spans and events. The query interface this exposes is more like a table where you can select any columns, aggregations on them with filters. It's easy to do slicing and dicing of data (only from one table since no JOINs are supported) with this interface.
Expand All @@ -20,7 +20,7 @@ The Query service uses gradlew to compile/install/distribute. Gradle wrapper is
## Testing

### Running unit tests
Run `./gradlew test` to execute unit tests.
Run `./gradlew test` to execute unit tests.


### Testing image
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ plugins {
id("org.hypertrace.publish-plugin") version "1.0.2" apply false
id("org.hypertrace.jacoco-report-plugin") version "0.2.0" apply false
id("org.hypertrace.integration-test-plugin") version "0.2.0" apply false
id("org.hypertrace.code-style-plugin") version "1.1.1" apply false
}

subprojects {
group = "org.hypertrace.core.query.service"
apply(plugin = "org.hypertrace.code-style-plugin")
pluginManager.withPlugin("org.hypertrace.publish-plugin") {
configure<org.hypertrace.gradle.publishing.HypertracePublishExtension> {
license.set(org.hypertrace.gradle.publishing.License.TRACEABLE_COMMUNITY)
Expand Down
7 changes: 6 additions & 1 deletion query-service-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import com.google.protobuf.gradle.*
import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.id
import com.google.protobuf.gradle.ofSourceSet
import com.google.protobuf.gradle.plugins
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc

plugins {
`java-library`
Expand Down
2 changes: 0 additions & 2 deletions query-service-api/src/main/proto/request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,3 @@ enum SortOrder {
ASC = 0;
DESC = 1;
}


1 change: 0 additions & 1 deletion query-service-api/src/main/proto/response.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ message ResultSetChunk {
message Row {
repeated Value column = 1;
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,35 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link QueryRequest}
*/
/** Unit tests for {@link QueryRequest} */
public class QueryRequestTest {
@Test
public void testJsonSerializeDeserialize() throws InvalidProtocolBufferException {
QueryRequest.Builder builder = QueryRequest.newBuilder()
.addSelection(Expression.newBuilder().setColumnIdentifier(
ColumnIdentifier.newBuilder().setColumnName("test").setAlias("my_column").build()))
.addAggregation(Expression.newBuilder().setFunction(
Function.newBuilder().setFunctionName("SUM").build()))
.addGroupBy(Expression.newBuilder().setColumnIdentifier(
ColumnIdentifier.newBuilder().setColumnName("test").build()))
.addOrderBy(OrderByExpression.newBuilder().setOrderValue(-1).setExpression(
Expression.newBuilder().setColumnIdentifier(
ColumnIdentifier.newBuilder().setColumnName("column2"))))
.setOffset(0).setLimit(1);
QueryRequest.Builder builder =
QueryRequest.newBuilder()
.addSelection(
Expression.newBuilder()
.setColumnIdentifier(
ColumnIdentifier.newBuilder()
.setColumnName("test")
.setAlias("my_column")
.build()))
.addAggregation(
Expression.newBuilder()
.setFunction(Function.newBuilder().setFunctionName("SUM").build()))
.addGroupBy(
Expression.newBuilder()
.setColumnIdentifier(
ColumnIdentifier.newBuilder().setColumnName("test").build()))
.addOrderBy(
OrderByExpression.newBuilder()
.setOrderValue(-1)
.setExpression(
Expression.newBuilder()
.setColumnIdentifier(
ColumnIdentifier.newBuilder().setColumnName("column2"))))
.setOffset(0)
.setLimit(1);

QueryRequest request = builder.build();
// Serialize into json.
Expand Down
4 changes: 2 additions & 2 deletions query-service-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ dependencies {
implementation("org.apache.zookeeper:zookeeper:3.6.2") {
because("Multiple vulnerabilities")
}
implementation("io.netty:netty-transport-native-epoll:4.1.63.Final") {
implementation("io.netty:netty-transport-native-epoll:4.1.68.Final") {
because("Multiple vulnerabilities")
}
implementation("io.netty:netty-handler:4.1.63.Final") {
implementation("io.netty:netty-handler:4.1.68.Final") {
because("Multiple vulnerabilities")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.hypertrace.core.query.service.api.ValueType;

/**
* Wrapper class to hold the query execution context that is needed by different components
* during the life cycles of a request.
* Wrapper class to hold the query execution context that is needed by different components during
* the life cycles of a request.
*/
public class ExecutionContext {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hypertrace.core.query.service;


/**
* Canonical query function names received in requests. These should be converted to data-store
* specific names when handling a request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import org.hypertrace.core.query.service.api.QueryRequest;

public interface QueryTransformation {
Single<QueryRequest> transform(QueryRequest queryRequest, QueryTransformationContext transformationContext);
Single<QueryRequest> transform(
QueryRequest queryRequest, QueryTransformationContext transformationContext);

interface QueryTransformationContext {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public class RequestHandlerInfo {
private final Config config;

public RequestHandlerInfo(
String name,
Class<? extends RequestHandler> requestHandlerClazz,
Config config) {
String name, Class<? extends RequestHandler> requestHandlerClazz, Config config) {
this.name = name;
this.requestHandlerClazz = requestHandlerClazz;
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ public Map<Integer, ByteString> getByteStringParams() {

@Override
public String toString() {
return "Params{" +
"integerParams=" + integerParams +
", longParams=" + longParams +
", stringParams=" + stringParams +
", floatParams=" + floatParams +
", doubleParams=" + doubleParams +
", byteStringParams=" + byteStringParams +
'}';
return "Params{"
+ "integerParams="
+ integerParams
+ ", longParams="
+ longParams
+ ", stringParams="
+ stringParams
+ ", floatParams="
+ floatParams
+ ", doubleParams="
+ doubleParams
+ ", byteStringParams="
+ byteStringParams
+ '}';
}

@Override
Expand Down Expand Up @@ -164,8 +170,8 @@ public Builder addByteStringParam(ByteString paramValue) {
}

public Params build() {
return new Params(integerParams, longParams, stringParams, floatParams, doubleParams,
byteStringParams);
return new Params(
integerParams, longParams, stringParams, floatParams, doubleParams, byteStringParams);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ public QueryCost canHandle(QueryRequest request, ExecutionContext executionConte
return QueryCost.UNSUPPORTED;
}

// TODO
// if (!this.viewDefinitionSupportsGranularity(viewDefinition, request.getGroupByList())) {
// return QueryCost.UNSUPPORTED;
// }
// TODO
// if (!this.viewDefinitionSupportsGranularity(viewDefinition, request.getGroupByList())) {
// return QueryCost.UNSUPPORTED;
// }

double cost;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class PinotClientFactory {

private final ConcurrentHashMap<String, PinotClient> clientMap = new ConcurrentHashMap<>();

private PinotClientFactory() {
}
private PinotClientFactory() {}

// Create a Pinot Client.
public static PinotClient createPinotClient(String pinotCluster, String pathType, String path) {
Expand Down Expand Up @@ -104,7 +103,8 @@ private PreparedStatement buildPreparedStatement(String statement, Params params
params.getLongParams().forEach(preparedStatement::setLong);
params.getDoubleParams().forEach(preparedStatement::setDouble);
params.getFloatParams().forEach(preparedStatement::setFloat);
params.getByteStringParams()
params
.getByteStringParams()
.forEach((i, b) -> preparedStatement.setString(i, Hex.encodeHexString(b.toByteArray())));
return preparedStatement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import org.hypertrace.core.query.service.RequestHandlerClientConfigRegistry;
import org.hypertrace.core.query.service.RequestHandlerBuilder;
import org.hypertrace.core.query.service.RequestHandlerClientConfigRegistry;

public class PinotModule extends AbstractModule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import javax.inject.Inject;
import org.hypertrace.core.query.service.QueryServiceConfig.RequestHandlerClientConfig;
import org.hypertrace.core.query.service.QueryServiceConfig.RequestHandlerConfig;
import org.hypertrace.core.query.service.RequestHandlerClientConfigRegistry;
import org.hypertrace.core.query.service.RequestHandler;
import org.hypertrace.core.query.service.RequestHandlerBuilder;
import org.hypertrace.core.query.service.RequestHandlerClientConfigRegistry;

public class PinotRequestHandlerBuilder implements RequestHandlerBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Converts {@link QueryRequest} to Pinot SQL query
*/
/** Converts {@link QueryRequest} to Pinot SQL query */
class QueryRequestToPinotSQLConverter {

private static final Logger LOG = LoggerFactory.getLogger(QueryRequestToPinotSQLConverter.class);
Expand Down Expand Up @@ -201,9 +199,12 @@ private Expression handleValueConversionForLiteralExpression(Expression lhs, Exp

String lhsColumnName = lhs.getColumnIdentifier().getColumnName();
try {
Value value = DestinationColumnValueConverter.INSTANCE.convert(rhs.getLiteral().getValue(),
viewDefinition.getColumnType(lhsColumnName));
return Expression.newBuilder().setLiteral(LiteralConstant.newBuilder().setValue(value)).build();
Value value =
DestinationColumnValueConverter.INSTANCE.convert(
rhs.getLiteral().getValue(), viewDefinition.getColumnType(lhsColumnName));
return Expression.newBuilder()
.setLiteral(LiteralConstant.newBuilder().setValue(value))
.build();
} catch (Exception e) {
throw new IllegalArgumentException(
String.format(
Expand Down Expand Up @@ -326,9 +327,7 @@ private LiteralConstant[] convertExpressionToMapLiterals(Expression expression)
return literals;
}

/**
* TODO:Handle all types
*/
/** TODO:Handle all types */
private String convertLiteralToString(LiteralConstant literal, Params.Builder paramsBuilder) {
Value value = literal.getValue();
String ret = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hypertrace.core.query.service.pinot;

import com.typesafe.config.Config;
import java.util.HashSet;
import java.util.Set;

/**
Expand All @@ -10,27 +9,18 @@
* The main view and filtered view can be optimized different for queries and only the queries
* matching the view filters will be routed to the filtered view.
*
* <p>Currently, we only support EQ and IN operators in these filters.</p>
* Example EQ filter:
* {
* column: "EVENT.isEntrySpan"
* operator: "EQ"
* value: "true"
* }
* <p>Currently, we only support EQ and IN operators in these filters. Example EQ filter: { column:
* "EVENT.isEntrySpan" operator: "EQ" value: "true" }
*
* Example IN filter:
* {
* column: "EVENT.statusCode"
* operator: "IN"
* values: ["500", "401"]
* }
* <p>Example IN filter: { column: "EVENT.statusCode" operator: "IN" values: ["500", "401"] }
*/
class ViewColumnFilter {
private final Operator operator;
private final Set<String> values;

enum Operator {
IN, EQ
IN,
EQ
}

public ViewColumnFilter(Operator operator, Set<String> values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
public class DestinationColumnValueConverter {
private static final Logger LOG = LoggerFactory.getLogger(DestinationColumnValueConverter.class);

public static final DestinationColumnValueConverter INSTANCE = new DestinationColumnValueConverter();
public static final DestinationColumnValueConverter INSTANCE =
new DestinationColumnValueConverter();
private static final String EMPTY = "";

private DestinationColumnValueConverter() {
}
private DestinationColumnValueConverter() {}

public Value convert(Value value, ValueType valueType) throws Exception {
// Currently, only Pinot's BYTES columns needs transformation since they're actually
Expand Down Expand Up @@ -47,16 +47,23 @@ public Value convert(Value value, ValueType valueType) throws Exception {
return valueBuilder.build();

default:
String msg = String.format("Unsupported value of type: %s while transforming to BYTES.",
value.getValueType().name());
String msg =
String.format(
"Unsupported value of type: %s while transforming to BYTES.",
value.getValueType().name());
LOG.warn(msg);
throw new IllegalArgumentException(msg);
}
}

private ByteString convertToByteString(String inValue) throws DecoderException {
String outValue = (Strings.isNullOrEmpty(inValue) || inValue.trim().equals("null") ||
inValue.trim().equals("''") || inValue.trim().equals("{}")) ? EMPTY : inValue;
String outValue =
(Strings.isNullOrEmpty(inValue)
|| inValue.trim().equals("null")
|| inValue.trim().equals("''")
|| inValue.trim().equals("{}"))
? EMPTY
: inValue;
byte[] bytes = Hex.decodeHex(outValue);
return ByteString.copyFrom(bytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public void setup() {
appConfig =
ConfigFactory.parseURL(
requireNonNull(
QueryServiceConfigTest.class
.getClassLoader()
.getResource("application.conf")));
QueryServiceConfigTest.class.getClassLoader().getResource("application.conf")));
queryServiceConfig = new QueryServiceConfig(appConfig.getConfig("service.config"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public void testValidNullFieldsForBytesColumn() throws Exception {
@Test
public void testInValidNullFieldsForBytesColumn() {
DestinationColumnValueConverter converter = DestinationColumnValueConverter.INSTANCE;
Assertions.assertThrows(DecoderException.class, () -> {
converter.convert(getStringValue("abc"), ValueType.BYTES);
});
Assertions.assertThrows(
DecoderException.class,
() -> {
converter.convert(getStringValue("abc"), ValueType.BYTES);
});
}
}
Loading

0 comments on commit c56ccad

Please sign in to comment.