Search in sources :

Example 21 with IonValue

use of com.amazon.ion.IonValue in project ion-java by amzn.

the class IonAssert method assertStructEquals.

private static void assertStructEquals(String path, IonStruct expected, IonStruct actual) {
    int expectedSize = expected.size();
    int actualSize = actual.size();
    if (expectedSize != actualSize) {
        fail(String.format("%s size, expected:%s actual:%s", path, expectedSize, actualSize));
    }
    Map<SymbolToken, List<IonValue>> expectedFields = sortFields(expected);
    Map<SymbolToken, List<IonValue>> actualFields = sortFields(actual);
    for (Entry<SymbolToken, List<IonValue>> expectedEntry : expectedFields.entrySet()) {
        SymbolToken token = expectedEntry.getKey();
        String fieldPath = path + '.' + printSymbol(token);
        List<IonValue> actualList = actualFields.get(token);
        if (actualList == null) {
            fail(String.format("Missing field %s, expected: %s actual: %s", fieldPath, expected, actual));
        }
        assertFieldEquals(fieldPath, expectedEntry.getValue(), actual, actualList);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) ArrayList(java.util.ArrayList) List(java.util.List)

Example 22 with IonValue

use of com.amazon.ion.IonValue in project ion-java by amzn.

the class IteratorTiming method main.

public static void main(String[] args) {
    IonSystem ion = IonSystemBuilder.standard().build();
    System.out.println("Start at " + new Date());
    try {
        InputStream is = new FileInputStream(args[0]);
        Iterator<IonValue> itera = ion.iterate(new InputStreamReader(is));
        int count = 0;
        long start = System.currentTimeMillis();
        long millis = start;
        while (itera.hasNext()) {
            itera.next();
            if ((++count % 100) == 0) {
                long diff = System.currentTimeMillis() - millis;
                System.out.println(diff);
                millis = System.currentTimeMillis();
            }
        }
        long now = System.currentTimeMillis();
        long elapsed = now - start;
        System.out.println();
        System.out.println("End at " + new Date());
        System.out.println("Total millis: " + elapsed);
        System.out.println("# values: " + count);
        System.out.println("avg millis/value: " + ((float) elapsed) / count);
        Runtime rt = Runtime.getRuntime();
        System.out.println("Total memory: " + rt.totalMemory());
    } catch (IOException e) {
        System.err.println(e);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Date(java.util.Date) FileInputStream(java.io.FileInputStream)

Example 23 with IonValue

use of com.amazon.ion.IonValue in project ion-java by amzn.

the class BinaryStreamingTest method testValue2.

@Test
public void testValue2() throws Exception {
    String s = "item_view::{item_id:\"B00096H8Q4\",marketplace_id:2," + "product:{item_name:[" + "{value:'''Method 24CT Leather Wipes''',lang:EN_CA}," + "{value:'''Method 24CT Chiffons de Cuir''',lang:FR_CA}]," + "list_price:{value:18.23,unit:EUR},}" + ",index_suppressed:true," + "offline_store_only:true,version:2,}";
    IonSystem sys = system();
    IonDatagram dg = sys.getLoader().load(s);
    IonValue v = dg.get(0);
    IonValue v2 = ((IonStruct) v).get("offline_store_only");
    SymbolTable sym = v.getSymbolTable();
    assert v2.getSymbolTable() == sym;
    IonReader ir = system().newReader(s);
    Iterator<String> symbols = sym.iterateDeclaredSymbolNames();
    SymbolTable u = system().newSharedSymbolTable("items", 1, symbols);
    IonBinaryWriter wr = system().newBinaryWriter(u);
    wr.writeValues(ir);
    byte[] buffer = wr.getBytes();
    dumpBuffer(buffer, buffer.length);
    ir = getStreamingMode().newIonReader(system().getCatalog(), buffer);
    wr = system().newBinaryWriter(u);
    wr.writeValues(ir);
    buffer = wr.getBytes();
    dumpBuffer(buffer, buffer.length);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) IonBinaryWriter(com.amazon.ion.IonBinaryWriter) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 24 with IonValue

use of com.amazon.ion.IonValue in project ion-java by amzn.

the class SymbolTableTest method testOverridingSystemSymbolId.

/**
 * Attempts to override system symbols are ignored.
 */
@Test
public void testOverridingSystemSymbolId() {
    String importingText = LocalSymbolTablePrefix + "{" + "  symbols:[ '''" + NAME + "''' ]," + "}\n" + "null";
    Iterator<IonValue> scanner = system().iterate(importingText);
    IonValue v = scanner.next();
    SymbolTable symtab = v.getSymbolTable();
    assertTrue(symtab.isLocalTable());
    checkSymbol(NAME, NAME_SID, symtab);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 25 with IonValue

use of com.amazon.ion.IonValue in project ion-java by amzn.

the class SymbolTableTest method testImportsFollowSymbols.

@Test
public void testImportsFollowSymbols() {
    registerImportedV1();
    final int import1id = systemMaxId() + 1;
    final int local1id = systemMaxId() + IMPORTED_1_MAX_ID + 1;
    final int local2id = local1id + 1;
    String importingText = "$ion_1_0 " + LocalSymbolTablePrefix + "{" + "  symbols:[ '''local1''' ]," + "  imports:[{name:'''imported''', version:1, max_id:2}]," + "}\n" + // This symbol is added to end of locals
    "local2\n" + "local1\n" + "'imported 1'";
    Iterator<IonValue> scanner = system().iterate(importingText);
    IonValue value = scanner.next();
    SymbolTable symtab = value.getSymbolTable();
    checkLocalTable(symtab);
    checkSymbol("local2", value);
    value = scanner.next();
    checkSymbol("local1", local1id, value);
    value = scanner.next();
    checkSymbol("imported 1", import1id, value);
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Aggregations

IonValue (com.amazon.ion.IonValue)185 Test (org.junit.Test)115 IonSequence (com.amazon.ion.IonSequence)61 SymbolTable (com.amazon.ion.SymbolTable)21 IonDatagram (com.amazon.ion.IonDatagram)20 IonStruct (com.amazon.ion.IonStruct)18 IonInt (com.amazon.ion.IonInt)16 IOException (java.io.IOException)14 IonReader (com.amazon.ion.IonReader)13 IonSystem (com.amazon.ion.IonSystem)12 Result (software.amazon.qldb.Result)11 SymbolToken (com.amazon.ion.SymbolToken)10 ArrayList (java.util.ArrayList)10 IonString (com.amazon.ion.IonString)9 IonException (com.amazon.ion.IonException)7 IonType (com.amazon.ion.IonType)6 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)6 Event (com.amazon.tools.events.Event)5 com.amazon.ion.impl._Private_IonValue (com.amazon.ion.impl._Private_IonValue)4 EventType (com.amazon.tools.events.EventType)4