Search in sources :

Example 81 with StringLiteral

use of io.confluent.ksql.execution.expression.tree.StringLiteral 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 82 with StringLiteral

use of io.confluent.ksql.execution.expression.tree.StringLiteral 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)

Example 83 with StringLiteral

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

the class CreateSourceAsPropertiesTest method shouldProperlyImplementEqualsAndHashCode.

@Test
public void shouldProperlyImplementEqualsAndHashCode() {
    final ImmutableMap<String, Literal> someConfig = ImmutableMap.of(VALUE_AVRO_SCHEMA_FULL_NAME, new StringLiteral("schema"));
    new EqualsTester().addEqualityGroup(CreateSourceAsProperties.from(someConfig), CreateSourceAsProperties.from(someConfig)).addEqualityGroup(CreateSourceAsProperties.from(ImmutableMap.of())).testEquals();
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) EqualsTester(com.google.common.testing.EqualsTester) 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 84 with StringLiteral

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

the class CreateSourceAsPropertiesTest method shouldThrowIfKeyFormatAndFormatProvided.

@Test
public void shouldThrowIfKeyFormatAndFormatProvided() {
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CreateSourceAsProperties.from(ImmutableMap.<String, Literal>builder().put(KEY_FORMAT_PROPERTY, new StringLiteral("KAFKA")).put(FORMAT_PROPERTY, new StringLiteral("JSON")).build()));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot supply both 'KEY_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) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 85 with StringLiteral

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

the class CreateSourceAsPropertiesTest method shouldIncludeOnlyProvidedPropsInToString.

@Test
public void shouldIncludeOnlyProvidedPropsInToString() {
    // Given:
    final CreateSourceAsProperties props = CreateSourceAsProperties.from(ImmutableMap.of("Wrap_Single_value", new StringLiteral("True"), "KAFKA_TOPIC", new StringLiteral("foo")));
    // 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) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)204 Test (org.junit.Test)199 Expression (io.confluent.ksql.execution.expression.tree.Expression)95 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)70 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)66 KsqlException (io.confluent.ksql.util.KsqlException)64 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)63 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)63 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)63 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)61 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)53 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)51 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)49 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)43 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)36 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)35 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)34 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)31 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)28 Matchers.containsString (org.hamcrest.Matchers.containsString)27