Search in sources :

Example 36 with Literal

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

the class CreateSourceAsPropertiesTest method shouldSetKeyFullSchemaName.

@Test
public void shouldSetKeyFullSchemaName() {
    // Given:
    final CreateSourceAsProperties props = CreateSourceAsProperties.from(ImmutableMap.<String, Literal>builder().put(FORMAT_PROPERTY, new StringLiteral("Json_sr")).put(KEY_SCHEMA_FULL_NAME, new StringLiteral("KeySchema")).build());
    // Then:
    assertThat(props.getKeyFormatProperties("json_sr", "foo"), hasEntry(ConnectProperties.FULL_SCHEMA_NAME, "KeySchema"));
}
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 37 with Literal

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

the class CreateSourceAsPropertiesTest method shouldSetValueFullSchemaName.

@Test
public void shouldSetValueFullSchemaName() {
    // When:
    final CreateSourceAsProperties properties = CreateSourceAsProperties.from(ImmutableMap.<String, Literal>builder().put(CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("Protobuf")).put(CommonCreateConfigs.VALUE_SCHEMA_FULL_NAME, new StringLiteral("schema")).build());
    // Then:
    assertThat(properties.getValueFormatProperties(), hasEntry(ConnectProperties.FULL_SCHEMA_NAME, "schema"));
}
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 38 with Literal

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

the class DefaultSchemaInjectorTest method givenFormatsAndProps.

private void givenFormatsAndProps(final String keyFormat, final String valueFormat, final Map<String, Literal> additionalProps) {
    final HashMap<String, Literal> props = new HashMap<>(BASE_PROPS);
    if (keyFormat != null) {
        props.put("KEY_FORMAT", new StringLiteral(keyFormat));
    }
    if (valueFormat != null) {
        props.put("VALUE_FORMAT", new StringLiteral(valueFormat));
    }
    props.putAll(additionalProps);
    final CreateSourceProperties csProps = CreateSourceProperties.from(props);
    final CreateSourceAsProperties casProps = CreateSourceAsProperties.from(props);
    when(cs.getProperties()).thenReturn(csProps);
    when(ct.getProperties()).thenReturn(csProps);
    when(csas.getProperties()).thenReturn(casProps);
    when(ctas.getProperties()).thenReturn(casProps);
/*
    when(csas.getSink()).thenReturn(
        Sink.of(SourceName.of("csas"), true, false, casProps));
    when(ctas.getSink()).thenReturn(
        Sink.of(SourceName.of("ctas"), true, false, casProps));
     */
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) HashMap(java.util.HashMap) 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) CreateSourceAsProperties(io.confluent.ksql.parser.properties.with.CreateSourceAsProperties) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties)

Example 39 with Literal

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

the class ImplicitlyCastResolverTest method shouldNotCastToDecimal.

@Test
public void shouldNotCastToDecimal() {
    // Given
    final List<Literal> fromLiterals = Arrays.asList(new BooleanLiteral("true"), new StringLiteral("10.2"), new DecimalLiteral(BigDecimal.valueOf(10.133)));
    for (final Literal literal : fromLiterals) {
        // When
        final Expression expression = ImplicitlyCastResolver.resolve(literal, DECIMAL_5_2);
        // Then
        assertThat("Should not cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, expression, instanceOf(literal.getClass()));
        assertThat("Should not cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, expression.equals(literal), is(true));
    }
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) Expression(io.confluent.ksql.execution.expression.tree.Expression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) 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