Search in sources :

Example 31 with IonStruct

use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.

the class IonGeneratorTest method testTreeWriteVerifiesOnce.

@Test
public void testTreeWriteVerifiesOnce() throws Exception {
    final String FIELD = "field";
    // We can test this by writing into a context where only a single object can be written
    joiGenerator.writeStartObject();
    joiGenerator.writeName(FIELD);
    joiGenerator.writeTree(testObjectTree);
    joiGenerator.writeEndObject();
    // to try to trigger [dataformats-binary#248]
    joiGenerator.close();
    joiGenerator.close();
    final IonStruct struct = (IonStruct) output.get(0);
    assertThat(struct.get(FIELD), is(testObjectIon));
}
Also used : IonStruct(com.amazon.ion.IonStruct) Test(org.junit.Test)

Example 32 with IonStruct

use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.

the class IonGeneratorTest method testObjectWriteVerifiesOnce.

@Test
public void testObjectWriteVerifiesOnce() throws Exception {
    final String FIELD = "field";
    // We can test this by writing into a context where only a single object can be written
    joiGenerator.writeStartObject();
    joiGenerator.writeName(FIELD);
    joiGenerator.writePOJO(testObject);
    joiGenerator.writeEndObject();
    final IonStruct struct = (IonStruct) output.get(0);
    assertThat(struct.get(FIELD), is(testObjectIon));
}
Also used : IonStruct(com.amazon.ion.IonStruct) Test(org.junit.Test)

Example 33 with IonStruct

use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.

the class SimpleIonWriteTest method initializeExpectedDatagram.

@Before
public void initializeExpectedDatagram() {
    IonStruct struct = ion.newEmptyStruct();
    struct.add("a").newString("value");
    struct.add("b").newInt(42);
    struct.add("c").newNull(IonType.INT);
    expected = ion.newDatagram();
    expected.add(struct);
}
Also used : IonStruct(com.amazon.ion.IonStruct) Before(org.junit.Before)

Example 34 with IonStruct

use of com.amazon.ion.IonStruct in project jackson-dataformats-binary by FasterXML.

the class DataBindWriteTest method initializeExpectedMyBean.

@Before
public void initializeExpectedMyBean() {
    expectedMyBean = ion.newDatagram();
    IonStruct struct = ion.newEmptyStruct();
    struct.add("a").newString("value");
    struct.add("b").newInt(42);
    expectedMyBean = ion.newDatagram();
    expectedMyBean.add(struct);
}
Also used : IonStruct(com.amazon.ion.IonStruct) Before(org.junit.Before)

Example 35 with IonStruct

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

the class IonHiveSerDe method deserialize.

@Override
public Object deserialize(final Writable blob) throws SerDeException {
    final byte[] bytes;
    final int length;
    // TextFormat which produces Text
    if (blob instanceof Text) {
        Text text = (Text) blob;
        // getBytes returns a reference to the current buffer which is only valid up to length
        bytes = text.getBytes();
        length = text.getLength();
    } else if (blob instanceof BytesWritable) {
        BytesWritable bytesWritable = (BytesWritable) blob;
        // getBytes returns a reference to the current buffer which is only valid up to length
        bytes = bytesWritable.getBytes();
        length = bytesWritable.getLength();
    } else {
        throw new SerDeException("Invalid Writable instance, must be either Text or BytesWritable, was " + blob.getClass());
    }
    final IonSystem domFactory = ionFactory.getDomFactory();
    try (final IonReader reader = ionFactory.newReader(bytes, 0, length)) {
        /*
                We're using an IonStruct here because:
                1. We need a key-value store to carry column values
                2. The top-level IonStruct as a context object carries the IonSystem which we use as a ValueFactory in
                   the callbacks created in PathExtractionConfig
                Refer to https://github.com/amzn/ion-hive-serde/issues/61.
            */
        IonStruct struct = domFactory.newEmptyStruct();
        if (!serDeProperties.pathExtractorCaseSensitivity()) {
            struct = new IonStructCaseInsensitiveDecorator(struct);
        }
        final PathExtractor<IonStruct> pathExtractor = serDeProperties.pathExtractor();
        pathExtractor.match(reader, struct);
        return struct;
    } catch (IonException e) {
        // skips if ignoring malformed
        if (serDeProperties.getIgnoreMalformed()) {
            return null;
        }
        throw e;
    } catch (IOException e) {
        throw new SerDeException(e);
    }
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) IonException(com.amazon.ion.IonException) IonReader(com.amazon.ion.IonReader) IonStructCaseInsensitiveDecorator(com.amazon.ionhiveserde.caseinsensitivedecorator.IonStructCaseInsensitiveDecorator) Text(org.apache.hadoop.io.Text) BytesWritable(org.apache.hadoop.io.BytesWritable) IOException(java.io.IOException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Aggregations

IonStruct (com.amazon.ion.IonStruct)68 Test (org.junit.Test)28 IonValue (com.amazon.ion.IonValue)18 IonDatagram (com.amazon.ion.IonDatagram)13 IonList (com.amazon.ion.IonList)13 IonReader (com.amazon.ion.IonReader)13 SymbolTable (com.amazon.ion.SymbolTable)13 IOException (java.io.IOException)8 IonString (com.amazon.ion.IonString)7 IonSystem (com.amazon.ion.IonSystem)6 IonException (com.amazon.ion.IonException)5 IonSequence (com.amazon.ion.IonSequence)5 IonType (com.amazon.ion.IonType)5 IonFloat (com.amazon.ion.IonFloat)4 IonSymbol (com.amazon.ion.IonSymbol)4 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonWriter (com.amazon.ion.IonWriter)4 SymbolToken (com.amazon.ion.SymbolToken)4 ArrayList (java.util.ArrayList)4 IonBlob (com.amazon.ion.IonBlob)3