Search in sources :

Example 11 with Literal

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

the class CreateSourcePropertiesTest method shouldThrowOnConstructionOnUnknownWindowType.

@Test
public void shouldThrowOnConstructionOnUnknownWindowType() {
    // Given:
    final Map<String, Literal> props = ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CreateConfigs.WINDOW_TYPE_PROPERTY, new StringLiteral("Unknown")).build();
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CreateSourceProperties.from(props));
    // Then:
    assertThat(e.getMessage(), containsString("Invalid value Unknown for property WINDOW_TYPE: " + "String must be one of: SESSION, HOPPING, TUMBLING, null"));
}
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 12 with Literal

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

the class CreateSourcePropertiesTest method shouldThrowOnSessionWindowWithSize.

@Test
public void shouldThrowOnSessionWindowWithSize() {
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(WINDOW_TYPE_PROPERTY, new StringLiteral("SESSION")).put(WINDOW_SIZE_PROPERTY, new StringLiteral("2 MILLISECONDS")).build()));
    // Then:
    assertThat(e.getMessage(), containsString("'WINDOW_SIZE' should not be set for SESSION windows."));
}
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 13 with Literal

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

the class CreateSourcePropertiesTest method shouldSetSessionWindow.

@Test
public void shouldSetSessionWindow() {
    // When:
    final CreateSourceProperties properties = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CreateConfigs.WINDOW_TYPE_PROPERTY, new StringLiteral("SESSION")).build());
    // Then:
    assertThat(properties.getWindowType(), is(Optional.of(WindowType.SESSION)));
}
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 14 with Literal

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

the class CreateSourcePropertiesTest method shouldSetValidAvroSchemaName.

@Test
public void shouldSetValidAvroSchemaName() {
    // When:
    final CreateSourceProperties properties = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("AvRo")).put(CommonCreateConfigs.VALUE_AVRO_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 15 with Literal

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

the class CreateSourcePropertiesTest method shouldThrowOnConstructionOnInvalidDuration.

@Test
public void shouldThrowOnConstructionOnInvalidDuration() {
    // Given:
    final Map<String, Literal> props = ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CreateConfigs.WINDOW_TYPE_PROPERTY, new StringLiteral("HOPPING")).put(CreateConfigs.WINDOW_SIZE_PROPERTY, new StringLiteral("2 HOURS")).build();
    when(durationParser.apply(any())).thenThrow(new IllegalArgumentException("a failure reason"));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> new CreateSourceProperties(props, durationParser));
    // Then:
    assertThat(e.getMessage(), containsString("Error in WITH clause property 'WINDOW_SIZE': " + "a failure reason" + System.lineSeparator() + "Example valid value: '10 SECONDS'"));
}
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)

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