Search in sources :

Example 1 with PartialFunction

use of scala.PartialFunction in project OpenLineage by OpenLineage.

the class InternalEventHandlerFactory method createInputDatasetBuilder.

@Override
public Collection<PartialFunction<Object, List<InputDataset>>> createInputDatasetBuilder(OpenLineageContext context) {
    ImmutableList builders = ImmutableList.<PartialFunction<Object, List<InputDataset>>>builder().addAll(generate(eventHandlerFactories, factory -> factory.createInputDatasetBuilder(context))).addAll(DatasetBuilderFactoryProvider.getInstance().getInputBuilders(context)).build();
    context.getInputDatasetBuilders().addAll(builders);
    return builders;
}
Also used : Spliterators(java.util.Spliterators) InputDataset(io.openlineage.client.OpenLineage.InputDataset) OutputDatasetFacet(io.openlineage.client.OpenLineage.OutputDatasetFacet) Function(java.util.function.Function) SparkVersionFacetBuilder(io.openlineage.spark.agent.facets.builder.SparkVersionFacetBuilder) ImmutableList(com.google.common.collect.ImmutableList) OutputDataset(io.openlineage.client.OpenLineage.OutputDataset) ErrorFacetBuilder(io.openlineage.spark.agent.facets.builder.ErrorFacetBuilder) OutputStatisticsOutputDatasetFacetBuilder(io.openlineage.spark.agent.facets.builder.OutputStatisticsOutputDatasetFacetBuilder) JobFacet(io.openlineage.client.OpenLineage.JobFacet) DatabricksEnvironmentFacetBuilder(io.openlineage.spark.agent.facets.builder.DatabricksEnvironmentFacetBuilder) StreamSupport(java.util.stream.StreamSupport) LogicalPlanRunFacetBuilder(io.openlineage.spark.agent.facets.builder.LogicalPlanRunFacetBuilder) LogicalPlan(org.apache.spark.sql.catalyst.plans.logical.LogicalPlan) PartialFunction(scala.PartialFunction) OpenLineageContext(io.openlineage.spark.api.OpenLineageContext) Collection(java.util.Collection) InputDatasetFacet(io.openlineage.client.OpenLineage.InputDatasetFacet) ServiceLoader(java.util.ServiceLoader) DatasetFacet(io.openlineage.client.OpenLineage.DatasetFacet) Collectors(java.util.stream.Collectors) List(java.util.List) OpenLineageEventHandlerFactory(io.openlineage.spark.api.OpenLineageEventHandlerFactory) CustomFacetBuilder(io.openlineage.spark.api.CustomFacetBuilder) Builder(com.google.common.collect.ImmutableList.Builder) Spliterator(java.util.Spliterator) RunFacet(io.openlineage.client.OpenLineage.RunFacet) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with PartialFunction

use of scala.PartialFunction in project OpenLineage by OpenLineage.

the class BaseVisitorFactory method getOutputVisitors.

@Override
public List<PartialFunction<LogicalPlan, List<OpenLineage.OutputDataset>>> getOutputVisitors(OpenLineageContext context) {
    DatasetFactory<OpenLineage.OutputDataset> factory = DatasetFactory.output(context.getOpenLineage());
    List<PartialFunction<LogicalPlan, List<OpenLineage.OutputDataset>>> outputCommonVisitors = getCommonVisitors(context, factory);
    List<PartialFunction<LogicalPlan, List<OpenLineage.OutputDataset>>> list = new ArrayList<>(outputCommonVisitors);
    list.add(new InsertIntoDataSourceDirVisitor(context));
    list.add(new InsertIntoDataSourceVisitor(context));
    list.add(new InsertIntoHadoopFsRelationVisitor(context));
    list.add(new CreateDataSourceTableAsSelectCommandVisitor(context));
    list.add(new InsertIntoDirVisitor(context));
    if (InsertIntoHiveTableVisitor.hasHiveClasses()) {
        list.add(new InsertIntoHiveTableVisitor(context));
        list.add(new InsertIntoHiveDirVisitor(context));
        list.add(new CreateHiveTableAsSelectCommandVisitor(context));
    }
    if (OptimizedCreateHiveTableAsSelectCommandVisitor.hasClasses()) {
        list.add(new OptimizedCreateHiveTableAsSelectCommandVisitor(context));
    }
    list.add(new CreateDataSourceTableCommandVisitor(context));
    list.add(new LoadDataCommandVisitor(context));
    list.add(new AlterTableRenameCommandVisitor(context));
    list.add(new AlterTableAddColumnsCommandVisitor(context));
    list.add(new CreateTableCommandVisitor(context));
    list.add(new DropTableCommandVisitor(context));
    list.add(new TruncateTableCommandVisitor(context));
    return list;
}
Also used : AlterTableRenameCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.AlterTableRenameCommandVisitor) PartialFunction(scala.PartialFunction) OptimizedCreateHiveTableAsSelectCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.OptimizedCreateHiveTableAsSelectCommandVisitor) TruncateTableCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.TruncateTableCommandVisitor) DropTableCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.DropTableCommandVisitor) ArrayList(java.util.ArrayList) CreateDataSourceTableCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.CreateDataSourceTableCommandVisitor) LoadDataCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.LoadDataCommandVisitor) CreateDataSourceTableAsSelectCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.CreateDataSourceTableAsSelectCommandVisitor) InsertIntoHiveDirVisitor(io.openlineage.spark.agent.lifecycle.plan.InsertIntoHiveDirVisitor) InsertIntoHiveTableVisitor(io.openlineage.spark.agent.lifecycle.plan.InsertIntoHiveTableVisitor) CreateTableCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.CreateTableCommandVisitor) CreateHiveTableAsSelectCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.CreateHiveTableAsSelectCommandVisitor) OptimizedCreateHiveTableAsSelectCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.OptimizedCreateHiveTableAsSelectCommandVisitor) InsertIntoDirVisitor(io.openlineage.spark.agent.lifecycle.plan.InsertIntoDirVisitor) InsertIntoDataSourceVisitor(io.openlineage.spark.agent.lifecycle.plan.InsertIntoDataSourceVisitor) AlterTableAddColumnsCommandVisitor(io.openlineage.spark.agent.lifecycle.plan.AlterTableAddColumnsCommandVisitor) InsertIntoHadoopFsRelationVisitor(io.openlineage.spark.agent.lifecycle.plan.InsertIntoHadoopFsRelationVisitor) InsertIntoDataSourceDirVisitor(io.openlineage.spark.agent.lifecycle.plan.InsertIntoDataSourceDirVisitor)

Example 3 with PartialFunction

use of scala.PartialFunction in project ditto by eclipse.

the class StreamingSessionActor method createOutgoingSignalBehavior.

private Receive createOutgoingSignalBehavior() {
    final PartialFunction<Object, Object> setCorrelationIdAndStartAckForwarder = new PFBuilder<>().match(Signal.class, this::startAckForwarder).match(DittoRuntimeException.class, x -> x).build();
    final Receive publishSignal = ReceiveBuilder.create().match(SubscriptionEvent.class, signal -> {
        logger.debug("Got SubscriptionEvent in <{}> session, publishing: {}", type, signal);
        eventAndResponsePublisher.offer(SessionedJsonifiable.subscription(signal));
    }).match(CommandResponse.class, this::publishResponseOrError).match(DittoRuntimeException.class, this::publishResponseOrError).match(Signal.class, this::isSameOrigin, signal -> logger.withCorrelationId(signal).debug("Got Signal of type <{}> in <{}> session, but this was issued by " + " this connection itself, not publishing", signal.getType(), type)).match(Signal.class, signal -> {
        // check if this session is "allowed" to receive the Signal
        final var streamingType = determineStreamingType(signal);
        @Nullable final var session = streamingSessions.get(streamingType);
        if (null != session && isSessionAllowedToReceiveSignal(signal, session, streamingType)) {
            final ThreadSafeDittoLoggingAdapter l = logger.withCorrelationId(signal);
            l.info("Publishing Signal of type <{}> in <{}> session", signal.getType(), type);
            l.debug("Publishing Signal of type <{}> in <{}> session: {}", type, signal.getType(), signal);
            final DittoHeaders sessionHeaders = DittoHeaders.newBuilder().authorizationContext(authorizationContext).schemaVersion(jsonSchemaVersion).build();
            final var sessionedJsonifiable = SessionedJsonifiable.signal(signal, sessionHeaders, session);
            eventAndResponsePublisher.offer(sessionedJsonifiable);
        }
    }).matchEquals(Done.getInstance(), done -> {
    /* already done, nothing to publish */
    }).build();
    return addPreprocessors(List.of(setCorrelationIdAndStartAckForwarder), publishSignal);
}
Also used : EntityIdPlaceholder(org.eclipse.ditto.connectivity.api.placeholders.EntityIdPlaceholder) PFBuilder(akka.japi.pf.PFBuilder) StreamingType(org.eclipse.ditto.internal.utils.pubsub.StreamingType) Terminated(akka.actor.Terminated) Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) Signal(org.eclipse.ditto.base.model.signals.Signal) DittoHeaderDefinition(org.eclipse.ditto.base.model.headers.DittoHeaderDefinition) RqlPredicateParser(org.eclipse.ditto.rql.parser.RqlPredicateParser) MessageCommandAckRequestSetter(org.eclipse.ditto.messages.model.signals.commands.acks.MessageCommandAckRequestSetter) DittoRuntimeException(org.eclipse.ditto.base.model.exceptions.DittoRuntimeException) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) InvalidJwt(org.eclipse.ditto.gateway.service.streaming.InvalidJwt) DittoProtocolSub(org.eclipse.ditto.internal.utils.pubsub.DittoProtocolSub) ActorRef(akka.actor.ActorRef) Duration(java.time.Duration) Map(java.util.Map) RefreshSession(org.eclipse.ditto.gateway.service.streaming.RefreshSession) CommandResponse(org.eclipse.ditto.base.model.signals.commands.CommandResponse) PolicyAnnouncement(org.eclipse.ditto.policies.model.signals.announcements.PolicyAnnouncement) EnumSet(java.util.EnumSet) NamespaceReader(org.eclipse.ditto.base.model.namespaces.NamespaceReader) SubscriptionManager(org.eclipse.ditto.internal.utils.search.SubscriptionManager) SourceQueueWithComplete(akka.stream.javadsl.SourceQueueWithComplete) SubscriptionEvent(org.eclipse.ditto.thingsearch.model.signals.events.SubscriptionEvent) PartialFunction(scala.PartialFunction) EnumMap(java.util.EnumMap) SignalInformationPoint(org.eclipse.ditto.internal.models.signal.SignalInformationPoint) QueryFilterCriteriaFactory(org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory) Done(akka.Done) Collection(java.util.Collection) ThingLiveCommandAckRequestSetter(org.eclipse.ditto.things.model.signals.commands.acks.ThingLiveCommandAckRequestSetter) GatewayInternalErrorException(org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayInternalErrorException) Set(java.util.Set) GatewayWebsocketSessionExpiredException(org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayWebsocketSessionExpiredException) Instant(java.time.Instant) FatalPubSubException(org.eclipse.ditto.base.model.acks.FatalPubSubException) DittoLoggerFactory(org.eclipse.ditto.internal.utils.akka.logging.DittoLoggerFactory) HeaderTranslator(org.eclipse.ditto.protocol.HeaderTranslator) List(java.util.List) ResourcePlaceholder(org.eclipse.ditto.protocol.placeholders.ResourcePlaceholder) Optional(java.util.Optional) Props(akka.actor.Props) Connect(org.eclipse.ditto.gateway.service.streaming.Connect) StartStreaming(org.eclipse.ditto.gateway.service.streaming.StartStreaming) ThingSearchCommand(org.eclipse.ditto.thingsearch.model.signals.commands.ThingSearchCommand) Event(org.eclipse.ditto.base.model.signals.events.Event) AcknowledgementConfig(org.eclipse.ditto.internal.models.acks.config.AcknowledgementConfig) AcknowledgementLabel(org.eclipse.ditto.base.model.acks.AcknowledgementLabel) AuthorizationContext(org.eclipse.ditto.base.model.auth.AuthorizationContext) Jwt(org.eclipse.ditto.gateway.service.streaming.Jwt) DittoHeaderInvalidException(org.eclipse.ditto.base.model.exceptions.DittoHeaderInvalidException) ThreadSafeDittoLoggingAdapter(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLoggingAdapter) GatewayWebsocketSessionClosedException(org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayWebsocketSessionClosedException) AbstractActorWithTimers(akka.actor.AbstractActorWithTimers) Nullable(javax.annotation.Nullable) JwtAuthenticationResultProvider(org.eclipse.ditto.gateway.service.security.authentication.jwt.JwtAuthenticationResultProvider) TopicPathPlaceholder(org.eclipse.ditto.protocol.placeholders.TopicPathPlaceholder) JsonSchemaVersion(org.eclipse.ditto.base.model.json.JsonSchemaVersion) AcknowledgementLabelNotDeclaredException(org.eclipse.ditto.base.model.acks.AcknowledgementLabelNotDeclaredException) AcknowledgementAggregatorActorStarter(org.eclipse.ditto.internal.models.acks.AcknowledgementAggregatorActorStarter) StopStreaming(org.eclipse.ditto.gateway.service.streaming.StopStreaming) ImmutableJsonWebToken(org.eclipse.ditto.jwt.model.ImmutableJsonWebToken) TimePlaceholder(org.eclipse.ditto.placeholders.TimePlaceholder) ThingModifyCommandAckRequestSetter(org.eclipse.ditto.things.model.signals.commands.acks.ThingModifyCommandAckRequestSetter) JwtValidator(org.eclipse.ditto.gateway.service.security.authentication.jwt.JwtValidator) IncomingSignal(org.eclipse.ditto.gateway.service.streaming.IncomingSignal) AcknowledgementForwarderActor(org.eclipse.ditto.internal.models.acks.AcknowledgementForwarderActor) ReceiveBuilder(akka.japi.pf.ReceiveBuilder) AcknowledgementLabelNotUniqueException(org.eclipse.ditto.base.model.acks.AcknowledgementLabelNotUniqueException) Signal(org.eclipse.ditto.base.model.signals.Signal) IncomingSignal(org.eclipse.ditto.gateway.service.streaming.IncomingSignal) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ThreadSafeDittoLoggingAdapter(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLoggingAdapter) CommandResponse(org.eclipse.ditto.base.model.signals.commands.CommandResponse) DittoRuntimeException(org.eclipse.ditto.base.model.exceptions.DittoRuntimeException) Nullable(javax.annotation.Nullable)

Example 4 with PartialFunction

use of scala.PartialFunction in project OpenLineage by OpenLineage.

the class InternalEventHandlerFactory method createOutputDatasetBuilder.

@Override
public Collection<PartialFunction<Object, List<OutputDataset>>> createOutputDatasetBuilder(OpenLineageContext context) {
    ImmutableList outputDatasetBuilders = ImmutableList.<PartialFunction<Object, List<OutputDataset>>>builder().addAll(generate(eventHandlerFactories, factory -> factory.createOutputDatasetBuilder(context))).addAll(DatasetBuilderFactoryProvider.getInstance().getOutputBuilders(context)).build();
    context.getOutputDatasetBuilders().addAll(outputDatasetBuilders);
    return outputDatasetBuilders;
}
Also used : Spliterators(java.util.Spliterators) InputDataset(io.openlineage.client.OpenLineage.InputDataset) OutputDatasetFacet(io.openlineage.client.OpenLineage.OutputDatasetFacet) Function(java.util.function.Function) SparkVersionFacetBuilder(io.openlineage.spark.agent.facets.builder.SparkVersionFacetBuilder) ImmutableList(com.google.common.collect.ImmutableList) OutputDataset(io.openlineage.client.OpenLineage.OutputDataset) ErrorFacetBuilder(io.openlineage.spark.agent.facets.builder.ErrorFacetBuilder) OutputStatisticsOutputDatasetFacetBuilder(io.openlineage.spark.agent.facets.builder.OutputStatisticsOutputDatasetFacetBuilder) JobFacet(io.openlineage.client.OpenLineage.JobFacet) DatabricksEnvironmentFacetBuilder(io.openlineage.spark.agent.facets.builder.DatabricksEnvironmentFacetBuilder) StreamSupport(java.util.stream.StreamSupport) LogicalPlanRunFacetBuilder(io.openlineage.spark.agent.facets.builder.LogicalPlanRunFacetBuilder) LogicalPlan(org.apache.spark.sql.catalyst.plans.logical.LogicalPlan) PartialFunction(scala.PartialFunction) OpenLineageContext(io.openlineage.spark.api.OpenLineageContext) Collection(java.util.Collection) InputDatasetFacet(io.openlineage.client.OpenLineage.InputDatasetFacet) ServiceLoader(java.util.ServiceLoader) DatasetFacet(io.openlineage.client.OpenLineage.DatasetFacet) Collectors(java.util.stream.Collectors) List(java.util.List) OpenLineageEventHandlerFactory(io.openlineage.spark.api.OpenLineageEventHandlerFactory) CustomFacetBuilder(io.openlineage.spark.api.CustomFacetBuilder) Builder(com.google.common.collect.ImmutableList.Builder) Spliterator(java.util.Spliterator) RunFacet(io.openlineage.client.OpenLineage.RunFacet) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 5 with PartialFunction

use of scala.PartialFunction in project OpenLineage by OpenLineage.

the class BaseVisitorFactory method getBaseCommonVisitors.

protected <D extends Dataset> List<PartialFunction<LogicalPlan, List<D>>> getBaseCommonVisitors(OpenLineageContext context, DatasetFactory<D> factory) {
    List<PartialFunction<LogicalPlan, List<D>>> list = new ArrayList<>();
    list.add(new LogicalRDDVisitor(context, factory));
    if (BigQueryNodeVisitor.hasBigQueryClasses()) {
        list.add(new BigQueryNodeVisitor(context, factory));
    }
    if (KafkaRelationVisitor.hasKafkaClasses()) {
        list.add(new KafkaRelationVisitor(context, factory));
    }
    if (SqlDWDatabricksVisitor.hasSqlDWDatabricksClasses()) {
        list.add(new SqlDWDatabricksVisitor(context, factory));
    }
    return list;
}
Also used : LogicalRDDVisitor(io.openlineage.spark.agent.lifecycle.plan.LogicalRDDVisitor) PartialFunction(scala.PartialFunction) ArrayList(java.util.ArrayList) KafkaRelationVisitor(io.openlineage.spark.agent.lifecycle.plan.KafkaRelationVisitor) BigQueryNodeVisitor(io.openlineage.spark.agent.lifecycle.plan.BigQueryNodeVisitor) SqlDWDatabricksVisitor(io.openlineage.spark.agent.lifecycle.plan.SqlDWDatabricksVisitor)

Aggregations

PartialFunction (scala.PartialFunction)5 Collection (java.util.Collection)3 List (java.util.List)3 ImmutableList (com.google.common.collect.ImmutableList)2 Builder (com.google.common.collect.ImmutableList.Builder)2 DatasetFacet (io.openlineage.client.OpenLineage.DatasetFacet)2 InputDataset (io.openlineage.client.OpenLineage.InputDataset)2 InputDatasetFacet (io.openlineage.client.OpenLineage.InputDatasetFacet)2 JobFacet (io.openlineage.client.OpenLineage.JobFacet)2 OutputDataset (io.openlineage.client.OpenLineage.OutputDataset)2 OutputDatasetFacet (io.openlineage.client.OpenLineage.OutputDatasetFacet)2 RunFacet (io.openlineage.client.OpenLineage.RunFacet)2 DatabricksEnvironmentFacetBuilder (io.openlineage.spark.agent.facets.builder.DatabricksEnvironmentFacetBuilder)2 ErrorFacetBuilder (io.openlineage.spark.agent.facets.builder.ErrorFacetBuilder)2 LogicalPlanRunFacetBuilder (io.openlineage.spark.agent.facets.builder.LogicalPlanRunFacetBuilder)2 OutputStatisticsOutputDatasetFacetBuilder (io.openlineage.spark.agent.facets.builder.OutputStatisticsOutputDatasetFacetBuilder)2 SparkVersionFacetBuilder (io.openlineage.spark.agent.facets.builder.SparkVersionFacetBuilder)2 Done (akka.Done)1 AbstractActorWithTimers (akka.actor.AbstractActorWithTimers)1 ActorRef (akka.actor.ActorRef)1