use of io.confluent.ksql.parser.tree.UnsetProperty in project ksql by confluentinc.
the class PropertyExecutorTest method shouldUnSetProperty.
@Test
public void shouldUnSetProperty() {
// Given:
engine.givenSource(DataSourceType.KSTREAM, "stream");
final SessionProperties sessionProperties = new SessionProperties(Collections.singletonMap(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "none"), mock(KsqlHostInfo.class), mock(URL.class), false);
final Map<String, Object> properties = sessionProperties.getMutableScopedProperties();
// When:
CUSTOM_EXECUTORS.unsetProperty().execute((ConfiguredStatement<UnsetProperty>) engine.configure("UNSET '" + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG + "';"), sessionProperties, engine.getEngine(), engine.getServiceContext());
// Then:
assertThat(properties, not(hasKey(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG)));
}
use of io.confluent.ksql.parser.tree.UnsetProperty in project ksql by confluentinc.
the class PropertyOverriderTest method shouldFailOnUnknownUnsetProperty.
@Test
public void shouldFailOnUnknownUnsetProperty() {
// Given:
final Map<String, Object> properties = new HashMap<>();
final SessionProperties sessionProperties = new SessionProperties(properties, mock(KsqlHostInfo.class), mock(URL.class), false);
// When:
final Exception e = assertThrows(KsqlStatementException.class, () -> CustomValidators.UNSET_PROPERTY.validate(ConfiguredStatement.of(PreparedStatement.of("UNSET 'consumer.invalid';", new UnsetProperty(Optional.empty(), "consumer.invalid")), SessionConfig.of(engine.getKsqlConfig(), new HashMap<>())), sessionProperties, engine.getEngine(), engine.getServiceContext()));
// Then:
assertThat(e.getMessage(), containsString("Unknown property: consumer.invalid"));
}
use of io.confluent.ksql.parser.tree.UnsetProperty in project ksql by confluentinc.
the class StandaloneExecutorTest method shouldRunUnSetStatements.
@Test
public void shouldRunUnSetStatements() {
// Given:
final PreparedStatement<SetProperty> setProp = PreparedStatement.of("SET", new SetProperty(Optional.empty(), ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"));
final PreparedStatement<UnsetProperty> unsetProp = PreparedStatement.of("UNSET", new UnsetProperty(Optional.empty(), ConsumerConfig.AUTO_OFFSET_RESET_CONFIG));
final PreparedStatement<CreateStream> cs = PreparedStatement.of("CS", new CreateStream(SOME_NAME, SOME_ELEMENTS, false, false, JSON_PROPS, false));
final ConfiguredStatement<?> configured = ConfiguredStatement.of(cs, SessionConfig.of(ksqlConfig, emptyMap()));
givenQueryFileParsesTo(setProp, unsetProp, cs);
// When:
standaloneExecutor.startAsync();
// Then:
verify(ksqlEngine).execute(serviceContext, configured);
}
use of io.confluent.ksql.parser.tree.UnsetProperty in project ksql by confluentinc.
the class KsqlTesterTest method execute.
@SuppressWarnings("unchecked")
private void execute(final ParsedStatement parsedStatement) {
final PreparedStatement<?> engineStatement = engine.prepare(parsedStatement);
final ConfiguredStatement<?> configured = ConfiguredStatement.of(engineStatement, SessionConfig.of(config, overrides));
createTopics(engineStatement);
if (engineStatement.getStatement() instanceof InsertValues) {
pipeInput((ConfiguredStatement<InsertValues>) configured);
return;
} else if (engineStatement.getStatement() instanceof SetProperty) {
PropertyOverrider.set((ConfiguredStatement<SetProperty>) configured, overrides);
return;
} else if (engineStatement.getStatement() instanceof UnsetProperty) {
PropertyOverrider.unset((ConfiguredStatement<UnsetProperty>) configured, overrides);
return;
}
final ConfiguredStatement<?> injected = formatInjector.inject(configured);
final ExecuteResult result = engine.execute(serviceContext, injected);
// is DDL statement
if (!result.getQuery().isPresent()) {
return;
}
final PersistentQueryMetadata query = (PersistentQueryMetadata) result.getQuery().get();
final Topology topology = query.getTopology();
final Properties properties = new Properties();
properties.putAll(query.getStreamsProperties());
properties.put(StreamsConfig.STATE_DIR_CONFIG, tmpFolder.getRoot().getAbsolutePath());
final TopologyTestDriver driver = new TopologyTestDriver(topology, properties);
final List<TopicInfo> inputTopics = query.getSourceNames().stream().map(sn -> engine.getMetaStore().getSource(sn)).map(ds -> new TopicInfo(ds.getKafkaTopicName(), keySerde(ds), valueSerde(ds))).collect(Collectors.toList());
// Sink may be Optional for source tables. Once source table query execution is supported, then
// we would need have a condition to not create an output topic info
final DataSource output = engine.getMetaStore().getSource(query.getSinkName().get());
final TopicInfo outputInfo = new TopicInfo(output.getKafkaTopicName(), keySerde(output), valueSerde(output));
driverPipeline.addDriver(driver, inputTopics, outputInfo);
drivers.put(query.getQueryId(), new DriverAndProperties(driver, properties));
}
use of io.confluent.ksql.parser.tree.UnsetProperty in project ksql by confluentinc.
the class KsqlContextTest method shouldUnsetProperty.
@SuppressWarnings("unchecked")
@Test
public void shouldUnsetProperty() {
// Given:
when(ksqlEngine.parse(any())).thenReturn(ImmutableList.of(PARSED_STMT_0, PARSED_STMT_0));
final Map<String, Object> properties = ImmutableMap.of(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
final PreparedStatement<UnsetProperty> unset = PreparedStatement.of("UNSET SOMETHING", new UnsetProperty(Optional.empty(), ConsumerConfig.AUTO_OFFSET_RESET_CONFIG));
when(ksqlEngine.prepare(any())).thenReturn((PreparedStatement) unset).thenReturn(PREPARED_STMT_0);
// When:
ksqlContext.sql("SQL;", properties);
// Then:
verify(ksqlEngine).execute(serviceContext, ConfiguredStatement.of(PREPARED_STMT_0, SessionConfig.of(SOME_CONFIG, ImmutableMap.of())));
}
Aggregations