use of io.crate.expression.symbol.Literal in project crate by crate.
the class SelectStatementAnalyzerTest method testLikeNoStringDataTypeInWhereQuery.
@Test
public void testLikeNoStringDataTypeInWhereQuery() {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select * from sys.nodes where name like 1");
// check if the implicit cast of the pattern worked
List<DataType> argumentTypes = List.of(DataTypes.STRING, DataTypes.STRING);
Function whereClause = (Function) relation.where();
assertEquals(argumentTypes, Symbols.typeView(whereClause.arguments()));
assertThat(whereClause.arguments().get(1), IsInstanceOf.instanceOf(Literal.class));
Literal stringLiteral = (Literal) whereClause.arguments().get(1);
assertThat(stringLiteral.value(), is("1"));
}
use of io.crate.expression.symbol.Literal in project crate by crate.
the class ScalarTestCase method assertNormalize.
public void assertNormalize(String functionExpression, Matcher<? super Symbol> expectedSymbol, boolean evaluate) {
// Explicit normalization happens further below
sqlExpressions.context().allowEagerNormalize(false);
Symbol functionSymbol = sqlExpressions.asSymbol(functionExpression);
if (functionSymbol instanceof Literal) {
assertThat(functionSymbol, expectedSymbol);
return;
}
Function function = (Function) functionSymbol;
FunctionImplementation impl = sqlExpressions.nodeCtx.functions().getQualified(function, txnCtx.sessionSettings().searchPath());
assertThat("Function implementation not found using full qualified lookup", impl, Matchers.notNullValue());
Symbol normalized = sqlExpressions.normalize(function);
assertThat(String.format(Locale.ENGLISH, "expected <%s> to normalize to %s", functionExpression, expectedSymbol), normalized, expectedSymbol);
if (evaluate && normalized instanceof Input && allArgsAreInputs(function.arguments())) {
Input[] inputs = new Input[function.arguments().size()];
for (int i = 0; i < inputs.length; i++) {
inputs[i] = ((Input) function.arguments().get(i));
}
Object expectedValue = ((Input) normalized).value();
assertThat(((Scalar) impl).evaluate(txnCtx, null, inputs), is(expectedValue));
assertThat(((Scalar) impl).compile(function.arguments()).evaluate(txnCtx, sqlExpressions.nodeCtx, inputs), is(expectedValue));
}
}
Aggregations