|
1 | | - /* |
2 | | - * Copyright 2018 The Feast Authors |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * https://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
15 | | - * |
16 | | - */ |
| 1 | +/* |
| 2 | + * Copyright 2018 The Feast Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
17 | 17 |
|
18 | | - package feast.store.serving.redis; |
| 18 | +package feast.store.serving.redis; |
19 | 19 |
|
20 | | - import feast.core.FeatureSetProto.EntitySpec; |
21 | | - import feast.core.FeatureSetProto.FeatureSetSpec; |
22 | | - import feast.storage.RedisProto.RedisKey; |
23 | | - import feast.storage.RedisProto.RedisKey.Builder; |
24 | | - import feast.store.serving.redis.RedisCustomIO.Method; |
25 | | - import feast.store.serving.redis.RedisCustomIO.RedisMutation; |
26 | | - import feast.types.FieldProto.Field; |
27 | | - import feast.types.FeatureRowExtendedProto.FeatureRowExtended; |
28 | | - import feast.types.FeatureRowProto.FeatureRow; |
29 | | - import java.util.Set; |
30 | | - import java.util.stream.Collectors; |
31 | | - import lombok.AllArgsConstructor; |
32 | | - import lombok.extern.slf4j.Slf4j; |
33 | | - import org.apache.beam.sdk.transforms.DoFn; |
| 20 | +import feast.core.FeatureSetProto.EntitySpec; |
| 21 | +import feast.core.FeatureSetProto.FeatureSetSpec; |
| 22 | +import feast.storage.RedisProto.RedisKey; |
| 23 | +import feast.storage.RedisProto.RedisKey.Builder; |
| 24 | +import feast.store.serving.redis.RedisCustomIO.Method; |
| 25 | +import feast.store.serving.redis.RedisCustomIO.RedisMutation; |
| 26 | +import feast.types.FeatureRowProto.FeatureRow; |
| 27 | +import feast.types.FieldProto.Field; |
| 28 | +import java.util.Set; |
| 29 | +import java.util.stream.Collectors; |
| 30 | +import lombok.AllArgsConstructor; |
| 31 | +import lombok.NoArgsConstructor; |
| 32 | +import lombok.extern.slf4j.Slf4j; |
| 33 | +import org.apache.beam.sdk.transforms.DoFn; |
34 | 34 |
|
35 | | - @Slf4j |
36 | | - @AllArgsConstructor |
37 | | - public class FeatureRowToRedisMutationDoFn extends DoFn<FeatureRow, RedisMutation> { |
| 35 | +@Slf4j |
| 36 | +@AllArgsConstructor |
| 37 | +public class FeatureRowToRedisMutationDoFn extends DoFn<FeatureRow, RedisMutation> { |
38 | 38 |
|
39 | | - private FeatureSetSpec featureSetSpec; |
| 39 | + private FeatureSetSpec featureSetSpec; |
40 | 40 |
|
41 | | - // TODO: type and completeness checking |
42 | | - private RedisKey getKey(FeatureRow featureRow) { |
43 | | - Set<String> entityNames = featureSetSpec.getEntitiesList().stream() |
44 | | - .map(EntitySpec::getName).collect(Collectors.toSet()); |
| 41 | + // TODO: type and completeness checking |
| 42 | + private RedisKey getKey(FeatureRow featureRow) { |
| 43 | + Set<String> entityNames = featureSetSpec.getEntitiesList().stream() |
| 44 | + .map(EntitySpec::getName).collect(Collectors.toSet()); |
45 | 45 |
|
46 | | - Builder redisKeyBuilder = RedisKey.newBuilder() |
47 | | - .setFeatureSet(featureRow.getFeatureSet()); |
48 | | - for (Field field : featureRow.getFieldsList()) { |
49 | | - if (entityNames.contains(field.getName())) { |
50 | | - redisKeyBuilder.addEntities(field); |
51 | | - } |
52 | | - } |
| 46 | + Builder redisKeyBuilder = RedisKey.newBuilder() |
| 47 | + .setFeatureSet(featureRow.getFeatureSet()); |
| 48 | + for (Field field : featureRow.getFieldsList()) { |
| 49 | + if (entityNames.contains(field.getName())) { |
| 50 | + redisKeyBuilder.addEntities(field); |
| 51 | + } |
| 52 | + } |
53 | 53 |
|
54 | | - return redisKeyBuilder.build(); |
55 | | - } |
| 54 | + return redisKeyBuilder.build(); |
| 55 | + } |
56 | 56 |
|
57 | | - /** |
58 | | - * Output a redis mutation object for every feature in the feature row. |
59 | | - */ |
60 | | - @ProcessElement |
61 | | - public void processElement(ProcessContext context) { |
62 | | - FeatureRow featureRow = context.element(); |
63 | | - RedisKey key = getKey(featureRow); |
64 | | -// Duration expiry = options.getExpiryDuration(); |
65 | | -// // Add randomness to expiry so that it won't expire in the same time. |
66 | | -// long expiryMillis = (long) (expiry.getMillis() * (1 + random.nextFloat())); |
67 | | - context.output( |
68 | | - RedisMutation.builder() |
69 | | - .key(key.toByteArray()) |
70 | | - .value(featureRow.toByteArray()) |
71 | | - .method(Method.SET) |
72 | | - .build()); |
73 | | - } |
74 | | - } |
| 57 | + /** |
| 58 | + * Output a redis mutation object for every feature in the feature row. |
| 59 | + */ |
| 60 | + @ProcessElement |
| 61 | + public void processElement(ProcessContext context) { |
| 62 | + FeatureRow featureRow = context.element(); |
| 63 | + RedisKey key = getKey(featureRow); |
| 64 | + // Duration expiry = options.getExpiryDuration(); |
| 65 | + // Add randomness to expiry so that it won't expire in the same time. |
| 66 | + // long expiryMillis = (long) (expiry.getMillis() * (1 + random.nextFloat())); |
| 67 | + context.output( |
| 68 | + RedisMutation.builder() |
| 69 | + .key(key.toByteArray()) |
| 70 | + .value(featureRow.toByteArray()) |
| 71 | + .method(Method.SET) |
| 72 | + .build()); |
| 73 | + } |
| 74 | +} |
0 commit comments