Search in sources :

Example 11 with Create

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

the class GlobalTableStoreImpl method createMatTable.

@Override
public TempTable createMatTable(final String tableName, GroupSymbol group) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
    Create create = getCreateCommand(group, true, metadata);
    TempTable table = tableStore.addTempTable(tableName, create, bufferManager, false, null);
    table.setUpdatable(false);
    CacheHint hint = table.getCacheHint();
    if (hint != null) {
        table.setPreferMemory(hint.isPrefersMemory());
        if (hint.getTtl() != null) {
            getMatTableInfo(tableName).setTtl(hint.getTtl());
        }
        if (!create.getPrimaryKey().isEmpty()) {
            table.setUpdatable(hint.isUpdatable(false));
        }
    }
    return table;
}
Also used : CacheHint(org.teiid.query.sql.lang.CacheHint) Create(org.teiid.query.sql.lang.Create)

Example 12 with Create

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

the class GlobalTableStoreImpl method getCreateCommand.

public static Create getCreateCommand(GroupSymbol group, boolean matview, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
    Create create = new Create();
    create.setTable(group);
    List<ElementSymbol> allColumns = ResolverUtil.resolveElementsInGroup(group, metadata);
    create.setElementSymbolsAsColumns(allColumns);
    if (!matview) {
        for (int i = 0; i < allColumns.size(); i++) {
            ElementSymbol es = allColumns.get(i);
            if (!metadata.elementSupports(es.getMetadataID(), SupportConstants.Element.NULL)) {
                create.getColumns().get(i).setNullType(NullType.No_Nulls);
                if (es.getType() == DataTypeManager.DefaultDataClasses.INTEGER && metadata.elementSupports(es.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT)) {
                    // serial
                    create.getColumns().get(i).setAutoIncremented(true);
                }
            }
        }
    }
    Object pk = metadata.getPrimaryKey(group.getMetadataID());
    if (pk != null) {
        List<ElementSymbol> pkColumns = resolveIndex(metadata, allColumns, pk);
        create.getPrimaryKey().addAll(pkColumns);
    }
    return create;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Create(org.teiid.query.sql.lang.Create) ReplicatedObject(org.teiid.query.ReplicatedObject) CacheHint(org.teiid.query.sql.lang.CacheHint)

Example 13 with Create

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

the class TestCreateDrop method testCreateTempTable1.

@Test
public void testCreateTempTable1() {
    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.setCommitAction(CommitAction.PRESERVE_ROWS);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("Create local TEMPORARY table tempTable (c1 boolean, c2 byte) on commit preserve rows", "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte) ON COMMIT PRESERVE ROWS", 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)

Example 14 with Create

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

the class TestCreateDrop method testCreateTempTableWithPrimaryKey.

@Test
public void testCreateTempTableWithPrimaryKey() {
    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.getPrimaryKey().add(column);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("Create local TEMPORARY table tempTable(c1 boolean, c2 byte, primary key (c2))", "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte, PRIMARY KEY(c2))", 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)

Example 15 with Create

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

the class TestCreate method sample1.

// ################################## TEST HELPERS ################################
public static final Create sample1() {
    Create create = new Create();
    // $NON-NLS-1$
    create.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"));
    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)

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