All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.delta.flink.source.internal.enumerator.supplier.BoundedSourceSnapshotSupplier Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.delta.flink.source.internal.enumerator.supplier;

import io.delta.flink.internal.options.DeltaConnectorConfiguration;
import io.delta.flink.source.internal.DeltaSourceOptions;
import io.delta.flink.source.internal.utils.TransitiveOptional;

import io.delta.standalone.DeltaLog;
import io.delta.standalone.Snapshot;

/**
 * An implementation of {@link SnapshotSupplier} for {#link
 * {@link org.apache.flink.api.connector.source.Boundedness#BOUNDED}}
 * mode.
 */
public class BoundedSourceSnapshotSupplier extends SnapshotSupplier {

    public BoundedSourceSnapshotSupplier(DeltaLog deltaLog) {
        super(deltaLog);
    }

    /**
     * This method returns a {@link Snapshot} instance acquired from {@link #deltaLog}. This
     * implementation tries to quire the {@code Snapshot} in below order, stopping at first
     * non-empty result:
     * 
    *
  • If {@link DeltaSourceOptions#VERSION_AS_OF} was specified, use it to call * {@link DeltaLog#getSnapshotForVersionAsOf(long)}.
  • *
  • If {@link DeltaSourceOptions#TIMESTAMP_AS_OF} was specified, use it to call * {@link DeltaLog#getSnapshotForTimestampAsOf(long)}.
  • *
  • Get the head version using {@link DeltaLog#snapshot()}
  • *
* * @return A {@link Snapshot} instance or throws {@link java.util.NoSuchElementException} if no * snapshot was found. */ @Override public Snapshot getSnapshot(DeltaConnectorConfiguration sourceConfiguration) { return getSnapshotFromVersionAsOfOption(sourceConfiguration) .or(() -> getSnapshotFromTimestampAsOfOption(sourceConfiguration)) .or(this::getHeadSnapshot) .get(); } private TransitiveOptional getSnapshotFromVersionAsOfOption( DeltaConnectorConfiguration sourceConfiguration) { Long versionAsOf = sourceConfiguration.getValue(DeltaSourceOptions.VERSION_AS_OF); if (versionAsOf != null) { return TransitiveOptional.ofNullable(deltaLog.getSnapshotForVersionAsOf(versionAsOf)); } return TransitiveOptional.empty(); } private TransitiveOptional getSnapshotFromTimestampAsOfOption( DeltaConnectorConfiguration sourceConfiguration) { Long timestampAsOf = sourceConfiguration.getValue(DeltaSourceOptions.TIMESTAMP_AS_OF); if (timestampAsOf != null) { return TransitiveOptional.ofNullable( deltaLog.getSnapshotForTimestampAsOf(timestampAsOf) ); } return TransitiveOptional.empty(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy