/** * Convert a list of SingleElementSymbols to a List of ColumnInfo objects. * * @param symbols List of SingleElementSymbols * @return List of ColumnInfos */ public static List createColumnInfos(List symbols) { List infos = new ArrayList(symbols.size()); Iterator iter = symbols.iterator(); while (iter.hasNext()) { Expression symbol = (Expression) iter.next(); String name = Symbol.getName(symbol); if (symbol instanceof AliasSymbol) { AliasSymbol alias = (AliasSymbol) symbol; symbol = alias.getSymbol(); } if (symbol instanceof ElementSymbol) { ElementSymbol element = (ElementSymbol) symbol; GroupSymbol group = element.getGroupSymbol(); Object groupID = null; if (group != null) { groupID = group.getMetadataID(); } infos.add( new ColumnInfo( name, DataTypeManager.getDataTypeName(element.getType()), element.getType(), groupID, element.getMetadataID())); } else { // ExpressionSymbol or AggregateSymbol // Expressions don't map to a single element or group, so don't save that info infos.add( new ColumnInfo( name, DataTypeManager.getDataTypeName(symbol.getType()), symbol.getType())); } } return infos; }
private Expression rewriteMultiSourceCommand(Command command) throws TeiidComponentException { Expression result = null; if (command instanceof StoredProcedure) { StoredProcedure obj = (StoredProcedure) command; for (Iterator<SPParameter> params = obj.getMapOfParameters().values().iterator(); params.hasNext(); ) { SPParameter param = params.next(); if (param.getParameterType() != SPParameter.IN) { continue; } if (metadata.isMultiSourceElement(param.getMetadataID())) { Expression source = param.getExpression(); params.remove(); if (param.isUsingDefault() && source instanceof Constant && ((Constant) source).isNull()) { continue; } result = source; break; } } } if (command instanceof Insert) { Insert obj = (Insert) command; for (int i = 0; i < obj.getVariables().size(); i++) { ElementSymbol elem = obj.getVariables().get(i); Object metadataID = elem.getMetadataID(); if (metadata.isMultiSourceElement(metadataID)) { Expression source = (Expression) obj.getValues().get(i); obj.getVariables().remove(i); obj.getValues().remove(i); result = source; break; } } } else if (command instanceof FilteredCommand) { for (Criteria c : Criteria.separateCriteriaByAnd(((FilteredCommand) command).getCriteria())) { if (!(c instanceof CompareCriteria)) { continue; } CompareCriteria cc = (CompareCriteria) c; if (cc.getLeftExpression() instanceof ElementSymbol) { ElementSymbol es = (ElementSymbol) cc.getLeftExpression(); if (metadata.isMultiSourceElement(es.getMetadataID()) && EvaluatableVisitor.willBecomeConstant(cc.getRightExpression())) { if (result != null && !result.equals(cc.getRightExpression())) { return Constant.NULL_CONSTANT; } result = cc.getRightExpression(); } } } } return result; }
/** * Gets the data type names for each of the input expressions, in order. * * @param expressions List of Expressions * @return * @since 4.2 */ public static String[] getTypeNames(List<? extends Expression> expressions) { if (expressions == null) { return null; } String[] types = new String[expressions.size()]; for (ListIterator<? extends Expression> i = expressions.listIterator(); i.hasNext(); ) { Expression expr = i.next(); types[i.previousIndex()] = DataTypeManager.getDataTypeName(expr.getType()); } return types; }
public static List[] createResults(List symbols, int rowCount, boolean useIntCounter) { List[] rows = new List[rowCount]; for (int i = 0; i < rowCount; i++) { List row = new ArrayList(); Iterator iter = symbols.iterator(); while (iter.hasNext()) { Expression symbol = (Expression) iter.next(); Class type = symbol.getType(); row.add(getValue(type, i, useIntCounter)); } rows[i] = row; } return rows; }
public void process(ProcedurePlan procEnv) throws TeiidComponentException { List<?> currentRow = procEnv.getCurrentRow(rsName); VariableContext varContext = procEnv.getCurrentVariableContext(); // set results to the variable context(the cursor.element is treated as variable) if (this.elements == null) { List schema = procEnv.getSchema(rsName); elements = new ArrayList<ElementSymbol>(schema.size()); for (int i = 0; i < schema.size(); i++) { Expression element = (Expression) schema.get(i); ElementSymbol e = new ElementSymbol(rsName + Symbol.SEPARATOR + Symbol.getShortName(element)); e.setType(element.getType()); elements.add(e); } } for (int i = 0; i < elements.size(); i++) { varContext.setValue(elements.get(i), currentRow.get(i)); } }
private void validate( VDBMetaData vdb, ModelMetaData model, AbstractMetadataRecord record, ValidatorReport report, IQueryMetadataInterface metadata, MetadataFactory mf) { ValidatorReport resolverReport = null; try { if (record instanceof Procedure) { Procedure p = (Procedure) record; Command command = queryParser.parseProcedure(p.getQueryPlan(), false); GroupSymbol gs = createASTNode(ASTNodes.GROUP_SYMBOL); gs.setName(p.getFullName()); QueryResolver resolver = new QueryResolver(queryParser); resolver.resolveCommand(command, gs, ICommand.TYPE_STORED_PROCEDURE, metadata, false); Validator validator = new Validator(); resolverReport = validator.validate(command, metadata); determineDependencies(p, command); } else if (record instanceof Table) { Table t = (Table) record; GroupSymbol symbol = createASTNode(ASTNodes.GROUP_SYMBOL); symbol.setName(t.getFullName()); ResolverUtil.resolveGroup(symbol, metadata); String selectTransformation = t.getSelectTransformation(); boolean columnsIsEmpty = t.getColumns() == null || t.getColumns().isEmpty(); // Consider columns if teid 8.11 or lower boolean considerColumns_811 = isTeiidOrGreater(Version.TEIID_8_12_4) ? true : columnsIsEmpty; // Consider columns if teiid 8.12.4+ boolean considerColumns_8124 = isTeiidOrGreater(Version.TEIID_8_12_4) ? columnsIsEmpty : true; if (t.isVirtual() && considerColumns_811) { QueryCommand command = (QueryCommand) queryParser.parseCommand(selectTransformation); QueryResolver resolver = new QueryResolver(queryParser); resolver.resolveCommand(command, metadata); Validator validator = new Validator(); resolverReport = validator.validate(command, metadata); if (!resolverReport.hasItems() && considerColumns_8124) { List<Expression> symbols = command.getProjectedSymbols(); for (Expression column : symbols) { try { addColumn(Symbol.getShortName(column), column.getType(), t, mf); } catch (Exception e) { log(report, model, e.getMessage()); } } } if (considerColumns_8124) { determineDependencies(t, command); if (t.getInsertPlan() != null && t.isInsertPlanEnabled()) { validateUpdatePlan( model, report, metadata, t, t.getInsertPlan(), Command.TYPE_INSERT); } if (t.getUpdatePlan() != null && t.isUpdatePlanEnabled()) { validateUpdatePlan( model, report, metadata, t, t.getUpdatePlan(), Command.TYPE_UPDATE); } if (t.getDeletePlan() != null && t.isDeletePlanEnabled()) { validateUpdatePlan( model, report, metadata, t, t.getDeletePlan(), Command.TYPE_DELETE); } } } boolean addCacheHint = false; if (t.isMaterialized() && t.getMaterializedTable() == null) { List<KeyRecord> fbis = t.getFunctionBasedIndexes(); List<GroupSymbol> groups = Arrays.asList(symbol); if (fbis != null && !fbis.isEmpty()) { for (KeyRecord fbi : fbis) { for (int j = 0; j < fbi.getColumns().size(); j++) { Column c = fbi.getColumns().get(j); if (c.getParent() != fbi) { continue; } String exprString = c.getNameInSource(); try { Expression ex = queryParser.parseExpression(exprString); ResolverVisitor resolverVisitor = new ResolverVisitor(teiidVersion); resolverVisitor.resolveLanguageObject(ex, groups, metadata); if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ex) .isEmpty()) { log( report, model, Messages.gs(Messages.TEIID.TEIID31114, exprString, fbi.getFullName())); } EvaluatableVisitor ev = new EvaluatableVisitor(teiidVersion); PreOrPostOrderNavigator.doVisit(ex, ev, PostOrderNavigator.PRE_ORDER); if (ev.getDeterminismLevel().compareTo(Determinism.VDB_DETERMINISTIC) < 0) { log( report, model, Messages.gs(Messages.TEIID.TEIID31115, exprString, fbi.getFullName())); } } catch (QueryResolverException e) { log( report, model, Messages.gs( Messages.TEIID.TEIID31116, exprString, fbi.getFullName(), e.getMessage())); } } } } } else { addCacheHint = true; } // this seems to parse, resolve and validate. QueryResolver resolver = new QueryResolver(queryParser); QueryNode node = resolver.resolveView( symbol, new QueryNode(t.getSelectTransformation()), SQLConstants.Reserved.SELECT, metadata); CacheHint cacheHint = node.getCommand().getCacheHint(); Long ttl = -1L; if (cacheHint != null && cacheHint.getTtl() != null && addCacheHint && t.getProperty(MATVIEW_TTL, false) == null) { ttl = cacheHint.getTtl(); t.setProperty(MATVIEW_TTL, String.valueOf(ttl)); } } if (resolverReport != null && resolverReport.hasItems()) { for (ValidatorFailure v : resolverReport.getItems()) { log( report, model, v.getStatus() == IValidatorFailure.VFStatus.ERROR ? Severity.ERROR : Severity.WARNING, v.getMessage()); } } processReport(model, record, report, resolverReport); } catch (Exception e) { log( report, model, Messages.gs(Messages.TEIID.TEIID31080, record.getFullName(), e.getMessage())); } }