Search in sources :

Example 1 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class FastHit method addSummary.

void addSummary(DocsumDefinition docsumDef, Inspector value) {
    reserve(docsumDef.getFieldCount());
    for (DocsumField field : docsumDef.getFields()) {
        String fieldName = field.getName();
        Inspector f = value.field(fieldName);
        if (field.getEmulConfig().forceFillEmptyFields() || f.valid()) {
            setDocsumFieldIfNotPresent(fieldName, field.convert(f));
        }
    }
}
Also used : Inspector(com.yahoo.data.access.Inspector)

Example 2 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class JSONStringTestCase method testMap.

@Test
public void testMap() {
    String json = "[{\"key\":\"k1\",\"value\":\"v1\"},{\"key\":\"k2\",\"value\":\"v2\"}]";
    JSONString js = new JSONString(json);
    String correct = "\n" + "      <item><key>k1</key><value>v1</value></item>\n" + "      <item><key>k2</key><value>v2</value></item>\n    ";
    assertEquals(correct, js.toString());
    Inspector top = new Value.ArrayValue().add(new Value.ObjectValue().put("key", "k1").put("value", "v1")).add(new Value.ObjectValue().put("key", "k2").put("value", "v2"));
    js = new JSONString(top);
    assertEquals(correct, js.renderFromInspector());
}
Also used : Value(com.yahoo.data.access.simple.Value) Inspector(com.yahoo.data.access.Inspector) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 3 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class JSONStringTestCase method testArrayOfStructWithEmptyMap.

@Test
public void testArrayOfStructWithEmptyMap() {
    String json = "[{\"asf\":\"here is 1st simple string field\",\"map\":[],\"sf2\":\"here is 2nd simple string field\"},{\"asf\":\"here is 3rd simple string field\",\"map\":[],\"sf2\":\"here is 4th simple string field\"}]";
    JSONString js = new JSONString(json);
    String correct = "\n" + "      <item>\n" + "        <struct-field name=\"asf\">here is 1st simple string field</struct-field>\n" + "        <struct-field name=\"map\"></struct-field>\n" + "        <struct-field name=\"sf2\">here is 2nd simple string field</struct-field>\n" + "      </item>\n" + "      <item>\n" + "        <struct-field name=\"asf\">here is 3rd simple string field</struct-field>\n" + "        <struct-field name=\"map\"></struct-field>\n" + "        <struct-field name=\"sf2\">here is 4th simple string field</struct-field>\n" + "      </item>\n" + "    ";
    assertEquals(correct, js.toString());
    Inspector top = new Value.ArrayValue().add(new Value.ObjectValue().put("asf", "here is 1st simple string field").put("map", new Value.ArrayValue()).put("sf2", "here is 2nd simple string field")).add(new Value.ObjectValue().put("asf", "here is 3rd simple string field").put("map", new Value.ArrayValue()).put("sf2", "here is 4th simple string field"));
    js = new JSONString(top);
    assertEquals(correct, js.renderFromInspector());
}
Also used : Value(com.yahoo.data.access.simple.Value) Inspector(com.yahoo.data.access.Inspector) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 4 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class JSONStringTestCase method testContentToInspectorMapping.

@Test
public void testContentToInspectorMapping() {
    Inspector value1 = new JSONString("").inspect();
    Inspector value2 = new JSONString("foo").inspect();
    Inspector value3 = new JSONString("\"foo\"").inspect();
    Inspector value4 = new JSONString("123").inspect();
    Inspector value5 = new JSONString("{\"foo\":1}").inspect();
    Inspector value6 = new JSONString("[1,2,3]").inspect();
    System.out.println("1: " + value1);
    System.out.println("2: " + value2);
    System.out.println("3: " + value3);
    System.out.println("4: " + value4);
    System.out.println("5: " + value5);
    System.out.println("6: " + value6);
    assertEquals(Type.STRING, value1.type());
    assertEquals("", value1.asString());
    assertEquals(value2.type(), Type.STRING);
    assertEquals("foo", value2.asString());
    assertEquals(value3.type(), Type.STRING);
    assertEquals("\"foo\"", value3.asString());
    assertEquals(value4.type(), Type.STRING);
    assertEquals("123", value4.asString());
    assertEquals(value5.type(), Type.OBJECT);
    assertEquals(1L, value5.field("foo").asLong());
    assertEquals("{\"foo\":1}", value5.toString());
    assertEquals(value6.type(), Type.ARRAY);
    assertEquals(1L, value6.entry(0).asLong());
    assertEquals(2L, value6.entry(1).asLong());
    assertEquals(3L, value6.entry(2).asLong());
    assertEquals("[1,2,3]", value6.toString());
}
Also used : Inspector(com.yahoo.data.access.Inspector) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 5 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class JSONStringTestCase method testWithData.

@Test
public void testWithData() {
    byte[] d1 = { (byte) 0x41, (byte) 0x42, (byte) 0x43 };
    byte[] d2 = { (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02 };
    byte[] d3 = { (byte) 0x12, (byte) 0x34 };
    byte[] d4 = { (byte) 0xff, (byte) 0x80, (byte) 0x7f };
    Inspector top = new Value.ObjectValue().put("simple", new Value.DataValue(d1)).put("array", new Value.ArrayValue().add(new Value.DataValue(d2)).add(new Value.DataValue(d3)).add(new Value.DataValue(d4)));
    JSONString js = new JSONString(top);
    String correct = "\n" + "      <struct-field name=\"simple\">" + "<data length=\"3\" encoding=\"hex\">414243</data>" + "</struct-field>\n" + "      <struct-field name=\"array\">\n" + "        <item>" + "<data length=\"4\" encoding=\"hex\">00010002</data>" + "</item>\n" + "        <item>" + "<data length=\"2\" encoding=\"hex\">1234</data>" + "</item>\n" + "        <item>" + "<data length=\"3\" encoding=\"hex\">FF807F</data>" + "</item>\n" + "      </struct-field>\n    ";
    assertEquals(correct, js.renderFromInspector());
}
Also used : Value(com.yahoo.data.access.simple.Value) Inspector(com.yahoo.data.access.Inspector) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Aggregations

Inspector (com.yahoo.data.access.Inspector)21 Test (org.junit.Test)19 JSONString (com.yahoo.prelude.hitfield.JSONString)8 Value (com.yahoo.data.access.simple.Value)6 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)1 Slime (com.yahoo.slime.Slime)1 ByteBuffer (java.nio.ByteBuffer)1