Search in sources :

Example 1 with Create

use of org.teiid.query.sql.lang.Create 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 Create

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

the class TestCreate method testEquivalence.

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

Example 3 with Create

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

the class TestCreate method testNonEquivalence.

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

Example 4 with Create

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

the class TestCreate method sample2.

public static final Create sample2() {
    Create create = new Create();
    // $NON-NLS-1$
    create.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"));
    create.setElementSymbolsAsColumns(elements);
    return create;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Create(org.teiid.query.sql.lang.Create) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with Create

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

the class TestCreateDrop method testCreateTempTable2.

@Test
public void testCreateTempTable2() {
    Create create = new Create();
    // $NON-NLS-1$
    create.setTable(new GroupSymbol("tempTable"));
    List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
    // $NON-NLS-1$
    ElementSymbol column = new ElementSymbol("c1");
    column.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
    columns.add(column);
    // $NON-NLS-1$
    column = new ElementSymbol("c2");
    column.setType(DataTypeManager.DefaultDataClasses.BYTE);
    columns.add(column);
    create.setElementSymbolsAsColumns(columns);
    create.getColumns().get(0).setNullType(NullType.No_Nulls);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("Create local TEMPORARY table tempTable(c1 boolean not null, c2 byte)", "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean NOT NULL, c2 byte)", create);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Create(org.teiid.query.sql.lang.Create) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Create (org.teiid.query.sql.lang.Create)16 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)11 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)9 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 List (java.util.List)3 Insert (org.teiid.query.sql.lang.Insert)3 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)2 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)2 Column (org.teiid.metadata.Column)2 TempMetadataID (org.teiid.query.metadata.TempMetadataID)2 CacheHint (org.teiid.query.sql.lang.CacheHint)2 Drop (org.teiid.query.sql.lang.Drop)2 Clob (java.sql.Clob)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1