use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.
the class DynamicCommandResolver method resolveCommand.
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
DynamicCommand dynamicCmd = (DynamicCommand) command;
Iterator columns = dynamicCmd.getAsColumns().iterator();
Set groups = new HashSet();
boolean resolvedColumns = false;
// if there is no into group, just create temp metadata ids
if (dynamicCmd.getIntoGroup() == null) {
while (columns.hasNext()) {
ElementSymbol column = (ElementSymbol) columns.next();
column.setMetadataID(new TempMetadataID(column.getShortName(), column.getType()));
}
} else if (dynamicCmd.getIntoGroup().isTempGroupSymbol()) {
resolvedColumns = true;
while (columns.hasNext()) {
ElementSymbol column = (ElementSymbol) columns.next();
column.setGroupSymbol(new GroupSymbol(dynamicCmd.getIntoGroup().getName()));
}
}
ResolverVisitor.resolveLanguageObject(dynamicCmd, groups, dynamicCmd.getExternalGroupContexts(), metadata);
String sqlType = DataTypeManager.getDataTypeName(dynamicCmd.getSql().getType());
String targetType = DataTypeManager.DefaultDataTypes.CLOB;
if (!targetType.equals(sqlType) && !DataTypeManager.isImplicitConversion(sqlType, targetType)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30100, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30100, sqlType));
}
dynamicCmd.setSql(ResolverUtil.convertExpression(dynamicCmd.getSql(), targetType, metadata));
if (dynamicCmd.getUsing() != null && !dynamicCmd.getUsing().isEmpty()) {
for (SetClause clause : dynamicCmd.getUsing().getClauses()) {
ElementSymbol id = clause.getSymbol();
id.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.DVARS));
id.setType(clause.getValue().getType());
id.setMetadataID(new TempMetadataID(id.getName(), id.getType()));
}
}
GroupSymbol intoSymbol = dynamicCmd.getIntoGroup();
if (intoSymbol != null) {
if (!intoSymbol.isImplicitTempGroupSymbol()) {
ResolverUtil.resolveGroup(intoSymbol, metadata);
if (!resolvedColumns) {
// must be a temp table from a higher scope
for (ElementSymbol column : (List<ElementSymbol>) dynamicCmd.getAsColumns()) {
column.setGroupSymbol(dynamicCmd.getIntoGroup().clone());
}
}
} else {
List symbols = dynamicCmd.getAsColumns();
ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols);
}
}
}
use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.
the class TestDynamicCommand method testClone1.
public void testClone1() {
List symbols = new ArrayList();
// $NON-NLS-1$
ElementSymbol a1 = new ElementSymbol("a1");
a1.setType(DataTypeManager.DefaultDataClasses.STRING);
symbols.add(a1);
DynamicCommand sqlCmd = new DynamicCommand();
// $NON-NLS-1$
Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5");
sqlCmd.setSql(sql);
sqlCmd.setAsColumns(symbols);
sqlCmd.setAsClauseSet(true);
// $NON-NLS-1$
sqlCmd.setIntoGroup(new GroupSymbol("#g"));
UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.
the class TestDynamicCommand method testUpdatingModelCount.
public void testUpdatingModelCount() {
DynamicCommand sqlCmd = new DynamicCommand();
sqlCmd.setUpdatingModelCount(1);
assertEquals(1, sqlCmd.getUpdatingModelCount());
sqlCmd.setUpdatingModelCount(3);
assertEquals(2, sqlCmd.getUpdatingModelCount());
sqlCmd.setUpdatingModelCount(-1);
assertEquals(0, sqlCmd.getUpdatingModelCount());
}
use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.
the class TestDynamicCommand method testClone2.
public void testClone2() {
List symbols = new ArrayList();
// $NON-NLS-1$
ElementSymbol a1 = new ElementSymbol("a1");
a1.setType(DataTypeManager.DefaultDataClasses.STRING);
symbols.add(a1);
// $NON-NLS-1$
Expression sql = new Constant("SELECT * FROM g");
SetClauseList using = new SetClauseList();
using.addClause(a1, a1);
// $NON-NLS-1$
DynamicCommand sqlCmd = new DynamicCommand(sql, symbols, new GroupSymbol("#g"), using);
UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.
the class ProcedurePlanner method optimize.
/**
* <p>Produce a ProcessorPlan for the CreateUpdateProcedureCommand on the current node
* of the CommandTreeNode, the procedure plan construction involves using the child
* processor plans.</p>
* @param metadata source of metadata
* @param debug whether or not to generate verbose debug output during planning
* @return ProcessorPlan This processorPlan is a <code>ProcedurePlan</code>
* @throws QueryPlannerException indicating a problem in planning
* @throws QueryMetadataException indicating an exception in accessing the metadata
* @throws TeiidComponentException indicating an unexpected exception
*/
public ProcessorPlan optimize(Command procCommand, IDGenerator idGenerator, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
boolean debug = analysisRecord.recordDebug();
if (debug) {
// $NON-NLS-1$
analysisRecord.println("\n####################################################");
// $NON-NLS-1$
analysisRecord.println("PROCEDURE COMMAND: " + procCommand);
}
// $NON-NLS-1$
CreateProcedureCommand cupc = Assertion.isInstanceOf(procCommand, CreateProcedureCommand.class, "Wrong command type");
if (debug) {
// $NON-NLS-1$
analysisRecord.println("OPTIMIZING SUB-COMMANDS: ");
}
for (Command command : CommandCollectorVisitor.getCommands(procCommand)) {
if (!(command instanceof DynamicCommand)) {
command.setProcessorPlan(QueryOptimizer.optimizePlan(command, metadata, idGenerator, capFinder, analysisRecord, context));
}
}
Block block = cupc.getBlock();
Program programBlock = planBlock(cupc, block, metadata, debug, idGenerator, capFinder, analysisRecord, context);
if (debug) {
// $NON-NLS-1$
analysisRecord.println("\n####################################################");
}
// create plan from program and initialized environment
ProcedurePlan plan = new ProcedurePlan(programBlock);
plan.setMetadata(metadata);
plan.setOutputElements(cupc.getProjectedSymbols());
if (debug) {
// $NON-NLS-1$
analysisRecord.println("####################################################");
// $NON-NLS-1$
analysisRecord.println("PROCEDURE PLAN :" + plan);
// $NON-NLS-1$
analysisRecord.println("####################################################");
}
return plan;
}
Aggregations