use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateComparisons_int.
@Test
public void shouldEvaluateComparisons_int() {
// Given:
final Expression expression1 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL7, new IntegerLiteral(10));
final Expression expression2 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL7, new IntegerLiteral(20));
final Expression expression3 = new ComparisonExpression(ComparisonExpression.Type.EQUAL, COL7, new DoubleLiteral(30));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
// Then:
assertThat(interpreter1.evaluate(make(7, 30)), is(true));
assertThat(interpreter1.evaluate(make(7, 4)), is(false));
assertThat(interpreter2.evaluate(make(7, 13)), is(true));
assertThat(interpreter2.evaluate(make(7, 20)), is(false));
assertThat(interpreter3.evaluate(make(7, 30)), is(true));
assertThat(interpreter3.evaluate(make(7, 31)), is(false));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateComparisons_double.
@Test
public void shouldEvaluateComparisons_double() {
// Given:
final Expression expression1 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL3, new DoubleLiteral(-10.0));
final Expression expression2 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL3, new DoubleLiteral(10));
final Expression expression3 = new ComparisonExpression(ComparisonExpression.Type.EQUAL, COL3, new DoubleLiteral(6.5));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
// Then:
assertThat(interpreter1.evaluate(make(3, 5d)), is(true));
assertThat(interpreter1.evaluate(make(3, -20d)), is(false));
assertThat(interpreter2.evaluate(make(3, 5d)), is(true));
assertThat(interpreter2.evaluate(make(3, 20d)), is(false));
assertThat(interpreter3.evaluate(make(3, 6.5d)), is(true));
assertThat(interpreter3.evaluate(make(3, 8.5d)), is(false));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateComparisons_bytes.
@Test
public void shouldEvaluateComparisons_bytes() {
// Given:
final Expression expression1 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, BYTESCOL, new BytesLiteral(ByteBuffer.wrap(new byte[] { 123 })));
final Expression expression2 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, BYTESCOL, new BytesLiteral(ByteBuffer.wrap(new byte[] { 123 })));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
// Then:
assertThat(interpreter1.evaluate(make(14, ByteBuffer.wrap(new byte[] { 123 }))), is(false));
assertThat(interpreter2.evaluate(make(14, ByteBuffer.wrap(new byte[] { 110 }))), is(true));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class KsqlParserTest method testSimpleQuery.
@Test
public void testSimpleQuery() {
final String simpleQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
final PreparedStatement<?> statement = KsqlParserTestUtil.buildSingleAst(simpleQuery, metaStore);
assertThat(statement.getStatementText(), is(simpleQuery));
assertThat(statement.getStatement(), is(instanceOf(Query.class)));
final Query query = (Query) statement.getStatement();
assertThat(query.getSelect().getSelectItems(), hasSize(3));
assertThat(query.getFrom(), not(nullValue()));
Assert.assertTrue(query.getWhere().isPresent());
assertThat(query.getWhere().get(), is(instanceOf(ComparisonExpression.class)));
final ComparisonExpression comparisonExpression = (ComparisonExpression) query.getWhere().get();
assertThat(comparisonExpression.getType().getValue(), is(">"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class KsqlParserTest method parseDouble.
private Literal parseDouble(final String literalText) {
final PreparedStatement<Query> query = KsqlParserTestUtil.buildSingleAst("SELECT * FROM TEST1 WHERE COL3 > " + literalText + ";", metaStore);
final ComparisonExpression where = (ComparisonExpression) query.getStatement().getWhere().get();
return (Literal) where.getRight();
}
Aggregations