Skip to content

Commit a49cc35

Browse files
authored
chore: Refactor some minor issues in Java modules (#2787)
Signed-off-by: yanghua <yanghua1127@gmail.com>
1 parent 452dcd3 commit a49cc35

File tree

7 files changed

+30
-37
lines changed

7 files changed

+30
-37
lines changed

java/common/src/main/java/feast/common/logging/entry/MessageAuditLogEntry.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@
1919
import com.google.auto.value.AutoValue;
2020
import com.google.gson.Gson;
2121
import com.google.gson.GsonBuilder;
22-
import com.google.gson.JsonElement;
2322
import com.google.gson.JsonParser;
24-
import com.google.gson.JsonSerializationContext;
2523
import com.google.gson.JsonSerializer;
2624
import com.google.protobuf.Empty;
2725
import com.google.protobuf.InvalidProtocolBufferException;
2826
import com.google.protobuf.Message;
2927
import com.google.protobuf.util.JsonFormat;
3028
import io.grpc.Status.Code;
31-
import java.lang.reflect.Type;
3229
import java.util.UUID;
3330

3431
/** MessageAuditLogEntry records the handling of a Protobuf message by a service call. */
@@ -103,20 +100,17 @@ public String toJSON() {
103100
new GsonBuilder()
104101
.registerTypeAdapter(
105102
Message.class,
106-
new JsonSerializer<Message>() {
107-
@Override
108-
public JsonElement serialize(
109-
Message message, Type type, JsonSerializationContext context) {
110-
try {
111-
String messageJSON = JsonFormat.printer().print(message);
112-
return new JsonParser().parse(messageJSON);
113-
} catch (InvalidProtocolBufferException e) {
114-
115-
throw new RuntimeException(
116-
"Unexpected exception converting Protobuf to JSON", e);
117-
}
118-
}
119-
})
103+
(JsonSerializer<Message>)
104+
(message, type, context) -> {
105+
try {
106+
String messageJSON = JsonFormat.printer().print(message);
107+
return new JsonParser().parse(messageJSON);
108+
} catch (InvalidProtocolBufferException e) {
109+
110+
throw new RuntimeException(
111+
"Unexpected exception converting Protobuf to JSON", e);
112+
}
113+
})
120114
.create();
121115
return gson.toJson(this);
122116
}

java/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* GrpcMessageInterceptor assumes that all service calls are unary (ie single request/response).
3939
*/
4040
public class GrpcMessageInterceptor implements ServerInterceptor {
41-
private LoggingProperties loggingProperties;
41+
private final LoggingProperties loggingProperties;
4242

4343
/**
4444
* Construct GrpcMessageIntercetor.
@@ -78,7 +78,7 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(
7878

7979
// Register forwarding call to intercept outgoing response and log to audit log
8080
call =
81-
new SimpleForwardingServerCall<ReqT, RespT>(call) {
81+
new SimpleForwardingServerCall<>(call) {
8282
@Override
8383
public void sendMessage(RespT message) {
8484
// 2. Track the response & Log entry to audit logger
@@ -97,7 +97,7 @@ public void close(Status status, Metadata trailers) {
9797
};
9898

9999
ServerCall.Listener<ReqT> listener = next.startCall(call, headers);
100-
return new SimpleForwardingServerCallListener<ReqT>(listener) {
100+
return new SimpleForwardingServerCallListener<>(listener) {
101101
@Override
102102
// Register listener to intercept incoming request messages and log to audit log
103103
public void onMessage(ReqT message) {

java/sdk/src/main/java/dev/feast/RequestUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public static List<FeatureReferenceV2> createFeatureRefs(List<String> featureRef
3535
}
3636

3737
List<FeatureReferenceV2> featureRefs =
38-
featureRefStrings.stream()
39-
.map(refStr -> parseFeatureRef(refStr))
40-
.collect(Collectors.toList());
38+
featureRefStrings.stream().map(RequestUtil::parseFeatureRef).collect(Collectors.toList());
4139

4240
return featureRefs;
4341
}

java/serving/src/main/java/feast/serving/registry/LocalRegistryFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.Optional;
2525

2626
public class LocalRegistryFile implements RegistryFile {
27-
private RegistryProto.Registry cachedRegistry;
27+
private final RegistryProto.Registry cachedRegistry;
2828

2929
public LocalRegistryFile(String path) {
3030
try {

java/serving/src/main/java/feast/serving/registry/Registry.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package feast.serving.registry;
1818

1919
import feast.proto.core.*;
20+
import feast.proto.core.FeatureServiceProto.FeatureService;
21+
import feast.proto.core.FeatureViewProto.FeatureView;
22+
import feast.proto.core.OnDemandFeatureViewProto.OnDemandFeatureView;
2023
import feast.proto.serving.ServingAPIProto;
2124
import feast.serving.exception.SpecRetrievalException;
2225
import java.util.List;
@@ -26,24 +29,24 @@
2629

2730
public class Registry {
2831
private final RegistryProto.Registry registry;
29-
private Map<String, FeatureViewProto.FeatureViewSpec> featureViewNameToSpec;
32+
private final Map<String, FeatureViewProto.FeatureViewSpec> featureViewNameToSpec;
3033
private Map<String, OnDemandFeatureViewProto.OnDemandFeatureViewSpec>
3134
onDemandFeatureViewNameToSpec;
32-
private Map<String, FeatureServiceProto.FeatureServiceSpec> featureServiceNameToSpec;
35+
private final Map<String, FeatureServiceProto.FeatureServiceSpec> featureServiceNameToSpec;
3336

3437
Registry(RegistryProto.Registry registry) {
3538
this.registry = registry;
3639
List<FeatureViewProto.FeatureViewSpec> featureViewSpecs =
3740
registry.getFeatureViewsList().stream()
38-
.map(fv -> fv.getSpec())
41+
.map(FeatureView::getSpec)
3942
.collect(Collectors.toList());
4043
this.featureViewNameToSpec =
4144
featureViewSpecs.stream()
4245
.collect(
4346
Collectors.toMap(FeatureViewProto.FeatureViewSpec::getName, Function.identity()));
4447
List<OnDemandFeatureViewProto.OnDemandFeatureViewSpec> onDemandFeatureViewSpecs =
4548
registry.getOnDemandFeatureViewsList().stream()
46-
.map(odfv -> odfv.getSpec())
49+
.map(OnDemandFeatureView::getSpec)
4750
.collect(Collectors.toList());
4851
this.onDemandFeatureViewNameToSpec =
4952
onDemandFeatureViewSpecs.stream()
@@ -53,7 +56,7 @@ public class Registry {
5356
Function.identity()));
5457
this.featureServiceNameToSpec =
5558
registry.getFeatureServicesList().stream()
56-
.map(fs -> fs.getSpec())
59+
.map(FeatureService::getSpec)
5760
.collect(
5861
Collectors.toMap(
5962
FeatureServiceProto.FeatureServiceSpec::getName, Function.identity()));

java/serving/src/main/java/feast/serving/service/OnlineTransformationService.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ public void processTransformFeaturesResponse(
239239
} catch (IOException e) {
240240
log.info(e.toString());
241241
throw Status.INTERNAL
242-
.withDescription(
243-
"Unable to correctly process transform features response: " + e.toString())
242+
.withDescription("Unable to correctly process transform features response: " + e)
244243
.asRuntimeException();
245244
}
246245
}
@@ -249,11 +248,10 @@ public void processTransformFeaturesResponse(
249248
public ValueType serializeValuesIntoArrowIPC(List<Pair<String, List<ValueProto.Value>>> values) {
250249
// In order to be serialized correctly, the data must be packaged in a VectorSchemaRoot.
251250
// We first construct all the columns.
252-
Map<String, FieldVector> columnNameToColumn = new HashMap<String, FieldVector>();
253251
BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
254252

255-
List<Field> columnFields = new ArrayList<Field>();
256-
List<FieldVector> columns = new ArrayList<FieldVector>();
253+
List<Field> columnFields = new ArrayList<>();
254+
List<FieldVector> columns = new ArrayList<>();
257255

258256
for (Pair<String, List<ValueProto.Value>> columnEntry : values) {
259257
// The Python FTS does not expect full feature names, so we extract the feature name.
@@ -316,8 +314,7 @@ public ValueType serializeValuesIntoArrowIPC(List<Pair<String, List<ValueProto.V
316314
} catch (IOException e) {
317315
log.info(e.toString());
318316
throw Status.INTERNAL
319-
.withDescription(
320-
"ArrowFileWriter could not write properly; failed with error: " + e.toString())
317+
.withDescription("ArrowFileWriter could not write properly; failed with error: " + e)
321318
.asRuntimeException();
322319
}
323320
byte[] byteData = out.toByteArray();

java/storage/api/src/main/java/feast/storage/api/retriever/AvroFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ public ValueProto.Value getFeatureValue(ValueProto.ValueType.Enum valueType) {
149149
.build();
150150
break;
151151
default:
152-
throw new RuntimeException("FeatureType is not supported");
152+
throw new RuntimeException(
153+
String.format("FeatureType %s is not supported", valueType.name()));
153154
}
154155
} catch (ClassCastException e) {
155156
// Feature type has changed

0 commit comments

Comments
 (0)