use of io.crate.analyze.symbol.Literal in project crate by crate.
the class AnyNotLikeOperatorTest method anyNotLike.
private Boolean anyNotLike(String pattern, String... expressions) {
Literal patternLiteral = Literal.of(pattern);
Object[] value = new Object[expressions.length];
for (int i = 0; i < expressions.length; i++) {
value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
}
Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
AnyNotLikeOperator impl = (AnyNotLikeOperator) new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
return impl.evaluate(patternLiteral, valuesLiteral);
}
use of io.crate.analyze.symbol.Literal in project crate by crate.
the class AnyNotLikeOperatorTest method testNegateNotLike.
@Test
public void testNegateNotLike() throws Exception {
Literal patternLiteral = Literal.of("A");
Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("A"), new BytesRef("B") });
FunctionImplementation impl = new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
Function anyNotLikeFunction = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
Input<Boolean> normalized = (Input<Boolean>) impl.normalizeSymbol(anyNotLikeFunction, new TransactionContext(SessionContext.SYSTEM_SESSION));
assertThat(normalized.value(), is(true));
assertThat(new NotPredicate().evaluate(normalized), is(false));
}
use of io.crate.analyze.symbol.Literal in project crate by crate.
the class AnyNotLikeOperatorTest method normalizeSymbol.
private static Symbol normalizeSymbol(String pattern, String... expressions) {
Literal patternLiteral = Literal.of(pattern);
Object[] value = new Object[expressions.length];
for (int i = 0; i < expressions.length; i++) {
value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
}
Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
AnyNotLikeOperator impl = (AnyNotLikeOperator) new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(patternLiteral.valueType(), valuesLiteral.valueType()));
Function function = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
return impl.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
use of io.crate.analyze.symbol.Literal in project crate by crate.
the class MatchesFunction method compile.
@Override
public Scalar<BytesRef[], Object> compile(List<Symbol> arguments) {
assert arguments.size() > 1 : "number of arguments must be > 1";
String pattern = null;
if (arguments.get(1).symbolType() == SymbolType.LITERAL) {
Literal literal = (Literal) arguments.get(1);
Object patternVal = literal.value();
if (patternVal == null) {
return this;
}
pattern = ((BytesRef) patternVal).utf8ToString();
}
BytesRef flags = null;
if (arguments.size() == 3) {
assert arguments.get(2).symbolType() == SymbolType.LITERAL : "3rd argument must be a " + SymbolType.LITERAL;
flags = (BytesRef) ((Literal) arguments.get(2)).value();
}
if (pattern != null) {
regexMatcher = new RegexMatcher(pattern, flags);
} else {
regexMatcher = null;
}
return this;
}
use of io.crate.analyze.symbol.Literal in project crate by crate.
the class ReplaceFunction method compile.
@Override
public Scalar<BytesRef, Object> compile(List<Symbol> arguments) {
assert arguments.size() >= 3 : "number of arguments muts be > 3";
String pattern = null;
if (arguments.get(1).symbolType() == SymbolType.LITERAL) {
Literal literal = (Literal) arguments.get(1);
Object patternVal = literal.value();
if (patternVal == null) {
return this;
}
pattern = ((BytesRef) patternVal).utf8ToString();
}
BytesRef flags = null;
if (arguments.size() == 4) {
assert arguments.get(3).symbolType() == SymbolType.LITERAL : "4th argument must be of type " + SymbolType.LITERAL;
flags = (BytesRef) ((Literal) arguments.get(2)).value();
}
if (pattern != null) {
regexMatcher = new RegexMatcher(pattern, flags);
} else {
regexMatcher = null;
}
return this;
}
Aggregations