Package org.teiid.query.mapping.relational

Examples of org.teiid.query.mapping.relational.QueryNode


        for (Iterator i = resultSets.iterator(); i.hasNext();) {
            MappingSourceNode rsNode = (MappingSourceNode)i.next();
           
            ResultSetInfo childRsInfo = rsNode.getResultSetInfo();
           
            QueryNode planNode = QueryUtil.getQueryNode(childRsInfo.getResultSetName(), planEnv.getGlobalMetadata());   
            Command command = QueryUtil.getQuery(childRsInfo.getResultSetName(), planNode, planEnv);
           
            String inlineViewName = planEnv.getAliasName(childRsInfo.getResultSetName());
           
            updateSymbolMap(symbolMap, childRsInfo.getResultSetName(), inlineViewName, planEnv.getGlobalMetadata());
           
            // check if the criteria has been raised, if it is then we can update this as a join.
            if (childRsInfo.isCriteriaRaised()) {
                Query transformationQuery = (Query) command;
                SubqueryFromClause sfc = (SubqueryFromClause)transformationQuery.getFrom().getClauses().get(0);
               
                Criteria joinCriteria = ((Query)childRsInfo.getCommand()).getCriteria();
               
                if (joinCriteria == null) {
                    joinCriteria = QueryRewriter.TRUE_CRITERIA;
                }
               
                joinCriteria = (Criteria)joinCriteria.clone();
               
                //update the from clause
                FromClause clause = (FromClause)currentQuery.getFrom().getClauses().remove(0);
               
                JoinPredicate join = null;
               
                if (clause instanceof JoinPredicate) {
                    join = (JoinPredicate)clause;
                   
                    FromClause right = join.getRightClause();
                   
                    JoinPredicate newRight = new JoinPredicate(right, sfc, JoinType.JOIN_LEFT_OUTER, Criteria.separateCriteriaByAnd(joinCriteria));
                   
                    join.setRightClause(newRight);
                } else {
                    join = new JoinPredicate(clause, sfc, JoinType.JOIN_LEFT_OUTER, Criteria.separateCriteriaByAnd(joinCriteria));
                }
               
                currentQuery.getFrom().addClause(join);
               
                currentQuery.getSelect().setDistinct(true);
               
                continue;
            }
           
            if (!singleParentage) {
                throw new QueryPlannerException(QueryPlugin.Util.getString("XMLQueryPlanner.cannot_plan", rsInfo.getCriteria())); //$NON-NLS-1$
            }
           
            Query subQuery = QueryUtil.wrapQuery(new SubqueryFromClause(inlineViewName, command), inlineViewName);

            currentQuery.setCriteria(Criteria.combineCriteria(currentQuery.getCriteria(), new ExistsCriteria(subQuery)));
           
            currentQuery = subQuery;
        }
       
        Criteria userCrit = (Criteria)rsInfo.getCriteria().clone();
       
        currentQuery.setCriteria(Criteria.combineCriteria(currentQuery.getCriteria(), userCrit));
       
        StaticSymbolMappingVisitor.mapSymbols(contextQuery, symbolMap);
       
        if (rsInfo.isCriteriaRaised()) {
            //if allowing ancestor bindings, we need to update the bindings for the query node...
            prepareQuery(contextNode, planEnv, contextQuery);
            QueryUtil.rewriteQuery(contextQuery, planEnv.getGlobalMetadata(), planEnv.context);

            //selectively replace correlated references with their actual element symbols
            List<Reference> bindings = QueryUtil.getReferences(contextQuery);
           
            QueryNode modifiedNode = new QueryNode(null);
            modifiedNode.setCommand(contextQuery);
           
            for (Iterator<Reference> i = bindings.iterator(); i.hasNext();) {
                Reference ref = i.next();
                modifiedNode.addBinding(ref.getExpression().toString());
            }
           
            GroupSymbol groupSymbol = QueryUtil.createResolvedGroup(rsInfo.getResultSetName(), planEnv.getGlobalMetadata());
            planEnv.addQueryNodeToMetadata(groupSymbol.getMetadataID(), modifiedNode);
        }
View Full Code Here


    }
 
    private Command resolveVirtualGroup(GroupSymbol virtualGroup)
    throws QueryMetadataException, TeiidComponentException, TeiidProcessingException {
     
        QueryNode qnode = null;
       
        Object metadataID = virtualGroup.getMetadataID();
        boolean noCache = isNoCacheGroup(metadata, metadataID, option);
        boolean isMaterializedGroup = metadata.hasMaterialization(metadataID);
        String cacheString = SQLConstants.Reserved.SELECT;
       
        if( isMaterializedGroup) {
          Object matMetadataId = metadata.getMaterialization(metadataID);
          String matTableName = null;
          CacheHint hint = null;
          boolean isImplicitGlobal = matMetadataId == null;
            if (isImplicitGlobal) {
            TempMetadataID tid = context.getGlobalTableStore().getGlobalTempTableMetadataId(metadataID, metadata);
            matTableName = tid.getID();
            hint = tid.getCacheHint();
            if (hint != null) {
          recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.cache_hint_used", virtualGroup, matTableName, tid); //$NON-NLS-1$
        }         
            matMetadataId = tid;
            } else {
              matTableName = metadata.getFullName(matMetadataId);
            }

          if(noCache){
            //not use cache
            qnode = metadata.getVirtualPlan(metadataID);
            //TODO: update the table for defaultMat
            recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.materialized_table_not_used", virtualGroup, matTableName); //$NON-NLS-1$
          }else{
              this.context.accessedPlanningObject(matMetadataId);
            qnode = new QueryNode(null);
            Query query = createMatViewQuery(matMetadataId, matTableName, Arrays.asList(new AllSymbol()), isImplicitGlobal);
            query.setCacheHint(hint);
            qnode.setCommand(query);
                cacheString = "matview"; //$NON-NLS-1$
                recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.Query_was_redirected_to_Mat_table", virtualGroup, matTableName); //$NON-NLS-1$
          }
        } else {
            // Not a materialized view - query the primary transformation
View Full Code Here

    public static TempMetadataStore resolveCommand(Command currentCommand, GroupSymbol container, int type, QueryMetadataInterface metadata) throws QueryResolverException, TeiidComponentException {
      ResolverUtil.resolveGroup(container, metadata);
      switch (type) {
      case Command.TYPE_QUERY:
        ResolverUtil.resolveGroup(container, metadata);
          QueryNode queryNode = metadata.getVirtualPlan(container.getMetadataID());
           
          return resolveWithBindingMetadata(currentCommand, metadata, queryNode, false);
      case Command.TYPE_INSERT:
      case Command.TYPE_UPDATE:
      case Command.TYPE_DELETE:
View Full Code Here

      String cacheString, QueryMetadataInterface qmi) throws TeiidComponentException,
      QueryMetadataException, QueryResolverException,
      QueryValidatorException {
    qmi = qmi.getDesignTimeMetadata();
    cacheString = "transformation/" + cacheString; //$NON-NLS-1$
    QueryNode cachedNode = (QueryNode)qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
        if (cachedNode == null) {
          Command result = qnode.getCommand();
          List bindings = null;
            if (result == null) {
                try {
                  result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
                } catch(QueryParserException e) {
                    throw new QueryResolverException(e, "ERR.015.008.0011", QueryPlugin.Util.getString("ERR.015.008.0011", virtualGroup)); //$NON-NLS-1$ //$NON-NLS-2$
                }
               
                bindings = qnode.getBindings();
            }
            if (bindings != null && !bindings.isEmpty()) {
              QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
            } else {
              QueryResolver.resolveCommand(result, qmi, false);
            }
          Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
           
          validateProjectedSymbols(virtualGroup, qmi, result);
            cachedNode = new QueryNode(qnode.getQuery());
            cachedNode.setCommand((Command)result.clone());
         
      if(isView(virtualGroup, qmi)) {
            String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
        String deletePlan = qmi.getDeletePlan(virtualGroup.getMetadataID());
        String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());

              List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
          UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
        validator.validate(result, elements);
          UpdateInfo info = validator.getUpdateInfo();
          cachedNode.setUpdateInfo(info);
      }
          qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
        }
    return cachedNode;
  }
View Full Code Here

                baseQuery.getSelect().addSymbol(new ElementSymbol(newGroup + SingleElementSymbol.SEPARATOR + ses.getShortName()));
            }
           
            rsInfo.setCommand(baseQuery);
           
            QueryNode modifiedNode = QueryUtil.getQueryNode(newGroup, planEnv.getGlobalMetadata());
            Command command = QueryUtil.getQuery(newGroup, modifiedNode, planEnv);
                       
            MappingSourceNode parent = sourceNode.getParentSourceNode();
            Collection<ElementSymbol> bindings = QueryUtil.getBindingElements(modifiedNode);
            // root source nodes do not have any inputset criteria on them; so there is no use in
            // going through the raising the criteria.
            // if the original query is not a select.. we are out of luck. we can expand on this later
            // versions. make ure bindings are only to parent.
            if (parent == null || !canRaiseInputset(command, bindings) || !areBindingsOnlyToNode(modifiedNode, parent)) {
                return;
            }
           
            // now get the criteria set at the design time; and walk and remove any inputset
            // criteria.
            Query transformationQuery = (Query)command;
           
            Criteria criteria = transformationQuery.getCriteria();
            Criteria nonInputsetCriteria = null;
            Criteria inputSetCriteria = null;
           
            for (Iterator<Criteria> i = Criteria.separateCriteriaByAnd(criteria).iterator(); i.hasNext();) {
                Criteria conjunct = i.next();

                // collect references in the criteria; if there are references; then this is
                // set by inputset criteria
                Collection<ElementSymbol> references = QueryUtil.getBindingsReferences(conjunct, bindings);
                if (references.isEmpty()) {
                    nonInputsetCriteria = Criteria.combineCriteria(nonInputsetCriteria, conjunct);
                }
                else {
                    inputSetCriteria = Criteria.combineCriteria(inputSetCriteria, conjunct);
                }
            }
           
            // Keep the criteria which is not reference based.
            transformationQuery.setCriteria(nonInputsetCriteria);

            // check and map/convert the inputset criteria elements to groupName, so that
            // this criteria mapped on the baseQuery;

            boolean addedProjectedSymbol = convertCriteria(newGroupSymbol, transformationQuery, inputSetCriteria, planEnv.getGlobalMetadata(), sourceNode.getSymbolMap());
            if (addedProjectedSymbol && transformationQuery.getSelect().isDistinct()) {
                transformationQuery.getSelect().setDistinct(false);
                baseQuery.getSelect().setDistinct(true);
            }
           
            String inlineViewName = planEnv.getAliasName(newGroup);
            transformationQuery = QueryUtil.wrapQuery(new SubqueryFromClause(inlineViewName, transformationQuery), inlineViewName);
                       
            // Now that we have the modified Query Node for the group name
            // we need to update the metadata.
            QueryNode relationalNode = new QueryNode(SQLStringVisitor.getSQLString(transformationQuery));
            planEnv.addQueryNodeToMetadata(newGroupSymbol.getMetadataID(), relationalNode);
           
            QueryUtil.markBindingsAsNonExternal(inputSetCriteria, bindings);
           
            baseQuery.setCriteria(inputSetCriteria);
View Full Code Here

        // to convert to new group.
        sourceNode.setSymbolMap(QueryUtil.createSymbolMap(oldSymbol, newGroup, elements));       
               
        // now that we created a new group; now define the query node for this new group based
        // on the old one.
        QueryNode oldQueryNode = QueryUtil.getQueryNode(oldSymbol.getName(), planEnv.getGlobalMetadata());

        // move the query and its bindings
        QueryNode modifiedNode = new QueryNode(oldQueryNode.getQuery());
        mapBindings(sourceNode, oldQueryNode, modifiedNode);
       
        // add the query node for the new group into metadata.
        planEnv.addQueryNodeToMetadata(newGroupSymbol.getMetadataID(), modifiedNode);       
               
View Full Code Here

     *  Now they should both pass
     *
     */   
    @Test public void testInsertTempTableCreation() {
        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
        QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select #temp.var1 from #temp; END"); //$NON-NLS-1$ //$NON-NLS-2$
        FakeMetadataObject rs = FakeMetadataFactory.createResultSet("rs", v1, new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
        FakeMetadataObject paramRS = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs)//$NON-NLS-1$
        FakeMetadataObject vp = FakeMetadataFactory.createVirtualProcedure("v1.vp", v1, Arrays.asList(new Object[] {paramRS}), n1); //$NON-NLS-1$
       
        FakeMetadataStore store = new FakeMetadataStore();
View Full Code Here

        helpProcess(plan, new FakeDataManager(), expected);
    }
   
    @Test public void testInsertTempTableCreation1() {
        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
        QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select 2 as var1 into #temp; select #temp.var1 from #temp; END"); //$NON-NLS-1$ //$NON-NLS-2$
        FakeMetadataObject rs = FakeMetadataFactory.createResultSet("rs", v1, new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
        FakeMetadataObject paramRS = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs)//$NON-NLS-1$
        FakeMetadataObject vp = FakeMetadataFactory.createVirtualProcedure("v1.vp", v1, Arrays.asList(new Object[] {paramRS}), n1); //$NON-NLS-1$
       
        FakeMetadataStore store = new FakeMetadataStore();
View Full Code Here

    public static Command helpResolveWithBindings(String sql, QueryMetadataInterface metadata, List bindings) throws QueryResolverException, TeiidComponentException {
      
        // parse
        Command command = helpParse(sql);
       
        QueryNode qn = new QueryNode(sql);
        qn.setBindings(bindings);
        // resolve
      QueryResolver.resolveWithBindingMetadata(command, metadata, qn, true);

        CheckSymbolsAreResolvedVisitor vis = new CheckSymbolsAreResolvedVisitor();
        DeepPreOrderNavigator.doVisit(command, vis);
View Full Code Here

        FakeMetadataObject pm1 = store.findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
       
        FakeMetadataObject rs2 = FakeMetadataFactory.createResultSet("pm1.rs2", pm1, new String[] { "in", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        FakeMetadataObject rs2p1 = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs2)//$NON-NLS-1$
        FakeMetadataObject rs2p2 = FakeMetadataFactory.createParameter("in", 2, ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING, null)//$NON-NLS-1$
        QueryNode sq2n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN SELECT e1, e2 FROM pm1.g1 WHERE e1=pm1.sq2.in; END"); //$NON-NLS-1$ //$NON-NLS-2$
        FakeMetadataObject sq2 = FakeMetadataFactory.createVirtualProcedure("pm1.sq2", pm1, Arrays.asList(new FakeMetadataObject[] { rs2p1, rs2p2 }), sq2n1)//$NON-NLS-1$

        store.addObject(rs2);
        store.addObject(sq2);
       
View Full Code Here

TOP

Related Classes of org.teiid.query.mapping.relational.QueryNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.