Search in sources :

Example 1 with IonList

use of com.amazon.ion.IonList in project amazon-qldb-dmv-sample-java by aws-samples.

the class JournalS3ExportReader method getDataFileKeysFromManifest.

/**
 * Given the S3Object to the completed manifest file, return the keys
 * which are part of this export request.
 *
 * @param s3Object
 *              A {@link S3Object}.
 * @return a list of data file keys containing the chunk of {@link JournalBlock}.
 */
private static List<String> getDataFileKeysFromManifest(final S3Object s3Object) {
    IonReader ionReader = IonReaderBuilder.standard().build(s3Object.getObjectContent());
    // Read the data
    ionReader.next();
    List<String> keys = new ArrayList<>();
    IonStruct ionStruct = (IonStruct) SYSTEM.newValue(ionReader);
    IonList ionKeysList = (IonList) ionStruct.get("keys");
    ionKeysList.forEach(key -> keys.add(((IonString) key).stringValue()));
    return keys;
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString) IonList(com.amazon.ion.IonList) IonReader(com.amazon.ion.IonReader) ArrayList(java.util.ArrayList) IonString(com.amazon.ion.IonString)

Example 2 with IonList

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

the class SymbolTableTest method testSymtabImageMaintenance.

@Test
public void testSymtabImageMaintenance() {
    IonSystem system = system();
    SymbolTable st = ((_Private_ValueFactory) system).getLstFactory().newLocalSymtab(system.getSystemSymbolTable());
    st.intern("foo");
    IonStruct image = symtabTree(st, system);
    st.intern("bar");
    image = symtabTree(st, system);
    IonList symbols = (IonList) image.get(SYMBOLS);
    assertEquals("[\"foo\",\"bar\"]", symbols.toString());
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 3 with IonList

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

the class Symtabs method sharedSymtabStruct.

/**
 * Constructs the DOM for a shared symtab.
 *
 * @param syms If null, so symbols list will be added.
 */
public static IonStruct sharedSymtabStruct(ValueFactory factory, String name, int version, String... syms) {
    IonStruct s = factory.newEmptyStruct();
    s.setTypeAnnotations(SystemSymbols.ION_SHARED_SYMBOL_TABLE);
    s.add(SystemSymbols.NAME).newString(name);
    s.add(SystemSymbols.VERSION).newInt(version);
    if (syms != null) {
        IonList l = s.add(SystemSymbols.SYMBOLS).newEmptyList();
        for (String sym : syms) {
            l.add().newString(sym);
        }
    }
    return s;
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList) IonTextUtils.printString(com.amazon.ion.util.IonTextUtils.printString)

Example 4 with IonList

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

the class TreeReaderTest method testInitialStateForList.

@Test
public void testInitialStateForList() {
    IonList list = system().newEmptyList();
    in = system().newReader(list);
    check().next().type(IonType.LIST);
    assertEquals(0, in.getDepth());
    in.stepIn();
    {
        assertEquals(1, in.getDepth());
        expectEof();
    }
    in.stepOut();
    expectTopEof();
}
Also used : IonList(com.amazon.ion.IonList) Test(org.junit.Test)

Example 5 with IonList

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

the class ValueWriterTest method testWriteValuesWithSymtabIntoContainer.

// TODO more thorough testing that you can't output from DOM w/ bad text
@Test
public void testWriteValuesWithSymtabIntoContainer() throws Exception {
    myOutputInList = true;
    SymbolTable fredSymtab = Symtabs.register(Symtabs.FRED_NAME, 1, catalog());
    SymbolTable gingerSymtab = Symtabs.register(Symtabs.GINGER_NAME, 1, catalog());
    String gingerSym = gingerSymtab.findKnownSymbol(1);
    // First setup some data to be copied.
    IonDatagram dg = system().newDatagram(gingerSymtab);
    dg.add().newSymbol(gingerSym);
    IonReader r = system().newReader(dg.getBytes());
    // Now copy that data into a non-top-level context
    iw = makeWriter(fredSymtab);
    iw.writeValues(r);
    IonDatagram result = reload();
    IonList l = (IonList) result.get(0);
    assertEquals(1, l.size());
    IonSymbol s = (IonSymbol) l.get(0);
    // Should've assigned a new SID
    checkSymbol(gingerSym, systemMaxId() + Symtabs.FRED_MAX_IDS[1] + 1, s);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) IonReader(com.amazon.ion.IonReader) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Aggregations

IonList (com.amazon.ion.IonList)28 IonStruct (com.amazon.ion.IonStruct)13 Test (org.junit.Test)10 SymbolTable (com.amazon.ion.SymbolTable)5 IonDatagram (com.amazon.ion.IonDatagram)4 IonFloat (com.amazon.ion.IonFloat)3 IonReader (com.amazon.ion.IonReader)3 IonSexp (com.amazon.ion.IonSexp)3 IonString (com.amazon.ion.IonString)3 IonSymbol (com.amazon.ion.IonSymbol)3 IonBlob (com.amazon.ion.IonBlob)2 IonClob (com.amazon.ion.IonClob)2 IonTimestamp (com.amazon.ion.IonTimestamp)2 IonValue (com.amazon.ion.IonValue)2 BlobTest (com.amazon.ion.BlobTest)1 ClobTest (com.amazon.ion.ClobTest)1 IntTest (com.amazon.ion.IntTest)1 IonBool (com.amazon.ion.IonBool)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonException (com.amazon.ion.IonException)1