/** * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, * TempMetadataAdapter, boolean) */ @Override public void resolveCommand( Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws Exception { DynamicCommand dynamicCmd = (DynamicCommand) command; Iterator columns = dynamicCmd.getAsColumns().iterator(); Set<GroupSymbol> groups = new HashSet<GroupSymbol>(); // 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()) { while (columns.hasNext()) { ElementSymbol column = (ElementSymbol) columns.next(); GroupSymbol gs = getTeiidParser().createASTNode(ASTNodes.GROUP_SYMBOL); gs.setName(dynamicCmd.getIntoGroup().getName()); column.setGroupSymbol(gs); } } ResolverVisitor visitor = new ResolverVisitor(getTeiidParser().getVersion()); visitor.resolveLanguageObject( dynamicCmd, groups, dynamicCmd.getExternalGroupContexts(), metadata); String sqlType = getDataTypeManager().getDataTypeName(dynamicCmd.getSql().getType()); String targetType = DataTypeManagerService.DefaultDataTypes.STRING.getId(); if (!targetType.equals(sqlType) && !getDataTypeManager().isImplicitConversion(sqlType, targetType)) { throw new QueryResolverException(Messages.gs(Messages.TEIID.TEIID30100, sqlType)); } if (dynamicCmd.getUsing() != null && !dynamicCmd.getUsing().isEmpty()) { for (SetClause clause : dynamicCmd.getUsing().getClauses()) { ElementSymbol id = clause.getSymbol(); GroupSymbol gs = getTeiidParser().createASTNode(ASTNodes.GROUP_SYMBOL); gs.setName(ProcedureReservedWords.DVARS); id.setGroupSymbol(gs); 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); } else { List symbols = dynamicCmd.getAsColumns(); ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols); } } }
/** * NOTE: we specifically don't need to visit the as columns or the using identifiers. These will * be resolved by the dynamic command resolver instead. * * @see LanguageVisitor#visit(org.teiid.query.sql.lang.DynamicCommand) */ @Override public void visit(DynamicCommand obj) { preVisitVisitor(obj); visitNode(obj.getSql()); visitNode(obj.getIntoGroup()); if (obj.getUsing() != null) { for (SetClause setClause : obj.getUsing().getClauses()) { visitNode(setClause.getValue()); } } postVisitVisitor(obj); }