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;
}
}
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));
}
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");
}
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;
}
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);
}
Aggregations