use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatCreateTableStatementWithExplicitTimestamp.
@Test
public void shouldFormatCreateTableStatementWithExplicitTimestamp() {
// Given:
final CreateSourceProperties props = CreateSourceProperties.from(new ImmutableMap.Builder<String, Literal>().putAll(SOME_WITH_PROPS.copyOfOriginalLiterals()).put(CommonCreateConfigs.TIMESTAMP_NAME_PROPERTY, new StringLiteral("Foo")).put(CommonCreateConfigs.TIMESTAMP_FORMAT_PROPERTY, new StringLiteral("%s")).build());
final CreateTable createTable = new CreateTable(TEST, ELEMENTS_WITH_PRIMARY_KEY, false, false, props, false);
// When:
final String sql = SqlFormatter.formatSql(createTable);
// Then:
assertThat(sql, is("CREATE TABLE TEST (`k3` STRING PRIMARY KEY, `Foo` STRING) " + "WITH (KAFKA_TOPIC='topic_test', " + "TIMESTAMP='Foo', TIMESTAMP_FORMAT='%s', VALUE_FORMAT='JSON');"));
}
use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class SqlFormatterTest method shouldFormatCreateSourceTableStatement.
@Test
public void shouldFormatCreateSourceTableStatement() {
// 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, false, false, props, true);
// When:
final String sql = SqlFormatter.formatSql(createTable);
// Then:
assertThat(sql, is("CREATE SOURCE 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 SqlFormatterTest method shouldFormatCreateOrReplaceStreamStatement.
@Test
public void shouldFormatCreateOrReplaceStreamStatement() {
// Given:
final CreateSourceProperties props = CreateSourceProperties.from(new ImmutableMap.Builder<String, Literal>().putAll(SOME_WITH_PROPS.copyOfOriginalLiterals()).build());
final CreateStream createTable = new CreateStream(TEST, ELEMENTS_WITHOUT_KEY, true, false, props, false);
// When:
final String sql = SqlFormatter.formatSql(createTable);
// Then:
assertThat(sql, is("CREATE OR REPLACE STREAM TEST (`Foo` STRING, `Bar` 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 CreateSourceAsProperties method withTopic.
public CreateSourceAsProperties withTopic(final String name, final int partitions, final short replicas) {
final Map<String, Literal> originals = props.copyOfOriginalLiterals();
originals.put(CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral(name));
originals.put(CommonCreateConfigs.SOURCE_NUMBER_OF_PARTITIONS, new IntegerLiteral(partitions));
originals.put(CommonCreateConfigs.SOURCE_NUMBER_OF_REPLICAS, new IntegerLiteral(replicas));
return new CreateSourceAsProperties(originals);
}
use of io.confluent.ksql.execution.expression.tree.Literal in project ksql by confluentinc.
the class UdafUtil method createAggregateFunctionInitArgs.
public static AggregateFunctionInitArguments createAggregateFunctionInitArgs(final int udafIndex, final FunctionCall functionCall, final KsqlConfig config) {
final List<Expression> args = functionCall.getArguments();
final List<Object> initArgs = new ArrayList<>(Math.max(0, args.size() - 1));
// args for index > 0 must be literals:
for (int idx = 1; idx < args.size(); idx++) {
final Expression param = args.get(idx);
if (!(param instanceof Literal)) {
throw new KsqlException("Parameter " + (idx + 1) + " passed to function " + functionCall.getName().text() + " must be a literal constant, but was expression: '" + param + "'");
}
initArgs.add(((Literal) param).getValue());
}
final Map<String, Object> functionConfig = config.getKsqlFunctionsConfigProps(functionCall.getName().text());
return new AggregateFunctionInitArguments(udafIndex, functionConfig, initArgs);
}
Aggregations