Skip to content

Commit

Permalink
Ordering keys in ingestion and serving (#4)
Browse files Browse the repository at this point in the history
* Ordering keys in ingestion and serving

* Notracing
  • Loading branch information
Wirick authored May 3, 2020
1 parent 872b192 commit 743f097
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
REGISTRY := gcr.io/pm-registry/feast
VERSION := v0.4.3-cassandra-experiment-2.22-notrace
VERSION := v0.4-cassandra-ordered-notrace
PROJECT_ROOT := $(shell git rev-parse --show-toplevel)

test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import feast.types.FieldProto.Field;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.beam.sdk.coders.AvroCoder;
import org.apache.beam.sdk.coders.DefaultCoder;
Expand Down Expand Up @@ -86,20 +84,25 @@ public int getTtl() {
}

static String keyFromFeatureRow(FeatureSetSpec featureSetSpec, FeatureRow featureRow) {
Set<String> entityNames =
List<String> entityNames =
featureSetSpec.getEntitiesList().stream()
.map(EntitySpec::getName)
.collect(Collectors.toSet());
List<Field> entities = new ArrayList<>();
.collect(Collectors.toList());
Collections.sort(entityNames);
HashMap<String, Field> entities = new HashMap<>();
for (Field field : featureRow.getFieldsList()) {
if (entityNames.contains(field.getName())) {
entities.add(field);
entities.put(entityNames.get(entityNames.indexOf(field.getName())), field);
}
}
return featureRow.getFeatureSet()
+ ":"
+ entities.stream()
.map(f -> f.getName() + "=" + ValueUtil.toString(f.getValue()))
+ entityNames.stream()
.map(
f ->
entities.get(f).getName()
+ "="
+ ValueUtil.toString(entities.get(f).getValue()))
.collect(Collectors.joining("|"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.nio.ByteBuffer;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -303,6 +304,7 @@ private static String createCassandraKey(
String featureSet, List<String> featureSetEntityNames, EntityRow entityRow) {
Map<String, Value> fieldsMap = entityRow.getFieldsMap();
List<String> res = new ArrayList<>();
Collections.sort(featureSetEntityNames);
for (String entityName : featureSetEntityNames) {
res.add(entityName + "=" + ValueUtil.toString(fieldsMap.get(entityName)));
}
Expand Down

0 comments on commit 743f097

Please sign in to comment.