@Override public Expression create(List<Expression> children, StatementContext context) throws SQLException { QueryServices services = context.getConnection().getQueryServices(); boolean useByteBasedRegex = services.getProps().getBoolean(QueryServices.USE_BYTE_BASED_REGEX_ATTRIB, QueryServicesOptions.DEFAULT_USE_BYTE_BASED_REGEX); if (useByteBasedRegex) { return new ByteBasedRegexpSubstrFunction(children); } else { return new StringBasedRegexpSubstrFunction(children); } } }
@Test public void regexpSubstr() throws Exception { List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PChar.INSTANCE), getLiteral("l.h"), getLiteral(2)); evaluateAndAssertResult(new StringBasedRegexpSubstrFunction(args), "lah"); evaluateAndAssertResult(new ByteBasedRegexpSubstrFunction(args), "lah"); }
private String testExpression(String srcStr, String patternStr, int offset, SortOrder sortOrder) throws SQLException { Expression srcExp, patternExp, offsetExp; srcExp = LiteralExpression.newConstant(srcStr, TYPE, sortOrder); patternExp = LiteralExpression.newConstant(patternStr, TYPE, sortOrder); offsetExp = LiteralExpression.newConstant(offset, PInteger.INSTANCE, sortOrder); List<Expression> expressions = Lists.newArrayList(srcExp, patternExp, offsetExp); String res1, res2; res1 = evalExp(new ByteBasedRegexpSubstrFunction(expressions)); res2 = evalExp(new StringBasedRegexpSubstrFunction(expressions)); assertEquals(res1, res2); return res1; }
@Override public Expression create(List<Expression> children, StatementContext context) throws SQLException { QueryServices services = context.getConnection().getQueryServices(); boolean useByteBasedRegex = services.getProps().getBoolean(QueryServices.USE_BYTE_BASED_REGEX_ATTRIB, QueryServicesOptions.DEFAULT_USE_BYTE_BASED_REGEX); if (useByteBasedRegex) { return new ByteBasedRegexpSubstrFunction(children); } else { return new StringBasedRegexpSubstrFunction(children); } } }
@Override public Expression create(List<Expression> children, StatementContext context) throws SQLException { QueryServices services = context.getConnection().getQueryServices(); boolean useByteBasedRegex = services.getProps().getBoolean(QueryServices.USE_BYTE_BASED_REGEX_ATTRIB, QueryServicesOptions.DEFAULT_USE_BYTE_BASED_REGEX); if (useByteBasedRegex) { return new ByteBasedRegexpSubstrFunction(children); } else { return new StringBasedRegexpSubstrFunction(children); } } }