use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class SymbolTableTest method testDupLocalSymbolOnDatagram.
@Test
public void testDupLocalSymbolOnDatagram() throws Exception {
final IonSystem ion1 = system();
final SymbolTable st = ion1.newSharedSymbolTable("foobar", 1, Arrays.asList("s1").iterator());
final IonMutableCatalog cat = new SimpleCatalog();
cat.putTable(st);
// amzn/ion-java/issues/46 has the datagram producing something like:
// $ion_1_0 $ion_symbol_table::{imports:[{name: "foobar", version: 1, max_id: 1}], symbols: ["s1", "l1"]} $11 $12
// local table should not have "s1", user values should be $10 $11
IonDatagram dg = ion1.newDatagram(st);
dg.add().newSymbol("s1");
dg.add().newSymbol("l1");
final IonSystem ion2 = newSystem(cat);
dg = ion2.getLoader().load(dg.getBytes());
checkSymbol("s1", 10, dg.get(0));
checkSymbol("l1", 11, dg.get(1));
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method multipleSymbolTablesWithSymbolsThenImports.
@Test
public void multipleSymbolTablesWithSymbolsThenImports() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
catalog.putTable(SYSTEM.newSharedSymbolTable("bar", 1, Collections.singletonList("baz").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString("ghi");
writer.stepOut();
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("foo");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString("xyz");
writer.writeString("uvw");
writer.writeString("rst");
writer.stepOut();
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("bar");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(1);
writer.stepOut();
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
writer.writeSymbolToken(13);
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
SymbolTable[] imports = reader.getSymbolTable().getImportedTables();
assertEquals(1, imports.length);
assertEquals("foo", imports[0].getName());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("ghi", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("baz", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
imports = reader.getSymbolTable().getImportedTables();
assertEquals(1, imports.length);
assertEquals("bar", imports[0].getName());
assertEquals("xyz", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("uvw", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("rst", reader.stringValue());
assertNull(reader.next());
reader.close();
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method symbolTableWithManySymbolsThenImports.
@Test
public void symbolTableWithManySymbolsThenImports() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString("ghi");
writer.writeString("jkl");
writer.writeString("mno");
writer.writeString("pqr");
writer.stepOut();
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("foo");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
writer.writeSymbolToken(13);
writer.writeSymbolToken(14);
writer.writeSymbolToken(15);
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("ghi", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("jkl", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("mno", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("pqr", reader.stringValue());
assertNull(reader.next());
reader.close();
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method symbolTableWithMultipleImportsCorrectlyAssignsImportLocations.
@Test
public void symbolTableWithMultipleImportsCorrectlyAssignsImportLocations() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
catalog.putTable(SYSTEM.newSharedSymbolTable("bar", 1, Arrays.asList("123", "456").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("foo");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
// The matching shared symbol table in the catalog only declares two symbols.
writer.writeInt(4);
writer.stepOut();
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("bar");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
// The matching shared symbol table in the catalog declares two symbols, but only one is used.
writer.writeInt(1);
writer.stepOut();
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
// There is no match in the catalog; all symbols have unknown text.
writer.writeString("baz");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.stepOut();
// abc
writer.writeSymbolToken(10);
// def
writer.writeSymbolToken(11);
// unknown text, import SID 3 (from foo)
writer.writeSymbolToken(12);
// unknown text, import SID 4 (from foo)
writer.writeSymbolToken(13);
// 123
writer.writeSymbolToken(14);
// unknown text, import SID 1 (from baz)
writer.writeSymbolToken(15);
// unknown text, import SID 2 (from baz)
writer.writeSymbolToken(16);
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
IonReaderBinaryIncremental.SymbolTokenImpl symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
assertNull(symbolValue.getText());
assertEquals(new ImportLocation("foo", 3), symbolValue.getImportLocation());
assertEquals(IonType.SYMBOL, reader.next());
symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
assertNull(symbolValue.getText());
assertEquals(new ImportLocation("foo", 4), symbolValue.getImportLocation());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("123", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
assertEquals(new IonReaderBinaryIncremental.SymbolTokenImpl(null, 15, new ImportLocation("baz", 1)), symbolValue);
assertEquals(IonType.SYMBOL, reader.next());
symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
assertEquals(new IonReaderBinaryIncremental.SymbolTokenImpl(null, 16, new ImportLocation("baz", 2)), symbolValue);
assertNull(reader.next());
reader.close();
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method ivmResetsImports.
@Test
public void ivmResetsImports() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString("ghi");
writer.stepOut();
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("foo");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
writer.close();
out.write(_Private_IonConstants.BINARY_VERSION_MARKER_1_0);
out.write(0x20);
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
SymbolTable[] imports = reader.getSymbolTable().getImportedTables();
assertEquals(1, imports.length);
assertEquals("foo", imports[0].getName());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("ghi", reader.stringValue());
assertEquals(IonType.INT, reader.next());
assertTrue(reader.getSymbolTable().isSystemTable());
assertEquals(0, reader.intValue());
assertNull(reader.next());
reader.close();
}
Aggregations