Search in sources :

Example 86 with Expression

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);
}
Also used : Array(org.teiid.query.sql.symbol.Array) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 87 with Expression

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Test(org.junit.Test)

Example 88 with Expression

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);
}
Also used : Command(org.teiid.query.sql.lang.Command) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayImpl(org.teiid.core.types.ArrayImpl) Test(org.junit.Test)

Example 89 with Expression

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;
        }
    });
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException) BlockedException(org.teiid.common.buffer.BlockedException) QueryParserException(org.teiid.api.exception.query.QueryParserException) IOException(java.io.IOException)

Example 90 with Expression

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;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) TempMetadataID(org.teiid.query.metadata.TempMetadataID) SymbolMap(org.teiid.query.sql.util.SymbolMap) CacheHint(org.teiid.query.sql.lang.CacheHint) LinkedHashMap(java.util.LinkedHashMap) KeyRecord(org.teiid.metadata.KeyRecord) Expression(org.teiid.query.sql.symbol.Expression) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Collection(java.util.Collection) ReplicatedObject(org.teiid.query.ReplicatedObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Aggregations

Expression (org.teiid.query.sql.symbol.Expression)257 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)104 ArrayList (java.util.ArrayList)74 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)54 Test (org.junit.Test)53 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 List (java.util.List)49 Constant (org.teiid.query.sql.symbol.Constant)38 SymbolMap (org.teiid.query.sql.util.SymbolMap)37 HashMap (java.util.HashMap)22 LinkedList (java.util.LinkedList)22 Criteria (org.teiid.query.sql.lang.Criteria)22 Map (java.util.Map)21 ClobType (org.teiid.core.types.ClobType)16 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)16 HashSet (java.util.HashSet)13 LinkedHashSet (java.util.LinkedHashSet)13 AliasSymbol (org.teiid.query.sql.symbol.AliasSymbol)13 SearchedCaseExpression (org.teiid.query.sql.symbol.SearchedCaseExpression)13 OrderBy (org.teiid.query.sql.lang.OrderBy)12