use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class ImplicitlyCastResolverTest method shouldCastToDecimal.
@Test
public void shouldCastToDecimal() {
// Given
final Map<Literal, BigDecimal> fromLiterals = ImmutableMap.of(new IntegerLiteral(5), new BigDecimal("5.00"), new LongLiteral(5), new BigDecimal("5.00"), new DoubleLiteral(5), new BigDecimal("5.00"), new DecimalLiteral(BigDecimal.TEN), new BigDecimal("10.00"), new DecimalLiteral(new BigDecimal("10.1")), new BigDecimal("10.10"));
for (final Map.Entry<Literal, BigDecimal> entry : fromLiterals.entrySet()) {
final Literal literal = entry.getKey();
final BigDecimal expected = entry.getValue();
// When
final Expression expression = ImplicitlyCastResolver.resolve(literal, DECIMAL_5_2);
// Then
assertThat("Should cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, expression, instanceOf(DecimalLiteral.class));
assertThat("Should cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, ((DecimalLiteral) expression).getValue(), is(expected));
}
}
use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class KsqlParserTest method parseDouble.
private Literal parseDouble(final String literalText) {
final PreparedStatement<Query> query = KsqlParserTestUtil.buildSingleAst("SELECT * FROM TEST1 WHERE COL3 > " + literalText + ";", metaStore);
final ComparisonExpression where = (ComparisonExpression) query.getStatement().getWhere().get();
return (Literal) where.getRight();
}
use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatCreateSourceStreamStatement.
@Test
public void shouldFormatCreateSourceStreamStatement() {
// Given:
final CreateSourceProperties props = CreateSourceProperties.from(new ImmutableMap.Builder<String, Literal>().putAll(SOME_WITH_PROPS.copyOfOriginalLiterals()).build());
final CreateStream createStream = new CreateStream(TEST, ELEMENTS_WITH_KEY, false, false, props, true);
// When:
final String sql = SqlFormatter.formatSql(createStream);
// Then:
assertThat(sql, is("CREATE SOURCE STREAM TEST (`k3` STRING KEY, `Foo` STRING) " + "WITH (KAFKA_TOPIC='topic_test', VALUE_FORMAT='JSON');"));
}
use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatCreateOrReplaceTableStatement.
@Test
public void shouldFormatCreateOrReplaceTableStatement() {
// Given:
final CreateSourceProperties props = CreateSourceProperties.from(new ImmutableMap.Builder<String, Literal>().putAll(SOME_WITH_PROPS.copyOfOriginalLiterals()).build());
final CreateTable createTable = new CreateTable(TEST, ELEMENTS_WITH_PRIMARY_KEY, true, false, props, false);
// When:
final String sql = SqlFormatter.formatSql(createTable);
// Then:
assertThat(sql, is("CREATE OR REPLACE TABLE TEST (`k3` STRING PRIMARY KEY, `Foo` STRING) " + "WITH (KAFKA_TOPIC='topic_test', VALUE_FORMAT='JSON');"));
}
use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class CreateSourceProperties method withPartitions.
public CreateSourceProperties withPartitions(final int partitions) {
final Map<String, Literal> originals = props.copyOfOriginalLiterals();
originals.put(CommonCreateConfigs.SOURCE_NUMBER_OF_PARTITIONS, new IntegerLiteral(partitions));
return new CreateSourceProperties(originals, durationParser);
}
Aggregations