Search in sources :

Example 6 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class TestAuthorizationValidationVisitor method helpTest.

private void helpTest(String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb, DataPolicyMetadata... roles) throws QueryParserException, QueryResolverException, TeiidComponentException {
    QueryParser parser = QueryParser.getQueryParser();
    Command command = parser.parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    DataRolePolicyDecider dataRolePolicyDecider = createPolicyDecider(metadata, vdb, roles);
    // $NON-NLS-1$
    AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(dataRolePolicyDecider, context);
    ValidatorReport report = Validator.validate(command, metadata, visitor);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        // strings
        Set<String> expected = new HashSet<String>(Arrays.asList(expectedInaccesible));
        // elements
        Set<String> actual = new HashSet<String>();
        for (LanguageObject obj : firstFailure.getInvalidObjects()) {
            if (obj instanceof ElementSymbol) {
                actual.add(((ElementSymbol) obj).getName());
            } else {
                actual.add(obj.toString());
            }
        }
        assertEquals(expected, actual);
    } else if (expectedInaccesible.length > 0) {
        // $NON-NLS-1$
        fail("Expected inaccessible objects, but got none.");
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) ValidatorReport(org.teiid.query.validator.ValidatorReport) LanguageObject(org.teiid.query.sql.LanguageObject) HashSet(java.util.HashSet)

Example 7 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class TestSTree method testOrderedInsert.

@Test
public void testOrderedInsert() throws TeiidComponentException {
    BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
    bm.setProcessorBatchSize(4);
    ElementSymbol e1 = new ElementSymbol("x");
    e1.setType(Integer.class);
    List<ElementSymbol> elements = Arrays.asList(e1);
    STree map = bm.createSTree(elements, "1", 1);
    int size = (1 << 16) + (1 << 4) + 1;
    for (int i = 0; i < size; i++) {
        assertNull(map.insert(Arrays.asList(i), InsertMode.ORDERED, size));
        assertEquals(i + 1, map.getRowCount());
    }
    assertEquals(4, map.getHeight());
    for (int i = 0; i < size; i++) {
        assertNotNull(map.remove(Arrays.asList(i)));
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) Test(org.junit.Test)

Example 8 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class TestSTree method testUnOrderedInsert.

@Test
public void testUnOrderedInsert() throws TeiidComponentException {
    BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
    bm.setProcessorBatchSize(16);
    ElementSymbol e1 = new ElementSymbol("x");
    e1.setType(Integer.class);
    List elements = Arrays.asList(e1);
    STree map = bm.createSTree(elements, "1", 1);
    int size = (1 << 16) + (1 << 4) + 1;
    int logSize = map.getExpectedHeight(size);
    for (int i = 0; i < size; i++) {
        assertNull(map.insert(Arrays.asList(i), InsertMode.NEW, logSize));
        assertEquals(i + 1, map.getRowCount());
    }
    assertTrue(5 >= map.getHeight());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) List(java.util.List) Test(org.junit.Test)

Example 9 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class TestSTree method testSearch.

@Test
public void testSearch() throws TeiidComponentException, TeiidProcessingException {
    // due to buffering changes we need to hold this in memory directly rather than serialize it out as that will lead to GC overhead errors
    BufferManagerImpl bm = BufferManagerFactory.getTestBufferManager(Integer.MAX_VALUE, 1);
    ElementSymbol e1 = new ElementSymbol("x");
    e1.setType(Integer.class);
    ElementSymbol e2 = new ElementSymbol("x");
    e2.setType(Integer.class);
    List elements = Arrays.asList(e1, e2);
    STree map = bm.createSTree(elements, "1", 2);
    int size = 1 << 16;
    for (int i = 0; i < size; i++) {
        assertNull(map.insert(Arrays.asList(i, i), InsertMode.NEW, -1));
        assertEquals(i + 1, map.getRowCount());
    }
    map.compact();
    for (int i = 0; i < size; i++) {
        TupleBrowser tb = new TupleBrowser(map, new CollectionTupleSource(Collections.singletonList(Arrays.asList(i)).iterator()), true);
        assertNotNull(tb.nextTuple());
        assertNull(tb.nextTuple());
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) List(java.util.List) Test(org.junit.Test)

Example 10 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class TestSTree method testSearchWithRepeated.

@Test
public void testSearchWithRepeated() throws TeiidComponentException, TeiidProcessingException {
    // due to buffering changes we need to hold this in memory directly rather than serialize it out as that will lead to GC overhead errors
    BufferManagerImpl bm = BufferManagerFactory.getTestBufferManager(Integer.MAX_VALUE, 1);
    ElementSymbol e1 = new ElementSymbol("x");
    e1.setType(Integer.class);
    ElementSymbol e2 = new ElementSymbol("x");
    e2.setType(Integer.class);
    List<ElementSymbol> elements = Arrays.asList(e1, e2);
    STree map = bm.createSTree(elements, "1", 2);
    int size = 1 << 16;
    for (int i = 0; i < size; i++) {
        assertNull(map.insert(Arrays.asList(i, i * 2), InsertMode.NEW, -1));
        assertNull(map.insert(Arrays.asList(i, i * 2 + 1), InsertMode.NEW, -1));
        assertEquals((i + 1) * 2, map.getRowCount());
    }
    map.compact();
    for (int i = 0; i < size; i++) {
        TupleBrowser tb = new TupleBrowser(map, new CollectionTupleSource(Collections.singletonList(Arrays.asList(i)).iterator()), true);
        for (int j = 0; j < 2; j++) {
            assertNotNull(tb.nextTuple());
        }
        assertNull(tb.nextTuple());
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) Test(org.junit.Test)

Aggregations

ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)417 ArrayList (java.util.ArrayList)165 Test (org.junit.Test)157 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)148 Expression (org.teiid.query.sql.symbol.Expression)104 List (java.util.List)103 Constant (org.teiid.query.sql.symbol.Constant)94 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)41 SymbolMap (org.teiid.query.sql.util.SymbolMap)40 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)36 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)29 Map (java.util.Map)28 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)28 Query (org.teiid.query.sql.lang.Query)26 HashMap (java.util.HashMap)25 Select (org.teiid.query.sql.lang.Select)24 BufferManager (org.teiid.common.buffer.BufferManager)22 Criteria (org.teiid.query.sql.lang.Criteria)22 LinkedList (java.util.LinkedList)20 TupleBuffer (org.teiid.common.buffer.TupleBuffer)19