use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldSupportInsertIntoWithSchemaInfereceMatch.
@Test
public void shouldSupportInsertIntoWithSchemaInfereceMatch() throws Exception {
// Given:
when(srClient.getLatestSchemaMetadata(Mockito.any())).thenReturn(new SchemaMetadata(1, 1, "\"string\""));
givenDataSourceWithSchema(TOPIC_NAME, SCHEMA, SerdeFeatures.of(SerdeFeature.SCHEMA_INFERENCE, SerdeFeature.UNWRAP_SINGLES), SerdeFeatures.of(), FormatInfo.of(FormatFactory.AVRO.name()), FormatInfo.of(FormatFactory.AVRO.name()), false, false);
final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(K0, COL0), ImmutableList.of(new StringLiteral("foo"), new StringLiteral("bar")));
// When:
executor.execute(statement, mock(SessionProperties.class), engine, serviceContext);
// Then:
verify(keySerializer).serialize(TOPIC_NAME, genericKey("foo"));
verify(valueSerializer).serialize(TOPIC_NAME, genericRow("bar", null));
verify(producer).send(new ProducerRecord<>(TOPIC_NAME, null, 1L, KEY, VALUE));
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldHandleNegativeValueExpression.
@Test
public void shouldHandleNegativeValueExpression() {
// Given:
givenSourceStreamWithSchema(SCHEMA, SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(COL0, COL1), ImmutableList.of(new StringLiteral("str"), ArithmeticUnaryExpression.negative(Optional.empty(), new LongLiteral(1))));
// When:
executor.execute(statement, mock(SessionProperties.class), engine, serviceContext);
// Then:
verify(keySerializer).serialize(TOPIC_NAME, genericKey((String) null));
verify(valueSerializer).serialize(TOPIC_NAME, genericRow("str", -1L));
verify(producer).send(new ProducerRecord<>(TOPIC_NAME, null, 1L, KEY, VALUE));
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowWhenNotAuthorizedToWriteValSchemaToSR.
@Test
public void shouldThrowWhenNotAuthorizedToWriteValSchemaToSR() throws Exception {
// Given:
when(srClient.getLatestSchemaMetadata(Mockito.any())).thenReturn(new SchemaMetadata(1, 1, "\"string\""));
givenDataSourceWithSchema(TOPIC_NAME, SCHEMA, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES), SerdeFeatures.of(), FormatInfo.of(FormatFactory.AVRO.name()), FormatInfo.of(FormatFactory.AVRO.name()), false, false);
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allColumnNames(SCHEMA), ImmutableList.of(new StringLiteral("key"), new StringLiteral("str"), new LongLiteral(2L)));
when(valueSerializer.serialize(any(), any())).thenThrow(new RuntimeException(new RestClientException("foo", 401, 1)));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), containsString("Authorization denied to Write on Schema Registry subject: [" + KsqlConstants.getSRSubject(TOPIC_NAME, false)));
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnInsertKeyHeaders.
@Test
public void shouldThrowOnInsertKeyHeaders() {
// Given:
givenSourceStreamWithSchema(SCHEMA_WITH_KEY_HEADERS, SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allColumnNames(SCHEMA_WITH_KEY_HEADERS), ImmutableList.of(new StringLiteral("key"), new StringLiteral("str"), new LongLiteral(2L), new NullLiteral(), 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, HEAD1"));
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnSchemaInferenceMismatchForKey.
@Test
public void shouldThrowOnSchemaInferenceMismatchForKey() throws Exception {
// Given:
when(srClient.getLatestSchemaMetadata(Mockito.any())).thenReturn(new SchemaMetadata(1, 1, "schema"));
givenDataSourceWithSchema(TOPIC_NAME, SCHEMA, SerdeFeatures.of(SerdeFeature.SCHEMA_INFERENCE), SerdeFeatures.of(), FormatInfo.of(FormatFactory.AVRO.name()), FormatInfo.of(FormatFactory.AVRO.name()), false, false);
final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(K0, COL0), ImmutableList.of(new StringLiteral("foo"), new StringLiteral("bar")));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), containsString("ksqlDB generated schema would overwrite existing key schema"));
assertThat(e.getMessage(), containsString("Existing Schema: schema"));
assertThat(e.getMessage(), containsString("ksqlDB Generated: {\"type\":"));
}
Aggregations