From 9efbe90ee02b6b56f1a1208614c20d4b053a3135 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 16 Jan 2017 23:16:32 +0100 Subject: Revert "Revert "Revert "Bratseth/tensor type info in documents""" --- .../com/yahoo/fs4/test/RankFeaturesTestCase.java | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'container-search') diff --git a/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java b/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java index 5cf9aeda978..8c209438565 100644 --- a/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java +++ b/container-search/src/test/java/com/yahoo/fs4/test/RankFeaturesTestCase.java @@ -5,7 +5,6 @@ import com.yahoo.io.GrowableByteBuffer; import com.yahoo.search.query.ranking.RankFeatures; import com.yahoo.search.query.ranking.RankProperties; import com.yahoo.tensor.Tensor; -import com.yahoo.tensor.TensorType; import com.yahoo.tensor.serialization.TypedBinaryFormat; import com.yahoo.text.Utf8; import org.junit.Test; @@ -31,18 +30,16 @@ public class RankFeaturesTestCase { @Test public void requireThatSingleTensorIsBinaryEncoded() { - TensorType type = new TensorType.Builder().mapped("x").mapped("y").mapped("z").build(); - Tensor tensor = Tensor.from(type, "{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }"); - assertTensorEncodingAndDecoding(type, "query(my_tensor)", "my_tensor", tensor); - assertTensorEncodingAndDecoding(type, "$my_tensor", "my_tensor", tensor); + Tensor tensor = Tensor.from("{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }"); + assertTensorEncodingAndDecoding("query(my_tensor)", "my_tensor", tensor); + assertTensorEncodingAndDecoding("$my_tensor", "my_tensor", tensor); } @Test public void requireThatMultipleTensorsAreBinaryEncoded() { - TensorType type = new TensorType.Builder().mapped("x").mapped("y").mapped("z").build(); - Tensor tensor1 = Tensor.from(type, "{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }"); - Tensor tensor2 = Tensor.from(type, "{ {x:a, y:b, z:c}:5.0 }"); - assertTensorEncodingAndDecoding(type, Arrays.asList( + Tensor tensor1 = Tensor.from("{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }"); + Tensor tensor2 = Tensor.from("{ {x:a, y:b, z:c}:5.0 }"); + assertTensorEncodingAndDecoding(Arrays.asList( new Entry("query(tensor1)", "tensor1", tensor1), new Entry("$tensor2", "tensor2", tensor2))); } @@ -58,11 +55,11 @@ public class RankFeaturesTestCase { } } - private static void assertTensorEncodingAndDecoding(TensorType type, List entries) { + private static void assertTensorEncodingAndDecoding(List entries) { RankProperties properties = createRankPropertiesWithTensors(entries); assertEquals(entries.size(), properties.asMap().size()); - Map decodedProperties = decode(type, encode(properties)); + Map decodedProperties = decode(encode(properties)); assertEquals(entries.size() * 2, properties.asMap().size()); // tensor type info has been added assertEquals(entries.size() * 2, decodedProperties.size()); for (Entry entry : entries) { @@ -71,8 +68,8 @@ public class RankFeaturesTestCase { } } - private static void assertTensorEncodingAndDecoding(TensorType type, String key, String normalizedKey, Tensor tensor) { - assertTensorEncodingAndDecoding(type, Arrays.asList(new Entry(key, normalizedKey, tensor))); + private static void assertTensorEncodingAndDecoding(String key, String normalizedKey, Tensor tensor) { + assertTensorEncodingAndDecoding(Arrays.asList(new Entry(key, normalizedKey, tensor))); } private static RankProperties createRankPropertiesWithTensors(List entries) { @@ -94,7 +91,7 @@ public class RankFeaturesTestCase { return result; } - private static Map decode(TensorType type, byte[] encodedProperties) { + private static Map decode(byte[] encodedProperties) { GrowableByteBuffer buffer = GrowableByteBuffer.wrap(encodedProperties); byte[] mapNameBytes = new byte[buffer.getInt()]; buffer.get(mapNameBytes); @@ -109,7 +106,7 @@ public class RankFeaturesTestCase { if (key.contains(".type")) { result.put(key, Utf8.toString(value)); } else { - result.put(key, TypedBinaryFormat.decode(type, value)); + result.put(key, TypedBinaryFormat.decode(null, value)); // TODO: Pass type } } return result; -- cgit v1.2.3