Search in sources :

Example 21 with ArrayImpl

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

the class BaseIndexInfo method buildSearchRow.

private void buildSearchRow(int i, Object match, Object value2, List<Object> toSearch) {
    if (toSearch.size() != i) {
        return;
    }
    if (value2 instanceof ArrayImpl && match instanceof int[]) {
        int[] indexes = (int[]) match;
        ArrayImpl array = (ArrayImpl) value2;
        Object[] arrayVals = array.getValues();
        for (int j = 0; j < indexes.length; j++) {
            int index = indexes[j];
            if (index == -1) {
                break;
            }
            toSearch.add(arrayVals[index]);
        }
    } else {
        toSearch.add(value2);
    }
}
Also used : ArrayImpl(org.teiid.core.types.ArrayImpl)

Example 22 with ArrayImpl

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

the class TestArrayProcessing method testMultiDimensionalCast.

@Test
public void testMultiDimensionalCast() throws Exception {
    // $NON-NLS-1$
    String sql = "select cast( ((e2, e2), (e2, e2)) as object[])  from pm1.g1";
    QueryResolver.resolveCommand(helpParse(sql), RealMetadataFactory.example1Cached());
    Command command = helpResolve(sql, RealMetadataFactory.example1Cached());
    assertEquals(Object[].class, command.getProjectedSymbols().get(0).getType());
    ProcessorPlan pp = TestProcessor.helpGetPlan(command, RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.e2 FROM pm1.g1 AS g_0", Arrays.asList(1), Arrays.asList(2));
    TestProcessor.helpProcess(pp, dataManager, new List[] { Arrays.asList(new ArrayImpl((Object[]) new Integer[][] { new Integer[] { 1, 1 }, new Integer[] { 1, 1 } })), Arrays.asList(new ArrayImpl((Object[]) new Integer[][] { new Integer[] { 2, 2 }, new Integer[] { 2, 2 } })) });
    // $NON-NLS-1$
    sql = "select cast(cast( ((e2, e2), (e2, e2)) as object[]) as integer[][])  from pm1.g1";
    QueryResolver.resolveCommand(helpParse(sql), RealMetadataFactory.example1Cached());
    command = helpResolve(sql, RealMetadataFactory.example1Cached());
    assertEquals(Integer[][].class, command.getProjectedSymbols().get(0).getType());
}
Also used : Command(org.teiid.query.sql.lang.Command) ArrayImpl(org.teiid.core.types.ArrayImpl) Test(org.junit.Test)

Example 23 with ArrayImpl

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

the class TestArrayProcessing method testNestedArrayAgg.

@Test
public void testNestedArrayAgg() throws Exception {
    // $NON-NLS-1$
    String sql = "select array_agg((e1, e2)) from pm1.g1";
    Command command = helpParse(sql);
    ProcessorPlan pp = TestProcessor.helpGetPlan(command, RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0", Arrays.asList("a", 1), Arrays.asList("c", 2));
    TestProcessor.helpProcess(pp, dataManager, new List[] { Arrays.asList(new ArrayImpl(new Object[] { "a", 1 }, new Object[] { "c", 2 })) });
}
Also used : Command(org.teiid.query.sql.lang.Command) ArrayImpl(org.teiid.core.types.ArrayImpl) Test(org.junit.Test)

Example 24 with ArrayImpl

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

the class TestProcedureProcessor method testVariadicParameterOrdering.

@Test
public void testVariadicParameterOrdering() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE PROCEDURE p1(VARIADIC parameters integer) returns integer[] AS BEGIN " + "return parameters; END;", "x", "y");
    StringBuilder sql = new StringBuilder("exec p1(0");
    // dependent upon the jre.  this is suffient to trigger the issue on oracle 1.8
    int arraySize = 66000;
    for (int i = 1; i < arraySize; i++) {
        sql.append(',').append(i);
    }
    sql.append(')');
    ProcessorPlan plan = helpGetPlan(sql.toString(), metadata);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(metadata);
    Integer[] val = new Integer[arraySize];
    for (int i = 0; i < val.length; i++) {
        val[i] = i;
    }
    ArrayImpl expected = new ArrayImpl(val);
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    helpProcess(plan, cc, hdm, new List[] { Arrays.asList(expected) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ArrayImpl(org.teiid.core.types.ArrayImpl) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 25 with ArrayImpl

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

the class TestSQLXMLProcessing method testXmlTableSequenceArray.

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