Search in sources :

Example 41 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowOnInsertHeaders.

@Test
public void shouldThrowOnInsertHeaders() {
    // Given:
    givenSourceStreamWithSchema(SCHEMA_WITH_HEADERS, SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(allColumnNames(SCHEMA_WITH_HEADERS), ImmutableList.of(new StringLiteral("key"), new StringLiteral("str"), new LongLiteral(2L), new NullLiteral()));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getMessage(), is("Cannot insert into HEADER columns: HEAD0"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) SerializationException(org.apache.kafka.common.errors.SerializationException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) ExecutionException(java.util.concurrent.ExecutionException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.Test)

Example 42 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowOnInsertAllWithHeaders.

@Test
public void shouldThrowOnInsertAllWithHeaders() {
    // Given:
    givenSourceStreamWithSchema(SCHEMA_WITH_HEADERS, SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(), ImmutableList.of(new StringLiteral("key"), new StringLiteral("str"), new LongLiteral(2L), new NullLiteral()));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getMessage(), is("Cannot insert into HEADER columns: HEAD0"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) SerializationException(org.apache.kafka.common.errors.SerializationException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) ExecutionException(java.util.concurrent.ExecutionException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.Test)

Example 43 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowIfNotEnoughValuesSuppliedWithNoSchema.

@Test
public void shouldThrowIfNotEnoughValuesSuppliedWithNoSchema() {
    // Given:
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(), ImmutableList.of(new LongLiteral(1L)));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getCause(), (hasMessage(containsString("Expected a value for each column"))));
}
Also used : LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) SerializationException(org.apache.kafka.common.errors.SerializationException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) ExecutionException(java.util.concurrent.ExecutionException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.Test)

Example 44 with LongLiteral

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

the class InsertValuesExecutorTest method shouldThrowWhenInsertValuesOnReservedInternalTopic.

@Test
public void shouldThrowWhenInsertValuesOnReservedInternalTopic() {
    // Given
    givenDataSourceWithSchema("_confluent-ksql-default__command-topic", SCHEMA, SerdeFeatures.of(), SerdeFeatures.of(), false, false);
    final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
    final ConfiguredStatement<InsertValues> statement = ConfiguredStatement.of(PreparedStatement.of("", new InsertValues(SourceName.of("TOPIC"), allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)))), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert values into read-only topic: _confluent-ksql-default__command-topic"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) KsqlConfig(io.confluent.ksql.util.KsqlConfig) SerializationException(org.apache.kafka.common.errors.SerializationException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) ExecutionException(java.util.concurrent.ExecutionException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.Test)

Example 45 with LongLiteral

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

the class InterpretedExpressionTest method shouldEvaluateCastToInteger.

@Test
public void shouldEvaluateCastToInteger() {
    // Given:
    final Expression cast1 = new Cast(new LongLiteral(10L), new Type(SqlPrimitiveType.of("INTEGER")));
    final Expression cast2 = new Cast(new StringLiteral("1234"), new Type(SqlPrimitiveType.of("INTEGER")));
    final Expression cast3 = new Cast(new DoubleLiteral(12.5), new Type(SqlPrimitiveType.of("INTEGER")));
    final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("INTEGER")));
    // When:
    InterpretedExpression interpreter1 = interpreter(cast1);
    InterpretedExpression interpreter2 = interpreter(cast2);
    InterpretedExpression interpreter3 = interpreter(cast3);
    InterpretedExpression interpreter4 = interpreter(cast4);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(10));
    assertThat(interpreter2.evaluate(ROW), is(1234));
    assertThat(interpreter3.evaluate(ROW), is(12));
    assertThat(interpreter4.evaluate(ROW), is(4567));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) LambdaType(io.confluent.ksql.function.types.LambdaType) IntegerType(io.confluent.ksql.function.types.IntegerType) GenericType(io.confluent.ksql.function.types.GenericType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) IntervalUnitType(io.confluent.ksql.function.types.IntervalUnitType) Type(io.confluent.ksql.execution.expression.tree.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) BigDecimal(java.math.BigDecimal) 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