use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testAggregationSelect.
@Test
public void testAggregationSelect() throws Exception {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select avg(load['5']) from sys.nodes");
assertThat(relation.groupBy().isEmpty(), is(true));
assertThat(relation.outputs().size(), is(1));
Function col1 = (Function) relation.outputs().get(0);
assertThat(col1.signature().getKind(), is(FunctionType.AGGREGATE));
assertThat(col1.name(), is(AverageAggregation.NAME));
}
use of io.crate.expression.symbol.Function 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.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testRewriteRegexpNoMatch.
@Test
public void testRewriteRegexpNoMatch() throws Exception {
var executor = SQLExecutor.builder(clusterService).build();
String statement = "select * from sys.nodes where sys.nodes.name !~ '[sS]omething'";
QueriedSelectRelation relation = executor.analyze(statement);
Function notFunction = (Function) relation.where();
assertThat(notFunction.name(), is(NotPredicate.NAME));
assertThat(notFunction.arguments().size(), is(1));
Function eqFunction = (Function) notFunction.arguments().get(0);
assertThat(eqFunction.name(), is(RegexpMatchOperator.NAME));
assertThat(eqFunction.arguments().size(), is(2));
List<Symbol> eqArguments = eqFunction.arguments();
assertThat(eqArguments.get(0), isReference("name"));
assertThat(eqArguments.get(1), isLiteral("[sS]omething"));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testIsNullInWhereQuery.
@Test
public void testIsNullInWhereQuery() {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select * from sys.nodes where name is null");
Function isNullFunction = (Function) relation.where();
assertThat(isNullFunction.name(), is(IsNullPredicate.NAME));
assertThat(isNullFunction.arguments().size(), is(1));
assertThat(isNullFunction.arguments().get(0), isReference("name"));
assertNotNull(relation.where());
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testSelectWithParameters.
@Test
public void testSelectWithParameters() throws Exception {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select load from sys.nodes " + "where load['1'] = ? or load['5'] <= ? or load['15'] >= ? or load['1'] = ? " + "or load['1'] = ? or name = ?");
Function whereClause = (Function) relation.where();
assertThat(whereClause.name(), is(OrOperator.NAME));
assertThat(whereClause.signature().getKind() == FunctionType.AGGREGATE, is(false));
Function function = (Function) whereClause.arguments().get(0);
assertThat(function.name(), is(OrOperator.NAME));
function = (Function) function.arguments().get(1);
assertThat(function.name(), is(EqOperator.NAME));
assertThat(function.arguments().get(1), IsInstanceOf.instanceOf(ParameterSymbol.class));
assertThat(function.arguments().get(1).valueType(), is(DataTypes.DOUBLE));
function = (Function) whereClause.arguments().get(1);
assertThat(function.name(), is(EqOperator.NAME));
assertThat(function.arguments().get(1), IsInstanceOf.instanceOf(ParameterSymbol.class));
assertThat(function.arguments().get(1).valueType(), is(DataTypes.STRING));
}
Aggregations