use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueFromExpressionEquals.
@Test
public void shouldExtractKeyValueFromExpressionEquals() {
// Given:
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new IntegerLiteral(1)));
QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions);
// When:
final List<LookupConstraint> keys = filterNode.getLookupConstraints();
// Then:
assertThat(filterNode.isWindowed(), is(false));
assertThat(keys.size(), is(1));
final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
assertThat(keyConstraint.getKey(), is(GenericKey.genericKey(-1)));
assertThat(keyConstraint.getWindowBounds(), is(Optional.empty()));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowOnMultiColKeySchema.
@Test
public void shouldThrowOnMultiColKeySchema() {
// Given:
final LogicalSchema multiSchema = LogicalSchema.builder().keyColumn(ColumnName.of("K"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K2"), SqlTypes.INTEGER).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new IntegerLiteral(1)));
when(source.getSchema()).thenReturn(multiSchema);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("Multi-column sources must specify every key in the WHERE clause. Specified: [`K`] Expected: [`K` INTEGER KEY, `K2` INTEGER KEY]."));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForDecimalUnaryPlus.
@Test
public void shouldGenerateCorrectCodeForDecimalUnaryPlus() {
// Given:
final ArithmeticUnaryExpression binExp = new ArithmeticUnaryExpression(Optional.empty(), Sign.PLUS, new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")));
// When:
final String java = sqlToJavaVisitor.process(binExp);
// Then:
assertThat(java, is("(COL8.plus(new MathContext(2, RoundingMode.UNNECESSARY)))"));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class KsqlParserTest method shouldParseDoubleNegativeInteger.
@Test
public void shouldParseDoubleNegativeInteger() {
final String queryStr = "SELECT -(-12345) FROM test1;";
final Statement statement = KsqlParserTestUtil.buildSingleAst(queryStr, metaStore).getStatement();
assertThat(statement, instanceOf(Query.class));
final Query query = (Query) statement;
final SingleColumn column0 = (SingleColumn) query.getSelect().getSelectItems().get(0);
assertThat(column0.getAlias().isPresent(), is(false));
assertThat(column0.getExpression(), instanceOf(ArithmeticUnaryExpression.class));
final ArithmeticUnaryExpression aue = (ArithmeticUnaryExpression) column0.getExpression();
assertThat(aue.getSign(), equalTo(Sign.MINUS));
assertThat(((IntegerLiteral) aue.getValue()).getValue(), equalTo(-12345));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteArithmeticUnary.
@Test
public void shouldRewriteArithmeticUnary() {
// Given:
final ArithmeticUnaryExpression parsed = parseExpression("-(1)");
when(processor.apply(parsed.getValue(), context)).thenReturn(expr1);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new ArithmeticUnaryExpression(parsed.getLocation(), parsed.getSign(), expr1)));
}
Aggregations