/** * The object is modified in place, so is not returned. * @param obj Language object * @param exprMap Expression map, Expression to Expression */ public static void mapExpressions(LanguageObject obj, Map<? extends Expression, ? extends Expression> exprMap) { mapExpressions(obj, exprMap, false); }
/** * The object is modified in place, so is not returned. * @param obj Language object * @param exprMap Expression map, Expression to Expression */ public static void mapExpressions(LanguageObject obj, Map<? extends Expression, ? extends Expression> exprMap) { mapExpressions(obj, exprMap, false); }
/** * The object is modified in place, so is not returned. * @param obj Language object * @param exprMap Expression map, Expression to Expression */ public static void mapExpressions(LanguageObject obj, Map<? extends Expression, ? extends Expression> exprMap) { mapExpressions(obj, exprMap, false); }
private static Expression convertExpression(Expression expression, Map symbolMap) { if (expression == null || expression instanceof Constant) { return expression; } if(expression instanceof Expression) { Expression mappedSymbol = (Expression) symbolMap.get(expression); if (mappedSymbol != null) { return mappedSymbol; } if (expression instanceof ElementSymbol) { return expression; } } ExpressionMappingVisitor.mapExpressions(expression, symbolMap); return expression; }
private static Expression convertExpression(Expression expression, Map symbolMap) { if (expression == null || expression instanceof Constant) { return expression; } if(expression instanceof Expression) { Expression mappedSymbol = (Expression) symbolMap.get(expression); if (mappedSymbol != null) { return mappedSymbol; } if (expression instanceof ElementSymbol) { return expression; } } ExpressionMappingVisitor.mapExpressions(expression, symbolMap); return expression; }
private static Expression convertExpression(Expression expression, Map symbolMap) { if (expression == null || expression instanceof Constant) { return expression; } if(expression instanceof Expression) { Expression mappedSymbol = (Expression) symbolMap.get(expression); if (mappedSymbol != null) { return mappedSymbol; } if (expression instanceof ElementSymbol) { return expression; } } ExpressionMappingVisitor.mapExpressions(expression, symbolMap); return expression; }
private void replaceExpressions(LanguageObject lo, Map<Expression, ElementSymbol> mapping, Map<Expression, Expression> subMapping) { if (lo == null) { return; } ExpressionMappingVisitor.mapExpressions(lo, mapping); if (subMapping != null) { //support only 1 level of correlation for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(lo)) { ExpressionMappingVisitor.mapExpressions(container.getCommand(), subMapping); } } }
private void replaceExpressions(LanguageObject lo, Map<Expression, ElementSymbol> mapping, Map<Expression, Expression> subMapping) { if (lo == null) { return; } ExpressionMappingVisitor.mapExpressions(lo, mapping); if (subMapping != null) { //support only 1 level of correlation for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(lo)) { ExpressionMappingVisitor.mapExpressions(container.getCommand(), subMapping); } } }
private void replaceExpressions(LanguageObject lo, Map<Expression, ElementSymbol> mapping, Map<Expression, Expression> subMapping) { if (lo == null) { return; } ExpressionMappingVisitor.mapExpressions(lo, mapping); if (subMapping != null) { //support only 1 level of correlation for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(lo)) { ExpressionMappingVisitor.mapExpressions(container.getCommand(), subMapping); } } }
public void helpTest(LanguageObject original, Map<Expression, Expression> map, LanguageObject expected) { ExpressionMappingVisitor.mapExpressions(original, map); assertEquals("Did not get expected mapped expression", expected, original); //$NON-NLS-1$ }
static Criteria convertCriteria(Criteria criteria, final Map symbolMap, QueryMetadataInterface metadata, boolean rewrite) throws QueryPlannerException { ExpressionMappingVisitor.mapExpressions(criteria, symbolMap); if (!rewrite) { return criteria; } // Simplify criteria if possible try { return QueryRewriter.rewriteCriteria(criteria, null, metadata); } catch(TeiidProcessingException e) { throw new QueryPlannerException(QueryPlugin.Event.TEIID30263, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30263, criteria)); } catch (TeiidComponentException e) { throw new QueryPlannerException(QueryPlugin.Event.TEIID30263, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30263, criteria)); } }
@Test public void testSelectAlias() { ElementSymbol x = new ElementSymbol("y.x"); //$NON-NLS-1$ ElementSymbol y = new ElementSymbol("z.X"); //$NON-NLS-1$ HashMap<Expression, Expression> map = new HashMap<Expression, Expression>(); map.put(x, y); LanguageObject toMap = new Select(Arrays.asList(x)); ExpressionMappingVisitor.mapExpressions(toMap, map); assertEquals("Did not get expected mapped expression", " z.X AS x", toMap.toString()); //$NON-NLS-1$ //$NON-NLS-2$ }
static Criteria convertCriteria(Criteria criteria, final Map symbolMap, QueryMetadataInterface metadata, boolean rewrite) throws QueryPlannerException { ExpressionMappingVisitor.mapExpressions(criteria, symbolMap); if (!rewrite) { return criteria; } // Simplify criteria if possible try { return QueryRewriter.rewriteCriteria(criteria, null, metadata); } catch(TeiidProcessingException e) { throw new QueryPlannerException(QueryPlugin.Event.TEIID30263, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30263, criteria)); } catch (TeiidComponentException e) { throw new QueryPlannerException(QueryPlugin.Event.TEIID30263, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30263, criteria)); } }
static Criteria convertCriteria(Criteria criteria, final Map symbolMap, QueryMetadataInterface metadata, boolean rewrite) throws QueryPlannerException { ExpressionMappingVisitor.mapExpressions(criteria, symbolMap); if (!rewrite) { return criteria; } // Simplify criteria if possible try { return QueryRewriter.rewriteCriteria(criteria, null, metadata); } catch(TeiidProcessingException e) { throw new QueryPlannerException(QueryPlugin.Event.TEIID30263, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30263, criteria)); } catch (TeiidComponentException e) { throw new QueryPlannerException(QueryPlugin.Event.TEIID30263, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30263, criteria)); } }
@Test public void testSelectAlias1() { ElementSymbol x = new ElementSymbol("y.x"); //$NON-NLS-1$ ElementSymbol y = new ElementSymbol("z.x"); //$NON-NLS-1$ HashMap<ElementSymbol, ElementSymbol> map = new HashMap<ElementSymbol, ElementSymbol>(); map.put(x, y); LanguageObject toMap = new Select(Arrays.asList(x)); ExpressionMappingVisitor.mapExpressions(toMap, map); assertEquals("Did not get expected mapped expression", " z.x", toMap.toString()); //$NON-NLS-1$ //$NON-NLS-2$ }
private static void evaluateConstraint(Command atomicCommand, Evaluator eval, Criteria constraint, Map<ElementSymbol, Expression> values) throws BlockedException, TeiidComponentException, QueryProcessingException { Criteria clone = (Criteria) constraint.clone(); ExpressionMappingVisitor.mapExpressions(clone, values); try { if (!eval.evaluate(clone, null)) { throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand)); } } catch (ExpressionEvaluationException e) { throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand)); } }
private static void evaluateConstraint(Command atomicCommand, Evaluator eval, Criteria constraint, Map<ElementSymbol, Expression> values) throws BlockedException, TeiidComponentException, QueryProcessingException { Criteria clone = (Criteria) constraint.clone(); ExpressionMappingVisitor.mapExpressions(clone, values); try { if (!eval.evaluate(clone, null)) { throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand)); } } catch (ExpressionEvaluationException e) { throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand)); } }
private static void evaluateConstraint(Command atomicCommand, Evaluator eval, Criteria constraint, Map<ElementSymbol, Expression> values) throws BlockedException, TeiidComponentException, QueryProcessingException { Criteria clone = (Criteria) constraint.clone(); ExpressionMappingVisitor.mapExpressions(clone, values); try { if (!eval.evaluate(clone, null)) { throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand)); } } catch (ExpressionEvaluationException e) { throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, atomicCommand)); } }
@Test public void testArray() { Expression e1 = new ElementSymbol("g1.e1"); //$NON-NLS-1$ Expression e2 = new ElementSymbol("g1.e2"); //$NON-NLS-1$ Map<Expression, ElementSymbol> map = new HashMap<Expression, ElementSymbol>(); map.put(e1, new ElementSymbol("foo")); Array a = new Array(DataTypeManager.DefaultDataClasses.OBJECT, Arrays.asList(e1, e2)); ExpressionMappingVisitor.mapExpressions(a, map); assertEquals("(foo, g1.e2)", a.toString()); //$NON-NLS-1$ }
/** * we are not careful about ensuring that that every symbol is * unique in a plan, so there's a chance mapping the expression in an * aggregate in a project node will cause the same symbol to be * updated in a sort node. to ensure that we don't get into * recursion trouble we detect if we're replacing an expression * that already exists as a mapping. * * we simulate that situation here using the same aggregate twice in * a function. */ @Test public void testRecursionDetection() { ElementSymbol e1 = new ElementSymbol("g1.e1"); //$NON-NLS-1$ AggregateSymbol a1 = new AggregateSymbol(NonReserved.SUM, false, e1); Function f = new Function(SourceSystemFunctions.ADD_OP, new Expression[] {a1, a1}); HashMap<AggregateSymbol, AggregateSymbol> map = new HashMap<AggregateSymbol, AggregateSymbol>(); map.put(a1, new AggregateSymbol(NonReserved.SUM, false, a1)); ExpressionMappingVisitor.mapExpressions(f, map); assertEquals("(SUM(SUM(g1.e1)) + SUM(SUM(g1.e1)))", f.toString()); //$NON-NLS-1$ }