Search in sources :

Example 11 with LongLiteral

use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatSimpleCaseExpression.

@Test
public void shouldFormatSimpleCaseExpression() {
    final SimpleCaseExpression expression = new SimpleCaseExpression(new StringLiteral("operand"), Collections.singletonList(new WhenClause(new StringLiteral("foo"), new LongLiteral(1))), Optional.empty());
    assertThat(ExpressionFormatter.formatExpression(expression), equalTo("(CASE 'operand' WHEN 'foo' THEN 1 END)"));
}
Also used : SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 12 with LongLiteral

use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatBetweenPredicate.

@Test
public void shouldFormatBetweenPredicate() {
    final BetweenPredicate predicate = new BetweenPredicate(new StringLiteral("blah"), new LongLiteral(5), new LongLiteral(10));
    assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('blah' BETWEEN 5 AND 10)"));
}
Also used : BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 13 with LongLiteral

use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.

the class ParserUtil method visitIntegerLiteral.

public static Literal visitIntegerLiteral(final IntegerLiteralContext context) {
    final Optional<NodeLocation> location = getLocation(context);
    final long valueAsLong;
    try {
        valueAsLong = Long.parseLong(context.getText());
    } catch (final NumberFormatException e) {
        throw new ParsingException("Invalid numeric literal: " + context.getText(), location);
    }
    if (valueAsLong <= Integer.MAX_VALUE && valueAsLong >= Integer.MIN_VALUE) {
        return new IntegerLiteral(location, (int) valueAsLong);
    } else {
        return new LongLiteral(location, valueAsLong);
    }
}
Also used : NodeLocation(io.confluent.ksql.parser.NodeLocation) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) ParsingException(io.confluent.ksql.parser.ParsingException) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral)

Example 14 with LongLiteral

use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.

the class GenericRecordFactoryTest method shouldThrowOnInsertRowoffset.

@Test
public void shouldThrowOnInsertRowoffset() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).build();
    final Expression exp = new StringLiteral("a");
    when(ksqlConfig.getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED)).thenReturn(true);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(ImmutableList.of(SystemColumns.ROWTIME_NAME, KEY, SystemColumns.ROWOFFSET_NAME), ImmutableList.of(new LongLiteral(1L), exp, exp), schema, DataSourceType.KSTREAM));
    // Then:
    assertThat(e.getMessage(), containsString("Inserting into column `ROWOFFSET` is not allowed."));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) Expression(io.confluent.ksql.execution.expression.tree.Expression) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 15 with LongLiteral

use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.

the class SqlPredicateTest method shouldCompileEvaluator.

@Test
public void shouldCompileEvaluator() {
    // Given:
    predicate = new SqlPredicate(new ComparisonExpression(Type.LESS_THAN, COL0, new LongLiteral(100)), SCHEMA, KSQL_CONFIG, functionRegistry);
    transformer = predicate.getTransformer(processingLogger);
    // When:
    final Optional<GenericRow> result1 = transformer.transform("key", genericRow(99L), ctx);
    final Optional<GenericRow> result2 = transformer.transform("key", genericRow(100L), ctx);
    // Then:
    assertThat(result1, is(not(Optional.empty())));
    assertThat(result2, is(Optional.empty()));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Aggregations

LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)53 Test (org.junit.Test)49 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)35 KsqlException (io.confluent.ksql.util.KsqlException)21 InsertValues (io.confluent.ksql.parser.tree.InsertValues)20 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)17 ExecutionException (java.util.concurrent.ExecutionException)17 SerializationException (org.apache.kafka.common.errors.SerializationException)17 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)17 Expression (io.confluent.ksql.execution.expression.tree.Expression)16 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)15 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)10 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)10 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)9 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)9 BigDecimal (java.math.BigDecimal)9 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)7