Search in sources :

Example 11 with SimpleCatalog

use of com.amazon.ion.system.SimpleCatalog in project ion-hive-serde by amzn.

the class CatalogConfig method catalogFromReader.

private static IonCatalog catalogFromReader(final IonReader reader) {
    final SimpleCatalog catalog = new SimpleCatalog();
    while (reader.next() != null) {
        @SuppressWarnings("deprecated") final SymbolTable symbolTable = _Private_Utils.newSharedSymtab(reader, true);
        catalog.putTable(symbolTable);
    }
    return catalog;
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) SymbolTable(com.amazon.ion.SymbolTable)

Example 12 with SimpleCatalog

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

the class CloneTest method testDifferentValueFactoryCloneWithUnknownAnnotationText.

@Test
public void testDifferentValueFactoryCloneWithUnknownAnnotationText() {
    IonSystem otherSystem = newSystem(new SimpleCatalog());
    SymbolToken tok = newSymbolToken(99);
    IonInt original = system().newInt(5);
    original.setTypeAnnotationSymbols(tok);
    // TODO amzn/ion-java/issues/30 An UnknownSymbolException is expected here, but
    // it isn't thrown.
    IonInt copy = otherSystem.clone(original);
    // If we don't fail we should at least retain the SID.
    assertEquals(99, copy.getTypeAnnotationSymbols()[0].getSid());
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken) Test(org.junit.Test)

Example 13 with SimpleCatalog

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

the class CloneTest method testDifferentValueFactoryCloneWithUnknownFieldNameText.

@Test
public void testDifferentValueFactoryCloneWithUnknownFieldNameText() {
    IonSystem otherSystem = newSystem(new SimpleCatalog());
    SymbolToken tok = newSymbolToken(99);
    IonStruct original = system().newEmptyStruct();
    IonValue child = system().newNull();
    original.add(tok, child);
    // This works since the cloned child doesn't retain its field name.
    otherSystem.clone(child);
    // TODO amzn/ion-java/issues/30 An UnknownSymbolException is expected here, but
    // it isn't thrown.
    IonStruct copy = otherSystem.clone(original);
    // If we don't fail we should at least retain the SID.
    assertEquals(99, copy.iterator().next().getFieldNameSymbol().getSid());
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken) Test(org.junit.Test)

Example 14 with SimpleCatalog

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

the class VarIntTest method makeReader.

private IonReaderBinaryUserX makeReader(String hex) throws Exception {
    ByteArrayInputStream input = new ByteArrayInputStream(parseHexBinary("E00100EA" + hex));
    UnifiedInputStreamX uis = UnifiedInputStreamX.makeStream(input);
    uis.skip(4);
    return new IonReaderBinaryUserX(new SimpleCatalog(), LocalSymbolTable.DEFAULT_LST_FACTORY, uis, 0);
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 15 with SimpleCatalog

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

the class SymbolTableTest method testLocalTableWithMissingImport.

@Test
public void testLocalTableWithMissingImport() throws IOException {
    // Use a big symtab to get beyond any default allocation within the
    // dummy symtab.  This was done to trap a bug in LocalSymbolTable.
    ArrayList<String> syms = new ArrayList<String>();
    int maxId = 50;
    for (int i = 1; i <= maxId; i++) {
        syms.add("S" + i);
    }
    SymbolTable table = system().newSharedSymbolTable("T", 1, syms.iterator());
    SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
    catalog.putTable(table);
    final int import1id = systemMaxId() + 1;
    final int import2id = systemMaxId() + 2;
    final int local1id = systemMaxId() + maxId + 1;
    final int local2id = local1id + 1;
    String text = LocalSymbolTablePrefix + "{" + "  symbols:[ \"local1\", \"local2\" ]," + "  imports:[{name:'''T''', version:1," + "            max_id:" + maxId + "}]," + "}\n" + "local1 local2 S1 S2";
    byte[] binary = encode(text);
    // Remove the imported table before decoding the binary.
    assertSame(table, catalog.removeTable("T", 1));
    IonDatagram dg = loader().load(binary);
    checkSymbol("local1", local1id, dg.get(0));
    checkSymbol("local2", local2id, dg.get(1));
    checkUnknownSymbol(import1id, dg.get(2));
    checkUnknownSymbol(import2id, dg.get(3));
    SymbolTable st = dg.get(3).getSymbolTable();
    checkLocalTable(st);
    checkUnknownSymbol("S1", import1id, st);
    checkUnknownSymbol("S2", import2id, st);
    assertEquals(local1id - 1, st.getImportedMaxId());
    SymbolTable dummy = checkFirstImport("T", 1, new String[maxId], st);
    assertTrue(dummy.isSubstitute());
    checkUnknownSymbol("S1", import1id, dummy);
    checkUnknownSymbol("S2", import2id, dummy);
    SymbolTable[] importedTables = st.getImportedTables();
    assertEquals(1, importedTables.length);
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonDatagram(com.amazon.ion.IonDatagram) ArrayList(java.util.ArrayList) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Aggregations

SimpleCatalog (com.amazon.ion.system.SimpleCatalog)25 Test (org.junit.Test)22 SymbolTable (com.amazon.ion.SymbolTable)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6 IonDatagram (com.amazon.ion.IonDatagram)5 SymbolTableTest (com.amazon.ion.impl.SymbolTableTest)5 com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)5 com.amazon.ion.impl._Private_Utils.newSymbolToken (com.amazon.ion.impl._Private_Utils.newSymbolToken)3 IonSystem (com.amazon.ion.IonSystem)2 IonWriter (com.amazon.ion.IonWriter)2 IonMutableCatalog (com.amazon.ion.IonMutableCatalog)1 IonReader (com.amazon.ion.IonReader)1 IonValue (com.amazon.ion.IonValue)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1