use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestArrayProcessing method testArrayEquivalence.
@Test
public void testArrayEquivalence() throws Exception {
Array a1 = new Array(new ArrayList<Expression>());
UnitTestUtil.helpTestEquivalence(0, a1, a1);
Array a2 = new Array(Arrays.asList((Expression) new Constant(1)));
UnitTestUtil.helpTestEquivalence(1, a1, a2);
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestOptionsAndHints method testDepOptions2.
@Test
public void testDepOptions2() {
// $NON-NLS-1$
GroupSymbol a = new GroupSymbol("a");
// $NON-NLS-1$
GroupSymbol b = new GroupSymbol("b");
// $NON-NLS-1$
ElementSymbol x = new ElementSymbol("a.x", true);
// $NON-NLS-1$
ElementSymbol y = new ElementSymbol("b.y", true);
// $NON-NLS-1$
Criteria criteria = new CompareCriteria(x, CompareCriteria.EQ, new Function("func", new Expression[] { y }));
JoinPredicate predicate = new JoinPredicate(new UnaryFromClause(a), new UnaryFromClause(b), JoinType.JOIN_INNER, Arrays.asList(new Object[] { criteria }));
From from = new From(Arrays.asList(predicate));
predicate.getLeftClause().setMakeNotDep(true);
predicate.getRightClause().setMakeDep(true);
Select select = new Select(Arrays.asList(x, y));
Query query = new Query(select, from, null, null, null, null, null);
// $NON-NLS-1$
TestParser.helpTest(// $NON-NLS-1$
"Select a.x, b.y From a MAKENOTDEP INNER JOIN b MAKEDEP ON a.x = func(b.y)", // $NON-NLS-1$
"SELECT a.x, b.y FROM /*+ MAKENOTDEP */ a INNER JOIN /*+ MAKEDEP */ b ON a.x = func(b.y)", query);
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestArrayProcessing method testMultiDimensionalArrayRewrite.
@Test
public void testMultiDimensionalArrayRewrite() throws Exception {
// $NON-NLS-1$
String sql = "select (('a', 'b'),('c','d'))";
QueryResolver.resolveCommand(helpParse(sql), RealMetadataFactory.example1Cached());
Command command = helpResolve(sql, RealMetadataFactory.example1Cached());
assertEquals(String[][].class, command.getProjectedSymbols().get(0).getType());
command = QueryRewriter.rewrite(command, RealMetadataFactory.example1Cached(), null);
Expression ex = SymbolMap.getExpression(command.getProjectedSymbols().get(0));
Constant c = (Constant) ex;
assertTrue(c.getValue() instanceof ArrayImpl);
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestEnginePerformance method helpTestLike.
private void helpTestLike(int iterations, int threads) throws QueryParserException, InterruptedException, Exception {
final Expression ex = QueryParser.getQueryParser().parseExpression("'abcdefg' like 'a%g'");
runTask(iterations, threads, new Task() {
@Override
public Void call() throws Exception {
Evaluator.evaluate(ex);
return null;
}
});
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class GlobalTableStoreImpl method getGlobalTempTableMetadataId.
@Override
public TempMetadataID getGlobalTempTableMetadataId(Object viewId) throws TeiidProcessingException, TeiidComponentException {
String matViewName = metadata.getFullName(viewId);
String matTableName = RelationalPlanner.MAT_PREFIX + matViewName.toUpperCase();
GroupSymbol group = new GroupSymbol(matViewName);
group.setMetadataID(viewId);
TempMetadataID id = tableStore.getMetadataStore().getTempGroupID(matTableName);
// define the table preserving the key/index information and ensure that only a single instance exists
if (id == null) {
synchronized (viewId) {
id = tableStore.getMetadataStore().getTempGroupID(matTableName);
LinkedHashMap<Expression, Integer> newExprs = null;
if (id == null) {
List<ElementSymbol> allCols = ResolverUtil.resolveElementsInGroup(group, metadata);
QueryNode qnode = metadata.getVirtualPlan(viewId);
if (viewId instanceof Table) {
Table t = (Table) viewId;
List<KeyRecord> fbis = t.getFunctionBasedIndexes();
if (!fbis.isEmpty()) {
List<GroupSymbol> groups = Arrays.asList(group);
int i = 0;
newExprs = new LinkedHashMap<Expression, Integer>();
for (KeyRecord keyRecord : fbis) {
for (int j = 0; j < keyRecord.getColumns().size(); j++) {
Column c = keyRecord.getColumns().get(j);
if (c.getParent() != keyRecord) {
continue;
}
String exprString = c.getNameInSource();
Expression ex = QueryParser.getQueryParser().parseExpression(exprString);
Integer index = newExprs.get(ex);
if (index == null) {
ResolverVisitor.resolveLanguageObject(ex, groups, metadata);
ex = QueryRewriter.rewriteExpression(ex, null, metadata);
String colName = TEIID_FBI + i;
while (t.getColumnByName(colName) != null) {
colName = TEIID_FBI + (++i);
}
ElementSymbol es = new ElementSymbol(colName);
es.setType(ex.getType());
allCols.add(es);
c.setPosition(allCols.size());
newExprs.put(ex, allCols.size());
ex = (Expression) ex.clone();
} else {
c.setPosition(index);
}
}
}
ResolverUtil.clearGroupInfo(group, metadata);
// $NON-NLS-1$
StringBuilder query = new StringBuilder("SELECT ");
// $NON-NLS-1$
query.append(group).append(".*, ");
for (Iterator<Expression> iter = newExprs.keySet().iterator(); iter.hasNext(); ) {
query.append(iter.next());
if (iter.hasNext()) {
// $NON-NLS-1$
query.append(", ");
}
}
// $NON-NLS-1$ //$NON-NLS-2$
query.append(" FROM ").append(group).append(" option nocache ").append(group);
qnode = new QueryNode(query.toString());
}
}
id = tableStore.getMetadataStore().addTempGroup(matTableName, allCols, false, true);
id.setQueryNode(qnode);
id.setCardinality((int) metadata.getCardinality(viewId));
id.setOriginalMetadataID(viewId);
Object pk = metadata.getPrimaryKey(viewId);
if (pk != null) {
ArrayList<TempMetadataID> primaryKey = resolveIndex(metadata, id, pk);
id.setPrimaryKey(primaryKey);
}
Collection keys = metadata.getUniqueKeysInGroup(viewId);
for (Object key : keys) {
id.addUniqueKey(resolveIndex(metadata, id, key));
}
Collection indexes = metadata.getIndexesInGroup(viewId);
for (Object index : indexes) {
id.addIndex(index, resolveIndex(metadata, id, index));
}
if (newExprs != null) {
Table table = (Table) viewId;
List<KeyRecord> fbis = table.getFunctionBasedIndexes();
for (KeyRecord keyRecord : fbis) {
id.addIndex(keyRecord, resolveIndex(metadata, id, keyRecord));
}
GroupSymbol gs = new GroupSymbol(matTableName);
gs.setMetadataID(id);
SymbolMap map = SymbolMap.createSymbolMap(group, ResolverUtil.resolveElementsInGroup(gs, metadata).subList(0, allCols.size() - newExprs.size()), metadata);
LinkedHashMap<Expression, Integer> mappedExprs = new LinkedHashMap<Expression, Integer>();
for (Map.Entry<Expression, Integer> entry : newExprs.entrySet()) {
Expression ex = (Expression) entry.getKey().clone();
ExpressionMappingVisitor.mapExpressions(ex, map.asMap());
mappedExprs.put(ex, entry.getValue());
}
id.getTableData().setFunctionBasedExpressions(mappedExprs);
}
}
}
}
updateCacheHint(viewId, group, id);
return id;
}
Aggregations