@Override public AbstractStreamCreateStatement copyWith(final List<TableElement> elements, final Map<String, Expression> properties) { return new CreateStream(name, elements, notExists, properties); }
protected Node visitCreateStream(final CreateStream node, final Object context) { return new CreateStream( node.getLocation(), node.getName(), node.getElements().stream() .map(tableElement -> (TableElement) process(tableElement, context)) .collect(Collectors.toList()), node.isNotExists(), node.getProperties().entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> (Expression) process(e.getValue(), context) )) ); }
@Test public void shouldRunCsStatement() { // Given: final PreparedStatement<CreateStream> cs = new PreparedStatement<>("CS", new CreateStream(SOME_NAME, emptyList(), false, emptyMap())); when(engine.parseStatements(anyString())).thenReturn(ImmutableList.of(cs)); // When: standaloneExecutor.start(); // Then: verify(engine).execute(cs, ksqlConfig, emptyMap()); }
@Override public Node visitCreateStream(final SqlBaseParser.CreateStreamContext context) { return new CreateStream( Optional.of(getLocation(context)), getQualifiedName(context.qualifiedName()), visit(context.tableElement(), TableElement.class), context.EXISTS() != null, processTableProperties(context.tableProperties()) ); }
@Test public void shouldRunSetStatements() { // Given: when(engine.parseStatements(anyString())).thenReturn(ImmutableList.of( new PreparedStatement<>("CS", new SetProperty(Optional.empty(), "name", "value")), new PreparedStatement<>("CS", new CreateStream(SOME_NAME, emptyList(), false, emptyMap())) )); // When: standaloneExecutor.start(); // Then: verify(engine) .execute(any(), any(), eq(ImmutableMap.of("name", "value"))); }
@Test public void shouldRunUnSetStatements() { // Given: when(engine.parseStatements(anyString())).thenReturn(ImmutableList.of( new PreparedStatement<>("SET", new SetProperty(Optional.empty(), "name", "value")), new PreparedStatement<>("UNSET", new UnsetProperty(Optional.empty(), "name")), new PreparedStatement<>("CS", new CreateStream(SOME_NAME, emptyList(), false, emptyMap())) )); // When: standaloneExecutor.start(); // Then: verify(engine).execute(any(), any(), eq(emptyMap())); }
@Test public void shouldFormatCreateWithEmptySchema() { final CreateStream createStream = new CreateStream( QualifiedName.of("TEST"), Collections.emptyList(), false, Collections.singletonMap( DdlConfig.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral("topic_test") )); final String sql = SqlFormatter.formatSql(createStream); final String expectedSql = "CREATE STREAM TEST \n WITH (KAFKA_TOPIC='topic_test');"; assertThat(sql, equalTo(expectedSql)); }
@Test public void testFormatSql() { final ArrayList<TableElement> tableElements = new ArrayList<>(); tableElements.add(new TableElement("GROUP", new PrimitiveType(Type.KsqlType.STRING))); tableElements.add(new TableElement("NOLIT", new PrimitiveType(Type.KsqlType.STRING))); tableElements.add(new TableElement("Having", new PrimitiveType(Type.KsqlType.STRING))); final CreateStream createStream = new CreateStream( QualifiedName.of("TEST"), tableElements, false, Collections.singletonMap( DdlConfig.TOPIC_NAME_PROPERTY, new StringLiteral("topic_test") )); final String sql = SqlFormatter.formatSql(createStream); assertThat("literal escaping failure", sql, containsString("`GROUP` STRING")); assertThat("not literal escaping failure", sql, containsString("NOLIT STRING")); assertThat("lowercase literal escaping failure", sql, containsString("`Having` STRING")); final List<PreparedStatement<?>> statements = new KsqlParser().buildAst(sql, MetaStoreFixture.getNewMetaStore(new TestFunctionRegistry())); assertFalse("formatted sql parsing error", statements.isEmpty()); }
new CreateStream( QualifiedName.of(COMMANDS_STREAM_NAME), Collections.singletonList(new TableElement(