Skip to content

Commit

Permalink
[flink] fix the problem that DynamicFilteringEvent does not exist in …
Browse files Browse the repository at this point in the history
…version 1.16- of flink.
  • Loading branch information
liming30 committed Nov 13, 2023
1 parent 194bb75 commit 7179e4a
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.flink.source;

import org.apache.paimon.Snapshot;
import org.apache.paimon.flink.source.assigners.SplitAssigner;

import org.apache.flink.api.connector.source.SplitEnumerator;
import org.apache.flink.api.connector.source.SplitEnumeratorContext;

import javax.annotation.Nullable;

/** A {@link SplitEnumerator} implementation for {@link StaticFileStoreSource} input. */
public class StaticFileStoreSplitEnumerator extends StaticFileStoreSplitEnumeratorBase {

public StaticFileStoreSplitEnumerator(
SplitEnumeratorContext<FileStoreSourceSplit> context,
@Nullable Snapshot snapshot,
SplitAssigner splitAssigner) {
this(context, snapshot, splitAssigner, null);
}

public StaticFileStoreSplitEnumerator(
SplitEnumeratorContext<FileStoreSourceSplit> context,
@Nullable Snapshot snapshot,
SplitAssigner splitAssigner,
@Nullable DynamicPartitionFilteringInfo dynamicPartitionFilteringInfo) {
super(context, snapshot, splitAssigner);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.flink.source;

import org.apache.paimon.Snapshot;
import org.apache.paimon.flink.source.assigners.SplitAssigner;

import org.apache.flink.api.connector.source.SplitEnumerator;
import org.apache.flink.api.connector.source.SplitEnumeratorContext;

import javax.annotation.Nullable;

/** A {@link SplitEnumerator} implementation for {@link StaticFileStoreSource} input. */
public class StaticFileStoreSplitEnumerator extends StaticFileStoreSplitEnumeratorBase {

public StaticFileStoreSplitEnumerator(
SplitEnumeratorContext<FileStoreSourceSplit> context,
@Nullable Snapshot snapshot,
SplitAssigner splitAssigner) {
this(context, snapshot, splitAssigner, null);
}

public StaticFileStoreSplitEnumerator(
SplitEnumeratorContext<FileStoreSourceSplit> context,
@Nullable Snapshot snapshot,
SplitAssigner splitAssigner,
@Nullable DynamicPartitionFilteringInfo dynamicPartitionFilteringInfo) {
super(context, snapshot, splitAssigner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,21 @@
package org.apache.paimon.flink.source;

import org.apache.paimon.Snapshot;
import org.apache.paimon.annotation.VisibleForTesting;
import org.apache.paimon.flink.source.assigners.DynamicPartitionPruningAssigner;
import org.apache.paimon.flink.source.assigners.SplitAssigner;

import org.apache.flink.api.connector.source.SourceEvent;
import org.apache.flink.api.connector.source.SplitEnumerator;
import org.apache.flink.api.connector.source.SplitEnumeratorContext;
import org.apache.flink.api.connector.source.SplitsAssignment;
import org.apache.flink.table.connector.source.DynamicFilteringData;
import org.apache.flink.table.connector.source.DynamicFilteringEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import java.util.Collections;
import java.util.List;

import static org.apache.paimon.utils.Preconditions.checkNotNull;

/** A {@link SplitEnumerator} implementation for {@link StaticFileStoreSource} input. */
public class StaticFileStoreSplitEnumerator
implements SplitEnumerator<FileStoreSourceSplit, PendingSplitsCheckpoint> {

private static final Logger LOG = LoggerFactory.getLogger(StaticFileStoreSplitEnumerator.class);

private final SplitEnumeratorContext<FileStoreSourceSplit> context;

@Nullable private final Snapshot snapshot;

private SplitAssigner splitAssigner;
public class StaticFileStoreSplitEnumerator extends StaticFileStoreSplitEnumeratorBase {

@Nullable private final DynamicPartitionFilteringInfo dynamicPartitionFilteringInfo;

Expand All @@ -65,59 +49,10 @@ public StaticFileStoreSplitEnumerator(
@Nullable Snapshot snapshot,
SplitAssigner splitAssigner,
@Nullable DynamicPartitionFilteringInfo dynamicPartitionFilteringInfo) {
this.context = context;
this.snapshot = snapshot;
this.splitAssigner = splitAssigner;
super(context, snapshot, splitAssigner);
this.dynamicPartitionFilteringInfo = dynamicPartitionFilteringInfo;
}

@Override
public void start() {
// no resources to start
}

@Override
public void handleSplitRequest(int subtask, @Nullable String hostname) {
if (!context.registeredReaders().containsKey(subtask)) {
// reader failed between sending the request and now. skip this request.
return;
}

List<FileStoreSourceSplit> assignment = splitAssigner.getNext(subtask, hostname);
if (assignment.size() > 0) {
context.assignSplits(
new SplitsAssignment<>(Collections.singletonMap(subtask, assignment)));
} else {
context.signalNoMoreSplits(subtask);
}
}

@Override
public void addSplitsBack(List<FileStoreSourceSplit> backSplits, int subtaskId) {
splitAssigner.addSplitsBack(subtaskId, backSplits);
}

@Override
public void addReader(int subtaskId) {
// this source is purely lazy-pull-based, nothing to do upon registration
}

@Override
public PendingSplitsCheckpoint snapshotState(long checkpointId) {
return new PendingSplitsCheckpoint(
splitAssigner.remainingSplits(), snapshot == null ? null : snapshot.id());
}

@Override
public void close() {
// no resources to close
}

@Nullable
public Snapshot snapshot() {
return snapshot;
}

@Override
public void handleSourceEvent(int subtaskId, SourceEvent sourceEvent) {
if (sourceEvent instanceof DynamicFilteringEvent) {
Expand All @@ -140,12 +75,7 @@ public void handleSourceEvent(int subtaskId, SourceEvent sourceEvent) {
dynamicFilteringData);
}
} else {
LOG.error("Received unrecognized event: {}", sourceEvent);
super.handleSourceEvent(subtaskId, sourceEvent);
}
}

@VisibleForTesting
public SplitAssigner getSplitAssigner() {
return splitAssigner;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.flink.source;

import org.apache.paimon.Snapshot;
import org.apache.paimon.annotation.VisibleForTesting;
import org.apache.paimon.flink.source.assigners.SplitAssigner;

import org.apache.flink.api.connector.source.SourceEvent;
import org.apache.flink.api.connector.source.SplitEnumerator;
import org.apache.flink.api.connector.source.SplitEnumeratorContext;
import org.apache.flink.api.connector.source.SplitsAssignment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import java.util.Collections;
import java.util.List;

/** A {@link SplitEnumerator} base implementation for {@link StaticFileStoreSource} input. */
public abstract class StaticFileStoreSplitEnumeratorBase
implements SplitEnumerator<FileStoreSourceSplit, PendingSplitsCheckpoint> {

protected static final Logger LOG =
LoggerFactory.getLogger(StaticFileStoreSplitEnumeratorBase.class);

protected final SplitEnumeratorContext<FileStoreSourceSplit> context;

@Nullable protected final Snapshot snapshot;

protected SplitAssigner splitAssigner;

public StaticFileStoreSplitEnumeratorBase(
SplitEnumeratorContext<FileStoreSourceSplit> context,
@Nullable Snapshot snapshot,
SplitAssigner splitAssigner) {
this.context = context;
this.snapshot = snapshot;
this.splitAssigner = splitAssigner;
}

@Override
public void start() {
// no resources to start
}

@Override
public void handleSplitRequest(int subtask, @Nullable String hostname) {
if (!context.registeredReaders().containsKey(subtask)) {
// reader failed between sending the request and now. skip this request.
return;
}

List<FileStoreSourceSplit> assignment = splitAssigner.getNext(subtask, hostname);
if (assignment.size() > 0) {
context.assignSplits(
new SplitsAssignment<>(Collections.singletonMap(subtask, assignment)));
} else {
context.signalNoMoreSplits(subtask);
}
}

@Override
public void addSplitsBack(List<FileStoreSourceSplit> backSplits, int subtaskId) {
splitAssigner.addSplitsBack(subtaskId, backSplits);
}

@Override
public void addReader(int subtaskId) {
// this source is purely lazy-pull-based, nothing to do upon registration
}

@Override
public PendingSplitsCheckpoint snapshotState(long checkpointId) {
return new PendingSplitsCheckpoint(
splitAssigner.remainingSplits(), snapshot == null ? null : snapshot.id());
}

@Override
public void close() {
// no resources to close
}

@Nullable
public Snapshot snapshot() {
return snapshot;
}

@Override
public void handleSourceEvent(int subtaskId, SourceEvent sourceEvent) {
LOG.error("Received unrecognized event: {}", sourceEvent);
}

@VisibleForTesting
public SplitAssigner getSplitAssigner() {
return splitAssigner;
}
}

0 comments on commit 7179e4a

Please sign in to comment.