Search in sources :

Example 26 with Literal

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

the class CreateSourcePropertiesTest method shouldSetValueFullSchemaName.

@Test
public void shouldSetValueFullSchemaName() {
    // When:
    final CreateSourceProperties properties = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("Protobuf")).put(CommonCreateConfigs.VALUE_SCHEMA_FULL_NAME, new StringLiteral("schema")).build());
    // Then:
    assertThat(properties.getValueFormat().map(FormatInfo::getProperties).map(props -> props.get(ConnectProperties.FULL_SCHEMA_NAME)), is(Optional.of("schema")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KAFKA_TOPIC_NAME_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY) FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.FORMAT_PROPERTY) CreateSourceAsProperties.from(io.confluent.ksql.parser.properties.with.CreateSourceAsProperties.from) ColumnName(io.confluent.ksql.name.ColumnName) SourceName(io.confluent.ksql.name.SourceName) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CommonCreateConfigs(io.confluent.ksql.properties.with.CommonCreateConfigs) Function(java.util.function.Function) VALUE_SCHEMA_ID(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_SCHEMA_ID) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ConnectProperties(io.confluent.ksql.serde.connect.ConnectProperties) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Duration(java.time.Duration) Map(java.util.Map) WindowType(io.confluent.ksql.model.WindowType) CreateConfigs(io.confluent.ksql.properties.with.CreateConfigs) WINDOW_SIZE_PROPERTY(io.confluent.ksql.properties.with.CreateConfigs.WINDOW_SIZE_PROPERTY) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) TIMESTAMP_FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.TIMESTAMP_FORMAT_PROPERTY) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) KEY_FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.KEY_FORMAT_PROPERTY) VALUE_FORMAT_PROPERTY(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_FORMAT_PROPERTY) VALUE_AVRO_SCHEMA_FULL_NAME(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_AVRO_SCHEMA_FULL_NAME) ImmutableMap(com.google.common.collect.ImmutableMap) SerdeFeature(io.confluent.ksql.serde.SerdeFeature) Literal(io.confluent.ksql.execution.expression.tree.Literal) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) EqualsTester(com.google.common.testing.EqualsTester) KEY_SCHEMA_FULL_NAME(io.confluent.ksql.properties.with.CommonCreateConfigs.KEY_SCHEMA_FULL_NAME) VALUE_SCHEMA_FULL_NAME(io.confluent.ksql.properties.with.CommonCreateConfigs.VALUE_SCHEMA_FULL_NAME) WINDOW_TYPE_PROPERTY(io.confluent.ksql.properties.with.CreateConfigs.WINDOW_TYPE_PROPERTY) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) KEY_SCHEMA_ID(io.confluent.ksql.properties.with.CommonCreateConfigs.KEY_SCHEMA_ID) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FormatInfo(io.confluent.ksql.serde.FormatInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) FormatInfo(io.confluent.ksql.serde.FormatInfo) Test(org.junit.Test)

Example 27 with Literal

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

the class CreateSourcePropertiesTest method shouldSetReplicasFromNumber.

@Test
public void shouldSetReplicasFromNumber() {
    // When:
    final CreateSourceProperties properties = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CommonCreateConfigs.SOURCE_NUMBER_OF_REPLICAS, new IntegerLiteral(2)).build());
    // Then:
    assertThat(properties.getReplicas(), is(Optional.of((short) 2)));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Matchers.containsString(org.hamcrest.Matchers.containsString) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 28 with Literal

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

the class CreateSourcePropertiesTest method shouldThrowIfValueFormatAndFormatProvided.

@Test
public void shouldThrowIfValueFormatAndFormatProvided() {
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(VALUE_FORMAT_PROPERTY, new StringLiteral("JSON")).put(FORMAT_PROPERTY, new StringLiteral("KAFKA")).build()));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot supply both 'VALUE_FORMAT' and 'FORMAT' properties, " + "as 'FORMAT' sets both key and value formats."));
    assertThat(e.getMessage(), containsString("Either use just 'FORMAT', or use 'KEY_FORMAT' and 'VALUE_FORMAT'."));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 29 with Literal

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

the class CreateSourcePropertiesTest method shouldSetAvroNameOnAvroKeyFormat.

@Test
public void shouldSetAvroNameOnAvroKeyFormat() {
    // Given:
    final CreateSourceProperties props = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(FORMAT_PROPERTY, new StringLiteral("AVRO")).build());
    // When / Then:
    assertThat(props.getKeyFormat(SourceName.of("foo")).get().getFormat(), is("AVRO"));
    assertThat(props.getKeyFormat(SourceName.of("foo")).get().getProperties(), hasEntry(ConnectProperties.FULL_SCHEMA_NAME, "io.confluent.ksql.avro_schemas.FooKey"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 30 with Literal

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

the class CreateSourcePropertiesTest method shouldIncludeOnlyProvidedPropsInToString.

@Test
public void shouldIncludeOnlyProvidedPropsInToString() {
    // Given:
    final CreateSourceProperties props = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put("Wrap_Single_value", new StringLiteral("True")).build());
    // When:
    final String sql = props.toString();
    // Then:
    assertThat(sql, is("KAFKA_TOPIC='foo', WRAP_SINGLE_VALUE='True'"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Literal (io.confluent.ksql.execution.expression.tree.Literal)39 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)38 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)32 Test (org.junit.Test)32 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)28 Matchers.containsString (org.hamcrest.Matchers.containsString)27 KsqlException (io.confluent.ksql.util.KsqlException)10 ImmutableMap (com.google.common.collect.ImmutableMap)8 CreateSourceProperties (io.confluent.ksql.parser.properties.with.CreateSourceProperties)6 StringContains.containsString (org.hamcrest.core.StringContains.containsString)5 HashMap (java.util.HashMap)4 EqualsTester (com.google.common.testing.EqualsTester)3 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)3 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)3 Expression (io.confluent.ksql.execution.expression.tree.Expression)3 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)3 CreateTable (io.confluent.ksql.parser.tree.CreateTable)3 ImmutableMap.of (com.google.common.collect.ImmutableMap.of)2 WindowType (io.confluent.ksql.model.WindowType)2 ColumnName (io.confluent.ksql.name.ColumnName)2