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