Search in sources :

Example 1 with UserFunctionLoader

use of io.confluent.ksql.function.UserFunctionLoader in project ksql by confluentinc.

the class QueryAnalyzerFunctionalTest method shouldAnalyseTableFunctions.

@Test
public void shouldAnalyseTableFunctions() {
    // We need to load udfs for this
    final UserFunctionLoader loader = new UserFunctionLoader(functionRegistry, new File(""), Thread.currentThread().getContextClassLoader(), s -> false, Optional.empty(), true);
    loader.load();
    // Given:
    final Query query = givenQuery("SELECT ID, EXPLODE(ARR1) FROM SENSOR_READINGS EMIT CHANGES;");
    // When:
    final Analysis analysis = queryAnalyzer.analyze(query, Optional.empty());
    // Then:
    assertThat(analysis.getTableFunctions(), hasSize(1));
    assertThat(analysis.getTableFunctions().get(0).getName().text(), equalTo("EXPLODE"));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) UserFunctionLoader(io.confluent.ksql.function.UserFunctionLoader) File(java.io.File) Test(org.junit.Test)

Example 2 with UserFunctionLoader

use of io.confluent.ksql.function.UserFunctionLoader in project ksql by confluentinc.

the class StandaloneExecutorFactory method create.

@VisibleForTesting
static StandaloneExecutor create(final Map<String, Object> properties, final String queriesFile, final String installDir, final Function<KsqlConfig, ServiceContext> serviceContextFactory, final BiFunction<String, KsqlConfig, ConfigStore> configStoreFactory, final Function<Supplier<Boolean>, VersionCheckerAgent> versionCheckerFactory, final StandaloneExecutorConstructor constructor, final MetricCollectors metricCollectors) {
    final KsqlConfig baseConfig = new KsqlConfig(properties);
    final ServiceContext serviceContext = serviceContextFactory.apply(baseConfig);
    final String configTopicName = ReservedInternalTopics.configsTopic(baseConfig);
    KsqlInternalTopicUtils.ensureTopic(configTopicName, baseConfig, serviceContext.getTopicClient());
    final ConfigStore configStore = configStoreFactory.apply(configTopicName, baseConfig);
    final KsqlConfig ksqlConfig = configStore.getKsqlConfig();
    final ProcessingLogConfig processingLogConfig = new ProcessingLogConfig(properties);
    final ProcessingLogContext processingLogContext = ProcessingLogContext.create(processingLogConfig);
    final MutableFunctionRegistry functionRegistry = new InternalFunctionRegistry();
    final KsqlEngine ksqlEngine = new KsqlEngine(serviceContext, processingLogContext, functionRegistry, ServiceInfo.create(ksqlConfig), new SequentialQueryIdGenerator(), ksqlConfig, Collections.emptyList(), metricCollectors);
    final UserFunctionLoader udfLoader = UserFunctionLoader.newInstance(ksqlConfig, functionRegistry, installDir, metricCollectors.getMetrics());
    final VersionCheckerAgent versionChecker = versionCheckerFactory.apply(ksqlEngine::hasActiveQueries);
    return constructor.create(serviceContext, processingLogConfig, ksqlConfig, ksqlEngine, queriesFile, udfLoader, true, versionChecker, Injectors.NO_TOPIC_DELETE, metricCollectors);
}
Also used : KsqlEngine(io.confluent.ksql.engine.KsqlEngine) ProcessingLogContext(io.confluent.ksql.logging.processing.ProcessingLogContext) MutableFunctionRegistry(io.confluent.ksql.function.MutableFunctionRegistry) ServiceContext(io.confluent.ksql.services.ServiceContext) UserFunctionLoader(io.confluent.ksql.function.UserFunctionLoader) ProcessingLogConfig(io.confluent.ksql.logging.processing.ProcessingLogConfig) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KsqlVersionCheckerAgent(io.confluent.ksql.version.metrics.KsqlVersionCheckerAgent) VersionCheckerAgent(io.confluent.ksql.version.metrics.VersionCheckerAgent) KafkaConfigStore(io.confluent.ksql.rest.server.computation.KafkaConfigStore) ConfigStore(io.confluent.ksql.rest.server.computation.ConfigStore) SequentialQueryIdGenerator(io.confluent.ksql.query.id.SequentialQueryIdGenerator) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

UserFunctionLoader (io.confluent.ksql.function.UserFunctionLoader)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)1 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)1 MutableFunctionRegistry (io.confluent.ksql.function.MutableFunctionRegistry)1 ProcessingLogConfig (io.confluent.ksql.logging.processing.ProcessingLogConfig)1 ProcessingLogContext (io.confluent.ksql.logging.processing.ProcessingLogContext)1 Query (io.confluent.ksql.parser.tree.Query)1 SequentialQueryIdGenerator (io.confluent.ksql.query.id.SequentialQueryIdGenerator)1 ConfigStore (io.confluent.ksql.rest.server.computation.ConfigStore)1 KafkaConfigStore (io.confluent.ksql.rest.server.computation.KafkaConfigStore)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 KsqlConfig (io.confluent.ksql.util.KsqlConfig)1 KsqlVersionCheckerAgent (io.confluent.ksql.version.metrics.KsqlVersionCheckerAgent)1 VersionCheckerAgent (io.confluent.ksql.version.metrics.VersionCheckerAgent)1 File (java.io.File)1 Test (org.junit.Test)1