Search in sources :

Example 26 with ArrayImpl

use of org.teiid.core.types.ArrayImpl in project teiid by teiid.

the class TestSQLXMLProcessing method testXmlTableSequenceArraySingle.

@Test
public void testXmlTableSequenceArraySingle() throws Exception {
    // $NON-NLS-1$
    String sql = "select * from xmltable('/a' passing convert('<a><b>first</b></a>', xml) columns x string[] path 'b') as x";
    List<?>[] expected = new List<?>[] { Arrays.asList(new ArrayImpl("first")) };
    process(sql, expected);
}
Also used : ArrayImpl(org.teiid.core.types.ArrayImpl) List(java.util.List) Test(org.junit.Test)

Example 27 with ArrayImpl

use of org.teiid.core.types.ArrayImpl in project teiid by teiid.

the class TestArray method testArrayValueSerialization.

@SuppressWarnings("unchecked")
@Test
public void testArrayValueSerialization() throws Exception {
    ArrayImpl a1 = new ArrayImpl((Object[]) new Integer[] { 1, null, 3 });
    ArrayImpl a2 = new ArrayImpl((Object[]) null);
    String[] types = TupleBuffer.getTypeNames(Arrays.asList(new Array(Integer.class, null)));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    BatchSerializer.writeBatch(oos, types, Arrays.asList(Arrays.asList(a1), Arrays.asList(a2)));
    oos.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    List<List<Object>> batch = BatchSerializer.readBatch(ois, types);
    assertEquals(a1, batch.get(0).get(0));
    try {
        ((java.sql.Array) batch.get(1).get(0)).getArray();
        fail();
    } catch (SQLException e) {
    }
}
Also used : SQLException(java.sql.SQLException) ArrayImpl(org.teiid.core.types.ArrayImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 28 with ArrayImpl

use of org.teiid.core.types.ArrayImpl in project teiid by teiid.

the class TestArray method testArrayValueToString.

@Test
public void testArrayValueToString() {
    ArrayImpl a1 = new ArrayImpl(new Object[] { 1, "x'2", 3 });
    assertEquals("(1, 'x''2', 3)", SQLStringVisitor.getSQLString(new Constant(a1)));
    a1 = new ArrayImpl((Object[]) new Object[][] { { 1, "x'2" }, { "c" } });
    assertEquals("(('1', 'x''2'), ('c',))", SQLStringVisitor.getSQLString(new Constant(a1)));
}
Also used : ArrayImpl(org.teiid.core.types.ArrayImpl) Test(org.junit.Test)

Example 29 with ArrayImpl

use of org.teiid.core.types.ArrayImpl in project teiid by teiid.

the class TestArray method testSerialize.

@Test
public void testSerialize() throws Exception {
    ArrayImpl a1 = new ArrayImpl((Object[]) new Integer[] { 1, 2, 3 });
    a1 = UnitTestUtil.helpSerialize(a1);
    assertEquals(1, a1.getValues()[0]);
}
Also used : ArrayImpl(org.teiid.core.types.ArrayImpl) Test(org.junit.Test)

Example 30 with ArrayImpl

use of org.teiid.core.types.ArrayImpl in project teiid by teiid.

the class TestArray method testZeroBasedArray.

@Test
public void testZeroBasedArray() throws Exception {
    ArrayImpl a1 = new ArrayImpl((Object[]) new Integer[] { 1, 2, 3 });
    a1.setZeroBased(true);
    assertEquals(2, java.lang.reflect.Array.get(a1.getArray(1, 1), 0));
}
Also used : ArrayImpl(org.teiid.core.types.ArrayImpl) Test(org.junit.Test)

Aggregations

ArrayImpl (org.teiid.core.types.ArrayImpl)31 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)7 List (java.util.List)7 SQLException (java.sql.SQLException)3 Array (org.teiid.query.sql.symbol.Array)3 Constant (org.teiid.query.sql.symbol.Constant)3 IOException (java.io.IOException)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Array (java.sql.Array)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 TransformationException (org.teiid.core.types.TransformationException)2 XMLType (org.teiid.core.types.XMLType)2 ProcedureParameter (org.teiid.metadata.ProcedureParameter)2 LanguageObject (org.teiid.query.sql.LanguageObject)2 Command (org.teiid.query.sql.lang.Command)2 Expression (org.teiid.query.sql.symbol.Expression)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1