/** * Deep copy of object * @return Deep copy of object */ public Object clone() { Expression leftCopy = null; if(getLeftExpression() != null) { leftCopy = (Expression) getLeftExpression().clone(); } Expression rightCopy = null; if(getRightExpression() != null) { rightCopy = (Expression) getRightExpression().clone(); } MatchCriteria criteriaCopy = new MatchCriteria(leftCopy, rightCopy, getEscapeChar()); criteriaCopy.setNegated(isNegated()); criteriaCopy.mode = mode; return criteriaCopy; }
private Criteria rewriteCriteria(MatchCriteria criteria) throws TeiidComponentException, TeiidProcessingException{ criteria.setLeftExpression( rewriteExpressionDirect(criteria.getLeftExpression())); criteria.setRightExpression( rewriteExpressionDirect(criteria.getRightExpression())); if (isNull(criteria.getLeftExpression()) || isNull(criteria.getRightExpression())) { return UNKNOWN_CRITERIA; Expression rightExpr = criteria.getRightExpression(); if(rightExpr instanceof Constant && rightExpr.getType().equals(DataTypeManager.DefaultDataClasses.STRING)) { Constant constant = (Constant) rightExpr; String value = (String) constant.getValue(); if (criteria.getMode() != MatchMode.REGEX) { char escape = criteria.getEscapeChar(); criteria.setEscapeChar(MatchCriteria.NULL_ESCAPE_CHAR); return getSimpliedCriteria(criteria, criteria.getLeftExpression(), !criteria.isNegated(), true); if (criteria.getMode() == MatchMode.SIMILAR) { criteria.setMode(MatchMode.REGEX); criteria.setRightExpression(new Constant(Evaluator.SIMILAR_TO_REGEX.getPatternString(value, escape))); criteria.setEscapeChar(MatchCriteria.NULL_ESCAPE_CHAR); } else if(DataTypeManager.DefaultDataClasses.STRING.equals(criteria.getLeftExpression().getType()) && value.indexOf(escape) < 0 && value.indexOf(MatchCriteria.MATCH_CHAR) < 0 return rewriteCriteria(new CompareCriteria(criteria.getLeftExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, criteria.getRightExpression()));
/** * Constructs an instance of this class from a left and right expression * * @param leftExpression The expression to check * @param rightExpression The match expression */ public MatchCriteria( Expression leftExpression, Expression rightExpression ) { setLeftExpression(leftExpression); setRightExpression(rightExpression); }
/** * @see org.teiid.query.sql.LanguageVisitor#visit(MatchCriteria) */ public void visit(MatchCriteria obj) { obj.setLeftExpression( replaceExpression(obj.getLeftExpression()) ); obj.setRightExpression( replaceExpression(obj.getRightExpression()) ); }
Like translate(MatchCriteria criteria) { Character escapeChar = null; if(criteria.getEscapeChar() != MatchCriteria.NULL_ESCAPE_CHAR) { escapeChar = new Character(criteria.getEscapeChar()); } Like like = new Like(translate(criteria.getLeftExpression()), translate(criteria.getRightExpression()), escapeChar, criteria.isNegated()); like.setMode(criteria.getMode()); return like; }
MatchCriteria matchcriteria = new MatchCriteria(expression, value); matchcriteria.setNegated(negated); if(esc == null && ((value instanceof Constant && t.image != null && t.image.startsWith("E'")) matchcriteria.setEscapeChar(esc.charValue()); matchcriteria.setMode(similar?MatchMode.SIMILAR:MatchMode.LIKE); {if (true) return matchcriteria;} throw new Error("Missing return statement in function");
public static MatchCriteria example(String str, char escapeChar) { MatchCriteria crit = new MatchCriteria(); crit.setLeftExpression(new ElementSymbol("m.g1.e1")); //$NON-NLS-1$ crit.setRightExpression(new Constant(str)); crit.setEscapeChar(escapeChar); return crit; }
@Test public void testMatchCriteria3() { MatchCriteria mc = new MatchCriteria(); mc.setLeftExpression(new ElementSymbol("m.g.e1")); //$NON-NLS-1$ mc.setRightExpression(new Constant("abc")); //$NON-NLS-1$ mc.setNegated(true); helpTest(mc, "m.g.e1 NOT LIKE 'abc'"); //$NON-NLS-1$ }
public static MatchCriteria example(String str) { MatchCriteria crit = new MatchCriteria(); crit.setLeftExpression(new ElementSymbol("m.g1.e1")); //$NON-NLS-1$ crit.setRightExpression(new Constant(str)); return crit; }
final public MatchCriteria regexMatchCrit(ParseInfo info, Expression expression) throws ParseException { Expression value = null; boolean negated = false; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case NOT: jj_consume_token(NOT); negated = true; break; default: jj_la1[214] = jj_gen; ; } jj_consume_token(LIKE_REGEX); value = commonValueExpression(info); MatchCriteria matchcriteria = new MatchCriteria(expression, value); matchcriteria.setNegated(negated); matchcriteria.setMode(MatchMode.REGEX); {if (true) return matchcriteria;} throw new Error("Missing return statement in function"); }
/** * Get hash code. WARNING: The hash code is based on data in the criteria. * If data values are changed, the hash code will change - don't hash this * object and change values. * @return Hash code */ public int hashCode() { int hc = 0; hc = HashCodeUtil.hashCode(hc, getLeftExpression()); hc = HashCodeUtil.hashCode(hc, getRightExpression()); return hc; }
public static MatchCriteria helpExample(String right, char escape, boolean negated) { ElementSymbol e1 = TestElementImpl.helpExample("vm1.g1", "e1"); //$NON-NLS-1$ //$NON-NLS-2$ MatchCriteria match = new MatchCriteria(e1, new Constant(right), escape); match.setNegated(negated); return match; }
public void testVisitMatchCriteria() { MatchCriteria mc = new MatchCriteria(exampleElement(true, 0), new Constant("abc")); //$NON-NLS-1$ helpTest(mc, getSymbolMap()); }
@Test public void testEquals3() { MatchCriteria c1 = example("abc", '#'); //$NON-NLS-1$ c1.setNegated(true); MatchCriteria c2 = (MatchCriteria) c1.clone(); assertTrue("Equivalent match criteria don't compare as equal: " + c1 + ", " + c2, c1.equals(c2)); //$NON-NLS-1$ //$NON-NLS-2$ }
float ndv = getPredicateNDV(matchCriteria.getLeftExpression(), currentNode, childCost, metadata); isNegatedPredicateCriteria = matchCriteria.isNegated();
@Test public void testEquals2() { MatchCriteria c1 = example("abc", '#'); //$NON-NLS-1$ c1.setNegated(true); MatchCriteria c2 = example("abc", '#'); //$NON-NLS-1$ c2.setNegated(true); assertTrue("Equivalent match criteria don't compare as equal: " + c1 + ", " + c2, c1.equals(c2)); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Constructs an instance of this class from a left and right expression * and an escape character * * @param leftExpression The expression to check * @param rightExpression The match expression * @param escapeChar The escape character, to allow literal use of wildcard and single match chars */ public MatchCriteria( Expression leftExpression, Expression rightExpression, char escapeChar ) { this(leftExpression, rightExpression); setEscapeChar(escapeChar); }
private boolean match(String pattern, char escape, CharSequence search, MatchMode mode) throws ExpressionEvaluationException { Pattern patternRegex = null; switch (mode) { case LIKE: patternRegex = LIKE_TO_REGEX.translate(pattern, escape); break; case SIMILAR: patternRegex = SIMILAR_TO_REGEX.translate(pattern, escape); break; case REGEX: patternRegex = MatchCriteria.getPattern(pattern, pattern, 0); break; default: throw new AssertionError(); } Matcher matcher = patternRegex.matcher(search); return matcher.find(); }
@Test public void testNonEquivalence2(){ MatchCriteria c1 = example("abc", '#'); //$NON-NLS-1$ c1.setNegated(true); MatchCriteria c2 = example("abc", '#'); //$NON-NLS-1$ c2.setNegated(false); int equals = -1; UnitTestUtil.helpTestEquivalence(equals, c1, c2); } }
@Test public void testNationCharString2() throws Exception { Query query = (Query) QueryParser.getQueryParser().parseCommand("SELECT DISTINCT TABLE_QUALIFIER, NULL AS TABLE_OWNER, NULL AS TABLE_NAME, NULL AS TABLE_TYPE, NULL AS REMARKS FROM ATIODBCSYSTEM.OA_TABLES WHERE TABLE_QUALIFIER LIKE N'%' ESCAPE '\\' ORDER BY TABLE_QUALIFIER "); //$NON-NLS-1$ MatchCriteria matchCrit = (MatchCriteria) query.getCriteria(); Constant c = (Constant) matchCrit.getRightExpression(); assertEquals(c, new Constant("%")); //$NON-NLS-1$ }