Search in sources :

Example 1 with Drop

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

the class TempTableResolver method resolveCommand.

/**
 * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter, boolean)
 */
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    if (command.getType() == Command.TYPE_CREATE) {
        Create create = (Create) command;
        GroupSymbol group = create.getTable();
        // assuming that all temp table creates are local, the user must use a local name
        if (group.getName().indexOf(Symbol.SEPARATOR) != -1) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID30117, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30117, group.getName()));
        }
        // this will only check non-temp groups
        Collection exitsingGroups = metadata.getMetadata().getGroupsForPartialName(group.getName());
        if (!exitsingGroups.isEmpty()) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
        }
        if (metadata.getMetadata().hasProcedure(group.getName())) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
        }
        // now we will be more specific for temp groups
        TempMetadataID id = metadata.getMetadataStore().getTempGroupID(group.getName());
        if (id != null && !metadata.isTemporaryTable(id)) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
        }
        // if we get here then either the group does not exist or has already been defined as a temp table
        // if it has been defined as a temp table, that's ok we'll use this as the new definition and throw an
        // exception at runtime if the user has not dropped the previous table yet
        TempMetadataID tempTable = ResolverUtil.addTempTable(metadata, group, create.getColumnSymbols());
        ResolverUtil.resolveGroup(create.getTable(), metadata);
        Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
        groups.add(create.getTable());
        ResolverVisitor.resolveLanguageObject(command, groups, metadata);
        addAdditionalMetadata(create, tempTable);
        tempTable.setOriginalMetadataID(create.getTableMetadata());
        if (create.getOn() != null) {
            Object mid = null;
            try {
                mid = metadata.getModelID(create.getOn());
            } catch (QueryMetadataException e) {
                throw new QueryResolverException(QueryPlugin.Event.TEIID31134, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31134, create.getOn()));
            }
            if (mid != null && (metadata.isVirtualModel(mid) || !(mid instanceof Schema))) {
                throw new QueryResolverException(QueryPlugin.Event.TEIID31135, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31135, create.getOn()));
            }
            create.getTableMetadata().setParent((Schema) mid);
            tempTable.getTableData().setModel(mid);
        }
    } else if (command.getType() == Command.TYPE_DROP) {
        ResolverUtil.resolveGroup(((Drop) command).getTable(), metadata);
    }
}
Also used : Create(org.teiid.query.sql.lang.Create) Schema(org.teiid.metadata.Schema) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) Collection(java.util.Collection) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) HashSet(java.util.HashSet) Drop(org.teiid.query.sql.lang.Drop)

Example 2 with Drop

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

the class TestDrop method testEquivalence.

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

Example 3 with Drop

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

the class TestDrop method sample1.

// ################################## TEST HELPERS ################################
public static final Drop sample1() {
    Drop Drop = new Drop();
    // $NON-NLS-1$
    Drop.setTable(new GroupSymbol("temp_table"));
    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 4 with Drop

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

the class TestDrop method testNonEquivalence.

public void testNonEquivalence() {
    Drop c1 = sample1();
    Drop c2 = sample2();
    int equals = -1;
    UnitTestUtil.helpTestEquivalence(equals, c1, c2);
}
Also used : Drop(org.teiid.query.sql.lang.Drop)

Example 5 with Drop

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

the class TestCreateDrop method testDropTable.

@Test
public void testDropTable() {
    Drop drop = new Drop();
    // $NON-NLS-1$
    drop.setTable(new GroupSymbol("tempTable"));
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("DROP table tempTable", "DROP TABLE tempTable", drop);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Drop(org.teiid.query.sql.lang.Drop) Test(org.junit.Test)

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