use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class FakeDataManager method getQueryGroup.
private GroupSymbol getQueryGroup(Query query) throws TeiidComponentException {
GroupSymbol group;
From from = query.getFrom();
List groups = from.getGroups();
if (groups.size() != 1) {
// $NON-NLS-1$
throw new TeiidComponentException("Cannot build fake tuple source for command: " + query);
}
group = (GroupSymbol) groups.get(0);
Iterator projSymbols = query.getSelect().getProjectedSymbols().iterator();
while (projSymbols.hasNext()) {
Object symbol = projSymbols.next();
if (symbol instanceof ElementSymbol) {
ElementSymbol elementSymbol = (ElementSymbol) symbol;
GroupSymbol g = elementSymbol.getGroupSymbol();
if (!g.equals(group)) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new TeiidComponentException("Illegal symbol " + elementSymbol + " in SELECT of command: " + query);
}
if (elementSymbol.getMetadataID() == null) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new TeiidComponentException("Illegal null metadata ID in ElementSymbol " + elementSymbol + " in SELECT of command: " + query);
} else if (elementSymbol.getMetadataID() instanceof TempMetadataID) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new TeiidComponentException("Illegal TempMetadataID in ElementSymbol " + elementSymbol + " in SELECT of command: " + query);
}
}
}
return group;
}
use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class TestTempTables method testForeignTemp.
@Test
public void testForeignTemp() throws Exception {
HardcodedDataManager hdm = new HardcodedDataManager(metadata);
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
cache.setTupleBufferCache(bm);
dataManager = new TempTableDataManager(hdm, bm, cache);
// $NON-NLS-1$
execute("create foreign temporary table x (e1 string options (nameinsource 'a'), e2 integer, e3 string, primary key (e1)) options (cardinality 1000, updatable true, \"other\" 'prop') on pm1", new List[] { Arrays.asList(0) });
TempMetadataID id = this.tempStore.getMetadataStore().getData().get("x");
// ensure that we're using the actual metadata
assertNotNull(id);
assertNotNull(this.metadata.getPrimaryKey(id));
assertEquals(1000, this.metadata.getCardinality(id), 0);
assertEquals("pm1", this.metadata.getName(this.metadata.getModelID(id)));
assertEquals("prop", this.metadata.getExtensionProperty(id, "other", false));
hdm.addData("SELECT x.a, x.e2, x.e3 FROM x", new List[] { Arrays.asList(1, 2, "3") });
// $NON-NLS-1$
execute("select * from x", new List[] { Arrays.asList(1, 2, "3") });
hdm.addData("SELECT g_0.e2 AS c_0, g_0.e3 AS c_1, g_0.a AS c_2 FROM x AS g_0 ORDER BY c_1, c_0", new List[] { Arrays.asList(2, "3", "1") });
hdm.addData("SELECT g_0.e3, g_0.e2 FROM x AS g_0", new List[] { Arrays.asList("3", 2) });
hdm.addData("DELETE FROM x WHERE x.a = '1'", new List[] { Arrays.asList(1) });
// ensure compensation behaves as if physical - not temp
// $NON-NLS-1$
execute("delete from x where e2 = (select max(e2) from x as z where e3 = x.e3)", new List[] { Arrays.asList(1) }, TestOptimizer.getGenericFinder());
hdm.addData("SELECT g_0.e1 FROM g1 AS g_0, x AS g_1 WHERE g_1.a = g_0.e1", new List[] { Arrays.asList(1) });
// ensure pushdown support
// $NON-NLS-1$
execute("select g1.e1 from pm1.g1 g1, x where x.e1 = g1.e1", new List[] { Arrays.asList(1) }, TestOptimizer.getGenericFinder());
try {
// $NON-NLS-1$
execute("create local temporary table x (e1 string)", new List[] { Arrays.asList(0) });
fail();
} catch (QueryResolverException e) {
}
// ensure that drop works
execute("drop table x", new List[] { Arrays.asList(0) });
try {
execute("drop table x", new List[] { Arrays.asList(0) });
fail();
} catch (QueryResolverException e) {
}
}
use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class TestResolver method testSelectIntoWithNullLiteral.
@Test
public void testSelectIntoWithNullLiteral() {
// $NON-NLS-1$
String sql = "select null as x into #temp from pm1.g1";
Query query = (Query) helpResolve(sql);
TempMetadataStore store = query.getTemporaryMetadata();
// $NON-NLS-1$
TempMetadataID id = store.getTempElementID("#temp.x");
assertEquals(DataTypeManager.DefaultDataClasses.STRING, id.getType());
}
Aggregations