Search in sources :

Example 56 with Query

use of org.teiid.query.sql.lang.Query in project teiid by teiid.

the class UpdateValidator method validate.

public void validate(Command command, List<ElementSymbol> viewSymbols) throws QueryMetadataException, TeiidComponentException {
    if (this.updateInfo.deleteType != UpdateType.INHERENT && this.updateInfo.updateType != UpdateType.INHERENT && this.updateInfo.insertType != UpdateType.INHERENT) {
        return;
    }
    if (command instanceof SetQuery) {
        SetQuery setQuery = (SetQuery) command;
        if (setQuery.getLimit() != null) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0013"), true, true, true);
            return;
        }
        LinkedList<Query> queries = new LinkedList<Query>();
        if (!PartitionAnalyzer.extractQueries((SetQuery) command, queries)) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001"), true, true, true);
            return;
        }
        Map<ElementSymbol, List<Set<Constant>>> partitions = PartitionAnalyzer.extractPartionInfo((SetQuery) command, viewSymbols);
        this.updateInfo.partitionInfo = partitions;
        if (partitions.isEmpty()) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0018"), false, true, false);
        }
        boolean first = true;
        for (Query query : queries) {
            UpdateInfo ui = this.updateInfo;
            if (!first) {
                this.updateInfo = new UpdateInfo();
                this.updateInfo.deleteType = ui.deleteType;
                this.updateInfo.insertType = ui.insertType;
                this.updateInfo.updateType = ui.updateType;
            }
            internalValidate(query, viewSymbols);
            // accumulate the errors on the first branch - will be checked at resolve time
            if (this.updateInfo.getDeleteValidationError() != null) {
                ui.setDeleteValidationError(this.updateInfo.getDeleteValidationError());
            }
            if (this.updateInfo.getUpdateValidationError() != null) {
                ui.setUpdateValidationError(this.updateInfo.getUpdateValidationError());
            }
            if (this.updateInfo.getInsertValidationError() != null) {
                ui.setInsertValidationError(this.updateInfo.getInsertValidationError());
            }
            if (!first) {
                ui.unionBranches.add(this.updateInfo);
                this.updateInfo = ui;
            } else {
                first = false;
            }
        }
        return;
    }
    internalValidate(command, viewSymbols);
    if (this.updateInfo.deleteType != UpdateType.INHERENT) {
        this.deleteReport.getItems().clear();
        this.updateInfo.deleteValidationError = null;
    }
    if (this.updateInfo.updateType != UpdateType.INHERENT) {
        this.updateReport.getItems().clear();
        this.updateInfo.updateValidationError = null;
    }
    if (this.updateInfo.insertType != UpdateType.INHERENT) {
        this.insertReport.getItems().clear();
        this.updateInfo.insertValidationError = null;
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SetQuery(org.teiid.query.sql.lang.SetQuery) SetQuery(org.teiid.query.sql.lang.SetQuery) Query(org.teiid.query.sql.lang.Query) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 57 with Query

use of org.teiid.query.sql.lang.Query in project teiid by teiid.

the class TestCachedResults method testCaching.

@Test
public void testCaching() throws Exception {
    FakeBufferService fbs = new FakeBufferService(true);
    // $NON-NLS-1$
    ElementSymbol x = new ElementSymbol("x");
    x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List<ElementSymbol> schema = Arrays.asList(x);
    // $NON-NLS-1$
    TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR);
    tb.setForwardOnly(false);
    tb.addTuple(Arrays.asList(1));
    tb.addTuple(Arrays.asList(2));
    tb.addTuple(Arrays.asList(3));
    tb.addTuple(Arrays.asList(4));
    tb.addTuple(Arrays.asList(5));
    tb.addTuple(Arrays.asList(6));
    tb.addTuple(Arrays.asList(7));
    tb.addTuple(Arrays.asList(8));
    tb.addTuple(Arrays.asList(9));
    tb.addTuple(Arrays.asList(10));
    tb.close();
    BufferManager bm = fbs.getBufferManager();
    CachedResults results = new CachedResults();
    ProcessorPlan plan = new FakeProcessorPlan(0);
    CommandContext cc = new CommandContext();
    Table t = RealMetadataFactory.exampleBQT().getGroupID("bqt1.smalla");
    cc.accessedDataObject(t);
    plan.setContext(cc);
    results.setResults(tb, plan);
    results.setCommand(new Query());
    // Cache cache = new DefaultCache("dummy"); //$NON-NLS-1$
    long ts = results.getAccessInfo().getCreationTime();
    // in cache
    for (int row = 1; row <= tb.getRowCount(); row += 4) {
    // cache.put(results.getId()+","+row, tb.getBatch(row), null); //$NON-NLS-1$
    }
    results.prepare(bm);
    // simulate distribute
    TupleBuffer distributedTb = bm.getTupleBuffer(results.getId());
    CachedResults cachedResults = UnitTestUtil.helpSerialize(results);
    RealMetadataFactory.buildWorkContext(RealMetadataFactory.exampleBQT());
    BufferManager bm2 = fbs.getBufferManager();
    bm2.distributeTupleBuffer(results.getId(), distributedTb);
    assertTrue(cachedResults.restore(bm2));
    // since restored, simulate a async cache flush
    // cache.clear();
    TupleBuffer cachedTb = cachedResults.getResults();
    assertTrue(cachedTb.isFinal());
    assertEquals(tb.getRowCount(), cachedTb.getRowCount());
    assertEquals(tb.getBatchSize(), cachedTb.getBatchSize());
    assertArrayEquals(tb.getBatch(1).getAllTuples(), cachedTb.getBatch(1).getAllTuples());
    assertArrayEquals(tb.getBatch(9).getAllTuples(), cachedTb.getBatch(9).getAllTuples());
    assertTrue(ts - cachedResults.getAccessInfo().getCreationTime() <= 5000);
// ensure that an incomplete load fails ( is this still valid use case?)
// bm2.getTupleBuffer(results.getId()).remove();
// cachedResults = UnitTestUtil.helpSerialize(results);
// assertFalse(cachedResults.restore(cache, bm2));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) Query(org.teiid.query.sql.lang.Query) TupleBuffer(org.teiid.common.buffer.TupleBuffer) FakeBufferService(org.teiid.dqp.service.FakeBufferService) BufferManager(org.teiid.common.buffer.BufferManager) FakeProcessorPlan(org.teiid.query.processor.FakeProcessorPlan) FakeProcessorPlan(org.teiid.query.processor.FakeProcessorPlan) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 58 with Query

use of org.teiid.query.sql.lang.Query in project teiid by teiid.

the class TestAliasGenerator method testOrderBySymbolName.

@Test
public void testOrderBySymbolName() throws Exception {
    // $NON-NLS-1$
    String sql = "select e1 from pm1.g1 order by e1";
    // $NON-NLS-1$
    String expected = "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0";
    Query command = (Query) helpTest(sql, expected, true, false, RealMetadataFactory.example1Cached());
    // $NON-NLS-1$
    assertEquals(((Symbol) command.getOrderBy().getSortKeys().get(0)).getName(), "c_0");
    // $NON-NLS-1$
    assertEquals(((Symbol) command.getProjectedSymbols().get(0)).getShortName(), "c_0");
}
Also used : Query(org.teiid.query.sql.lang.Query) Test(org.junit.Test)

Example 59 with Query

use of org.teiid.query.sql.lang.Query in project teiid by teiid.

the class TestScalarSubqueryImpl method helpExample.

public static org.teiid.query.sql.symbol.ScalarSubquery helpExample() {
    Query query = TestQueryImpl.helpExample(true);
    org.teiid.query.sql.symbol.ScalarSubquery ss = new org.teiid.query.sql.symbol.ScalarSubquery(query);
    ss.setType(((Expression) query.getProjectedSymbols().get(0)).getType());
    return ss;
}
Also used : Query(org.teiid.query.sql.lang.Query) ScalarSubquery(org.teiid.language.ScalarSubquery) ScalarSubquery(org.teiid.language.ScalarSubquery)

Example 60 with Query

use of org.teiid.query.sql.lang.Query in project teiid by teiid.

the class TestRulePlaceAccess method testAddAccessPatterns2.

/**
 * Tests that any access patterns (a Collection of Collections of
 * Object element ids) for a physical group will be found and added
 * as a property of an ACCESS node.
 */
public void testAddAccessPatterns2() throws Exception {
    Query query = new Query();
    From from = new From();
    // $NON-NLS-1$
    GroupSymbol group = new GroupSymbol("pm4.g2");
    from.addGroup(group);
    query.setFrom(from);
    Select select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    query.setSelect(select);
    // $NON-NLS-1$
    group.setMetadataID(METADATA.getGroupID("pm4.g2"));
    PlanNode n1 = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
    n1.setProperty(NodeConstants.Info.ATOMIC_REQUEST, query);
    n1.addGroup(group);
    RulePlaceAccess.addAccessPatternsProperty(n1, METADATA);
    Collection accessPatterns = (Collection) n1.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
    assertNotNull(accessPatterns);
    // $NON-NLS-1$
    assertTrue("Expected two access patterns, got " + accessPatterns.size(), accessPatterns.size() == 2);
}
Also used : MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) Query(org.teiid.query.sql.lang.Query) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Select(org.teiid.query.sql.lang.Select) Collection(java.util.Collection) From(org.teiid.query.sql.lang.From)

Aggregations

Query (org.teiid.query.sql.lang.Query)97 Test (org.junit.Test)58 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)31 Select (org.teiid.query.sql.lang.Select)30 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)26 From (org.teiid.query.sql.lang.From)25 Constant (org.teiid.query.sql.symbol.Constant)22 SetQuery (org.teiid.query.sql.lang.SetQuery)21 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)20 UnaryFromClause (org.teiid.query.sql.lang.UnaryFromClause)13 Limit (org.teiid.query.sql.lang.Limit)10 ArrayList (java.util.ArrayList)9 Expression (org.teiid.query.sql.symbol.Expression)9 SQLException (java.sql.SQLException)7 Reference (org.teiid.query.sql.symbol.Reference)7 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)6 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)5 List (java.util.List)4 ODataLibraryException (org.apache.olingo.server.api.ODataLibraryException)4 TeiidProcessingException (org.teiid.core.TeiidProcessingException)4