Search in sources :

Example 6 with KvArray

use of com.torodb.kvdocument.values.KvArray in project torodb by torodb.

the class TestConvertJson method parseMultiArrayEmpty.

@Test
public void parseMultiArrayEmpty() {
    KvDocument doc = parser.createFromResource("MultiArrayEmpty.json");
    KvArray array = (KvArray) doc.get("months");
    assertEquals(1, array.size());
    assertTrue(array.get(0) instanceof KvArray);
    KvArray inner = (KvArray) array.get(0);
    assertEquals(0, inner.size());
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) KvArray(com.torodb.kvdocument.values.KvArray) Test(org.junit.Test)

Example 7 with KvArray

use of com.torodb.kvdocument.values.KvArray in project torodb by torodb.

the class TestConvertJson method parseEmptyArray.

@Test
public void parseEmptyArray() {
    KvDocument doc = parser.createFromResource("EmptyArray.json");
    assertTrue(doc.containsKey("department"));
    assertTrue(doc.get("department") instanceof KvArray);
    assertTrue(((KvArray) doc.get("department")).size() == 0);
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) KvArray(com.torodb.kvdocument.values.KvArray) Test(org.junit.Test)

Example 8 with KvArray

use of com.torodb.kvdocument.values.KvArray in project torodb by torodb.

the class R2DTranslatorTest method readTwoInnerArray.

/*
   * Document: { "name" : "jero", "numbers" : [666, [4,8, 15, 16]] }
   */
@Test
public void readTwoInnerArray() {
    int did = 1;
    /*
     * Root Level
     */
    MetaDocPartBuilder builder = new MetaDocPartBuilder(rootRef);
    builder.addMetaField("name", "name_s", FieldType.STRING);
    builder.addMetaField("numbers", "numbers_e", FieldType.CHILD);
    builder.addRow(did, null, did, null, "jero", IsArray);
    MockedDocPartResult root = builder.getResultSet();
    /*
     * Second Level
     */
    int pid = did;
    TableRef secondRef = fact.createChild(rootRef, "numbers");
    MetaDocPartBuilder secondBuilder = new MetaDocPartBuilder(secondRef);
    secondBuilder.addMetaScalar("v_i", FieldType.INTEGER);
    secondBuilder.addMetaScalar("v_e", FieldType.CHILD);
    secondBuilder.addRow(did, pid, 20, 0, 666, null);
    secondBuilder.addRow(did, pid, 21, 1, null, IsArray);
    MockedDocPartResult secondLevel = secondBuilder.getResultSet();
    /*
     * Third Level
     */
    int pid1 = 21;
    TableRef thirdRef = fact.createChild(secondRef, 2);
    MetaDocPartBuilder thirdBuilder = new MetaDocPartBuilder(thirdRef);
    thirdBuilder.addMetaScalar("v_i", FieldType.INTEGER);
    thirdBuilder.addRow(did, pid1, 30, 0, 4);
    thirdBuilder.addRow(did, pid1, 31, 1, 8);
    thirdBuilder.addRow(did, pid1, 33, 2, 15);
    thirdBuilder.addRow(did, pid1, 34, 3, 16);
    MockedDocPartResult thirdLevel = thirdBuilder.getResultSet();
    List<DocPartResult> lst = Lists.newArrayList(thirdLevel, secondLevel, root);
    R2DTranslator r2dTranslator = new R2DTranslatorImpl();
    Collection<ToroDocument> readedDocuments = r2dTranslator.translate(lst.iterator());
    assertEquals(1, readedDocuments.size());
    KvDocument doc = readedDocuments.iterator().next().getRoot();
    assertEquals("jero", doc.get("name").getValue());
    KvValue<?> kvValue = doc.get("numbers");
    assertTrue(kvValue instanceof KvArray);
    KvArray array = (KvArray) kvValue;
    assertEquals(2, array.size());
    assertEquals(666, array.get(0).getValue());
    KvValue<?> kvValueSecond = array.get(1);
    assertNotNull(kvValueSecond);
    assertTrue(kvValueSecond instanceof KvArray);
    KvArray array2 = (KvArray) kvValueSecond;
    assertEquals(4, array2.size());
    assertEquals(4, array2.get(0).getValue());
    assertEquals(8, array2.get(1).getValue());
    assertEquals(15, array2.get(2).getValue());
    assertEquals(16, array2.get(3).getValue());
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) R2DTranslator(com.torodb.core.d2r.R2DTranslator) KvArray(com.torodb.kvdocument.values.KvArray) ToroDocument(com.torodb.core.document.ToroDocument) DocPartResult(com.torodb.core.d2r.DocPartResult) TableRef(com.torodb.core.TableRef) Test(org.junit.Test)

Aggregations

KvArray (com.torodb.kvdocument.values.KvArray)8 KvDocument (com.torodb.kvdocument.values.KvDocument)8 Test (org.junit.Test)8 TableRef (com.torodb.core.TableRef)3 DocPartResult (com.torodb.core.d2r.DocPartResult)3 R2DTranslator (com.torodb.core.d2r.R2DTranslator)3 ToroDocument (com.torodb.core.document.ToroDocument)3