Search in sources :

Example 6 with Drop

use of org.teiid.query.sql.lang.Drop in project teiid by teiid.

the class RulePlaceAccess method addAccessNode.

/**
 * Adds a access node if the node is a source leaf node.
 *
 * @param metadata
 * @param sourceNode
 * @return true if the source node has an access pattern
 * @throws QueryMetadataException
 * @throws TeiidComponentException
 */
private void addAccessNode(QueryMetadataInterface metadata, PlanNode sourceNode, CapabilitiesFinder finder, boolean[] additionalRules) throws QueryMetadataException, TeiidComponentException {
    boolean isInsert = false;
    Object req = sourceNode.getProperty(NodeConstants.Info.ATOMIC_REQUEST);
    if (req == null) {
        req = sourceNode.getProperty(NodeConstants.Info.NESTED_COMMAND);
    }
    if (sourceNode.getProperty(NodeConstants.Info.TABLE_FUNCTION) != null) {
        return;
    }
    if (req instanceof Insert) {
        isInsert = true;
    } else {
        PlanNode parent = sourceNode.getParent();
        if (parent.getType() == NodeConstants.Types.PROJECT && parent.getProperty(NodeConstants.Info.INTO_GROUP) != null) {
            isInsert = true;
        }
    }
    PlanNode apNode = sourceNode;
    if (sourceNode.getChildCount() == 0) {
        // Create the access node and insert
        PlanNode accessNode = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
        accessNode.addGroups(sourceNode.getGroups());
        copyProperties(sourceNode, accessNode);
        SourceHint sourceHint = (SourceHint) sourceNode.removeProperty(Info.SOURCE_HINT);
        // TODO: trim the hint to only the sources possible under this model (typically 1, but could be more in
        // multi-source
        accessNode.setProperty(Info.SOURCE_HINT, sourceHint);
        Object hint = sourceNode.removeProperty(NodeConstants.Info.IS_OPTIONAL);
        if (hint != null) {
            accessNode.setProperty(NodeConstants.Info.IS_OPTIONAL, hint);
        }
        Object modelId = null;
        if (sourceNode.getGroups().size() == 1) {
            GroupSymbol gs = sourceNode.getGroups().iterator().next();
            modelId = gs.getModelMetadataId();
            if (modelId != null) {
                accessNode.setProperty(NodeConstants.Info.MODEL_ID, modelId);
            }
        }
        if (req instanceof Create || req instanceof Drop) {
            modelId = TempMetadataAdapter.TEMP_MODEL;
        } else {
            modelId = RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata);
        }
        if (modelId != null) {
            boolean multiSource = metadata.isMultiSource(modelId);
            if (multiSource) {
                accessNode.setProperty(Info.IS_MULTI_SOURCE, multiSource);
            }
            accessNode.setProperty(NodeConstants.Info.MODEL_ID, modelId);
        }
        if (req == null && modelId != null) {
            // add "conformed" sources if they exist
            GroupSymbol group = sourceNode.getGroups().iterator().next();
            Object gid = group.getMetadataID();
            String sources = metadata.getExtensionProperty(gid, CONFORMED_SOURCES, false);
            if (sources != null) {
                Set<Object> conformed = new LinkedHashSet<Object>();
                conformed.add(modelId);
                for (String source : StringUtil.split(sources, ",")) {
                    // $NON-NLS-1$
                    Object mid = metadata.getModelID(source.trim());
                    if (metadata.isVirtualModel(mid)) {
                        // TODO: could validate this up-front
                        throw new QueryMetadataException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31148, metadata.getName(mid), group));
                    }
                    conformed.add(mid);
                }
                accessNode.setProperty(Info.CONFORMED_SOURCES, conformed);
            }
        }
        // Insert
        sourceNode.addAsParent(accessNode);
        apNode = accessNode;
        // set additional information
        for (GroupSymbol group : accessNode.getGroups()) {
            if (group.getCheckMatViewStatus() != null) {
                LinkedHashSet<Object> viewsToCheck = new LinkedHashSet<Object>();
                viewsToCheck.add(group.getCheckMatViewStatus());
                accessNode.setProperty(Info.CHECK_MAT_VIEW, viewsToCheck);
            }
            Object modelID = metadata.getModelID(group.getMetadataID());
            if (CapabilitiesUtil.requiresCriteria(modelID, metadata, finder)) {
                additionalRules[1] = true;
            }
        }
    }
    // Add access pattern(s), if any, as property of access node
    if (!isInsert && addAccessPatternsProperty(apNode, metadata)) {
        additionalRules[0] = true;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Insert(org.teiid.query.sql.lang.Insert) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) SourceHint(org.teiid.query.sql.lang.SourceHint) Drop(org.teiid.query.sql.lang.Drop) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) Create(org.teiid.query.sql.lang.Create) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 7 with Drop

use of org.teiid.query.sql.lang.Drop in project teiid by teiid.

the class TestDrop method sample2.

public static final Drop sample2() {
    Drop Drop = new Drop();
    // $NON-NLS-1$
    Drop.setTable(new GroupSymbol("temp_table2"));
    List elements = new ArrayList();
    // $NON-NLS-1$
    elements.add(new ElementSymbol("a"));
    // $NON-NLS-1$
    elements.add(new ElementSymbol("b"));
    return Drop;
}
Also used : Drop(org.teiid.query.sql.lang.Drop)

Example 8 with Drop

use of org.teiid.query.sql.lang.Drop in project teiid by teiid.

the class TestDrop method testSelfEquivalence.

public void testSelfEquivalence() {
    Drop c1 = sample1();
    int equals = 0;
    UnitTestUtil.helpTestEquivalence(equals, c1, c1);
}
Also used : Drop(org.teiid.query.sql.lang.Drop)

Aggregations

Drop (org.teiid.query.sql.lang.Drop)8 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)3 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)2 Create (org.teiid.query.sql.lang.Create)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1 Schema (org.teiid.metadata.Schema)1 TempMetadataID (org.teiid.query.metadata.TempMetadataID)1 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)1 Insert (org.teiid.query.sql.lang.Insert)1 SourceHint (org.teiid.query.sql.lang.SourceHint)1