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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations