Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
include:
- scalaProfile: "scala-2.12"
sparkProfile: "spark3.5"
flinkProfile: "flink2.2"
flinkProfile: "flink2.3"

steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -245,7 +245,7 @@ jobs:
include:
- scalaProfile: "scala-2.12"
sparkProfile: "spark3.5"
flinkProfile: "flink2.2"
flinkProfile: "flink2.3"

steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -293,7 +293,7 @@ jobs:
include:
- scalaProfile: "scala-2.12"
sparkProfile: "spark3.5"
flinkProfile: "flink2.2"
flinkProfile: "flink2.3"

steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -381,7 +381,7 @@ jobs:
include:
- scalaProfile: "scala-2.12"
sparkProfile: "spark3.5"
flinkProfile: "flink2.2"
flinkProfile: "flink2.3"

env:
UT_MODULES: >-
Expand Down Expand Up @@ -1497,7 +1497,7 @@ jobs:
# - flinkProfile: "flink2.0"
# flinkAvroVersion: "1.11.4"
# flinkParquetVersion: '1.14.4'
- flinkProfile: "flink2.2"
- flinkProfile: "flink2.3"
flinkAvroVersion: "1.11.4"
flinkParquetVersion: '1.15.2'
steps:
Expand Down Expand Up @@ -1531,7 +1531,7 @@ jobs:
FLINK_PROFILE: ${{ matrix.flinkProfile }}
FLINK_AVRO_VERSION: ${{ matrix.flinkAvroVersion }}
FLINK_PARQUET_VERSION: ${{ matrix.flinkParquetVersion }}
if: ${{ endsWith(env.FLINK_PROFILE, '2.2') }}
if: ${{ endsWith(env.FLINK_PROFILE, '2.3') }}
run: |
mvn clean install -T 2 -Pintegration-tests -D"$SCALA_PROFILE" -D"$FLINK_PROFILE" -pl hudi-flink-datasource/hudi-flink -am -Davro.version="$FLINK_AVRO_VERSION" -Dparquet.version="$FLINK_PARQUET_VERSION" -DskipTests=true $MVN_ARGS
mvn verify -Pintegration-tests -D"$SCALA_PROFILE" -D"$FLINK_PROFILE" -Davro.version="$FLINK_AVRO_VERSION" -Dparquet.version="$FLINK_PARQUET_VERSION" $FLINK_IT_FILTER1 -pl hudi-flink-datasource/hudi-flink $MVN_ARGS -Djacoco.skip=false
Expand All @@ -1542,10 +1542,10 @@ jobs:
if: always()
run: python3 scripts/ci/test_timing_summary.py --title "${{ github.job }}"
- name: Generate merged coverage report
if: always() && endsWith(matrix.flinkProfile, '2.2') && github.event_name != 'merge_group'
if: always() && endsWith(matrix.flinkProfile, '2.3') && github.event_name != 'merge_group'
run: ./scripts/jacoco/generate_merged_coverage_report.sh $GITHUB_WORKSPACE
- name: Upload coverage to Codecov
if: always() && endsWith(matrix.flinkProfile, '2.2') && github.event_name != 'merge_group'
if: always() && endsWith(matrix.flinkProfile, '2.3') && github.event_name != 'merge_group'
uses: ./.github/actions/upload-coverage
with:
flags: flink-integration-tests
Expand All @@ -1559,7 +1559,7 @@ jobs:
strategy:
matrix:
include:
- flinkProfile: "flink2.2"
- flinkProfile: "flink2.3"
flinkAvroVersion: "1.11.4"
flinkParquetVersion: '1.15.2'
steps:
Expand All @@ -1585,18 +1585,18 @@ jobs:
FLINK_PROFILE: ${{ matrix.flinkProfile }}
FLINK_AVRO_VERSION: ${{ matrix.flinkAvroVersion }}
FLINK_PARQUET_VERSION: ${{ matrix.flinkParquetVersion }}
if: ${{ endsWith(env.FLINK_PROFILE, '2.2') }}
if: ${{ endsWith(env.FLINK_PROFILE, '2.3') }}
run: |
mvn clean install -T 2 -Pintegration-tests -D"$SCALA_PROFILE" -D"$FLINK_PROFILE" -pl hudi-flink-datasource/hudi-flink -am -Davro.version="$FLINK_AVRO_VERSION" -Dparquet.version="$FLINK_PARQUET_VERSION" -DskipTests=true $MVN_ARGS
mvn verify -Pintegration-tests -D"$SCALA_PROFILE" -D"$FLINK_PROFILE" -Davro.version="$FLINK_AVRO_VERSION" -Dparquet.version="$FLINK_PARQUET_VERSION" $FLINK_IT_FILTER2 -pl hudi-flink-datasource/hudi-flink $MVN_ARGS -Djacoco.skip=false
- name: Test timing summary
if: always()
run: python3 scripts/ci/test_timing_summary.py --title "${{ github.job }}"
- name: Generate merged coverage report
if: always() && endsWith(matrix.flinkProfile, '2.2') && github.event_name != 'merge_group'
if: always() && endsWith(matrix.flinkProfile, '2.3') && github.event_name != 'merge_group'
run: ./scripts/jacoco/generate_merged_coverage_report.sh $GITHUB_WORKSPACE
- name: Upload coverage to Codecov
if: always() && endsWith(matrix.flinkProfile, '2.2') && github.event_name != 'merge_group'
if: always() && endsWith(matrix.flinkProfile, '2.3') && github.event_name != 'merge_group'
uses: ./.github/actions/upload-coverage
with:
flags: flink-integration-tests
Expand Down Expand Up @@ -1676,7 +1676,7 @@ jobs:
sparkProfile: 'spark3.5'
sparkRuntime: 'spark3.5.9'
- scalaProfile: 'scala-2.12'
flinkProfile: 'flink2.2'
flinkProfile: 'flink2.3'
flinkAvroVersion: '1.11.4'
flinkParquetVersion: '1.15.2'
sparkProfile: 'spark3.5'
Expand Down Expand Up @@ -1872,7 +1872,7 @@ jobs:
matrix:
include:
- sparkProfile: 'spark3.5'
flinkProfile: 'flink2.2'
flinkProfile: 'flink2.3'
sparkArchive: 'spark-3.5.9/spark-3.5.9-bin-hadoop3.tgz'
env:
# The only modules with integration-test classes besides hudi-flink, whose ITs run in the
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/maven_artifact_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
strategy:
matrix:
include:
- scalaProfile: 'scala-2.12'
flinkProfile: 'flink2.3'
sparkProfile: 'spark3.5'
sparkRuntime: 'spark3.5.9'
- scalaProfile: 'scala-2.12'
flinkProfile: 'flink2.2'
sparkProfile: 'spark3.5'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release_candidate_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ jobs:
flinkProfile: 'flink2.2'
sparkProfile: 'spark3.5'
sparkRuntime: 'spark3.5.9'
- scalaProfile: 'scala-2.12'
flinkProfile: 'flink2.3'
sparkProfile: 'spark3.5'
sparkRuntime: 'spark3.5.9'
steps:
- uses: actions/checkout@v5
- name: Set up JDK 11
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Prerequisites for building Apache Hudi:
```
# Checkout code and build
git clone https://github.com/apache/hudi.git && cd hudi
mvn clean package -DskipTests -Dspark3.5 -Dflink2.2
mvn clean package -DskipTests -Dspark3.5 -Dflink2.3

# Start command
spark-3.5.0-bin-hadoop3/bin/spark-shell \
Expand Down Expand Up @@ -163,10 +163,10 @@ mvn clean package -DskipTests -Dspark3.5 -Dscala-2.13 -pl packaging/hudi-spark-b
For example,
```
# Build against Spark 3.5.x
mvn clean package -DskipTests -Dspark3.5 -Dflink2.2
mvn clean package -DskipTests -Dspark3.5 -Dflink2.3

# Build against Spark 3.4.x
mvn clean package -DskipTests -Dspark3.4 -Dflink2.2
mvn clean package -DskipTests -Dspark3.4 -Dflink2.3
```

#### What about "spark-avro" module?
Expand All @@ -175,14 +175,15 @@ Starting from versions 0.11, Hudi no longer requires `spark-avro` to be specifie

### Build with different Flink versions

The default Flink version supported is 2.2. The default Flink 2.2.x version, corresponding to the `flink2.2` profile, is 2.2.1.
The default Flink version supported is 2.3. The default Flink 2.3.x version, corresponding to the `flink2.3` profile, is 2.3.0.
Flink is Scala-free since 1.15.x, there is no need to specify the Scala version for Flink 1.15.x and above versions.
Refer to the table below for building with different Flink and Scala versions.

| Maven build options | Expected Flink bundle jar name | Notes |
|:--------------------|:--------------------------------|:---------------------------------|
| (empty) | hudi-flink2.2-bundle | For Flink 2.2 (default options) |
| `-Dflink2.2` | hudi-flink2.2-bundle | For Flink 2.2 (same as default) |
| (empty) | hudi-flink2.3-bundle | For Flink 2.3 (default options) |
| `-Dflink2.3` | hudi-flink2.3-bundle | For Flink 2.3 (same as default) |
| `-Dflink2.2` | hudi-flink2.2-bundle | For Flink 2.2 |
| `-Dflink2.1` | hudi-flink2.1-bundle | For Flink 2.1 |
| `-Dflink2.0` | hudi-flink2.0-bundle | For Flink 2.0 |
| `-Dflink1.20` | hudi-flink1.20-bundle | For Flink 1.20 |
Expand All @@ -191,8 +192,8 @@ Refer to the table below for building with different Flink and Scala versions.

For example,
```
# Build against Flink 2.2.x
mvn clean package -DskipTests -Dflink2.2
# Build against Flink 2.3.x
mvn clean package -DskipTests -Dflink2.3
```

## Running Tests
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines-20230430.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

# NOTE:
# This config file defines how Azure CI runs tests with Spark 3.5 and Flink 2.2 profiles.
# This config file defines how Azure CI runs tests with Spark 3.5 and Flink 2.3 profiles.
# PRs will need to keep in sync with master's version to trigger the CI runs.
# See scripts/jacoco/README.md for how aggregated code coverage report works
# across multiple modules.
Expand Down Expand Up @@ -101,7 +101,7 @@ parameters:
- '!packaging/hudi-utilities-slim-bundle'

variables:
BUILD_PROFILES: '-Dscala-2.12 -Dspark3.5 -Dflink2.2'
BUILD_PROFILES: '-Dscala-2.12 -Dspark3.5 -Dflink2.3'
PLUGIN_OPTS: '-Dcheckstyle.skip=true -Drat.skip=true -ntp -B -V -Pwarn-log -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.shade=warn -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.dependency=warn'
# The aether.* properties drive maven-resolver's native HTTP transport (Maven 3.9+); the
# maven.wagon.* ones are kept because this image's Maven version is not pinned and Maven 3.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.flink.table.connector.sink.abilities.SupportsRowLevelUpdate;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.types.logical.RowType;
import org.apache.flink.types.RowKind;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -149,7 +150,17 @@ public ChangelogMode getChangelogMode(ChangelogMode changelogMode) {
if (conf.get(FlinkOptions.CHANGELOG_ENABLED)) {
return ChangelogModes.FULL;
} else {
return ChangelogModes.UPSERT;
// Keep the row kinds of the input and leave out UPDATE_BEFORE, which an upsert by record key does not require.
// An insert-only input then stays insert-only: asking for an upsert stream makes Flink 2.3 require
// an ON CONFLICT clause for a plain INSERT, and Flink 2.3.0 adds a stateful SinkUpsertMaterializer
// in front of the writer when that check is switched off.
ChangelogMode.Builder builder = ChangelogMode.newBuilder();
for (RowKind kind : changelogMode.getContainedKinds()) {
if (kind != RowKind.UPDATE_BEFORE) {
builder.addContainedKind(kind);
}
}
return builder.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.transformations.LegacySourceTransformation;
import org.apache.flink.streaming.api.transformations.SourceTransformation;
import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.ExplainDetail;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
Expand All @@ -39,6 +40,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
Expand Down Expand Up @@ -131,6 +133,41 @@ void testSinkPlanning() throws Exception {
appendPlan);
}

@Test
void testStreamingSinkPlanning() throws Exception {
TableEnvironment tableEnv =
TableEnvironment.create(EnvironmentSettings.newInstance().inStreamingMode().build());
createTable(tableEnv, "streaming_sink", new File(tempFile, "streaming_sink"), true);
createTable(tableEnv, "streaming_source", new File(tempFile, "streaming_source"), true);

// An insert-only input: the statement plans without an ON CONFLICT clause (Flink 2.3 asks an upsert sink
// for one) and no upsert materializer is put in front of the writer.
String insertOnlyPlan = tableEnv.explainSql(
"INSERT INTO streaming_sink VALUES "
+ "('id1', 'Alice', 20, TIMESTAMP '2026-01-01 00:00:00', 'p1')",
ExplainDetail.CHANGELOG_MODE,
ExplainDetail.JSON_EXECUTION_PLAN);
assertTrue(
insertOnlyPlan.contains("Sink(table=[default_catalog.default_database.streaming_sink]"),
insertOnlyPlan);
assertTrue(
insertOnlyPlan.contains("stream_write: default_database.streaming_sink"),
insertOnlyPlan);
assertFalse(insertOnlyPlan.contains("upsertMaterialize"), insertOnlyPlan);
assertFalse(insertOnlyPlan.contains("SinkMaterializer"), insertOnlyPlan);

// An input with updates, grouped by the column that feeds the primary key of the sink:
// the sink still takes it as an upsert stream, without UPDATE_BEFORE.
String upsertPlan = tableEnv.explainSql(
"INSERT INTO streaming_sink "
+ "SELECT name, MAX(uuid), MAX(age), MAX(ts), MAX(`partition`) "
+ "FROM streaming_source GROUP BY name",
ExplainDetail.CHANGELOG_MODE);
assertTrue(upsertPlan.contains("changelogMode=[I,UA]"), upsertPlan);
assertFalse(upsertPlan.contains("changelogMode=[I,UB,UA]"), upsertPlan);
assertFalse(upsertPlan.contains("upsertMaterialize"), upsertPlan);
}

private static void createTable(
TableEnvironment tableEnv,
String tableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.apache.flink.configuration.Configuration;
import org.apache.flink.table.connector.ChangelogMode;
import org.apache.flink.types.RowKind;
import org.junit.jupiter.api.Test;

import java.util.Collections;
Expand Down Expand Up @@ -61,6 +62,53 @@ void testChangelogModeAndCopy() {
assertEquals(WriteOperationType.UPSERT.value(), conf.get(FlinkOptions.OPERATION));
}

@Test
void testChangelogModeForInsertOnlyInput() {
HoodieTableSink sink = new HoodieTableSink(new Configuration(), TestConfigurations.TABLE_SCHEMA);

// an insert-only input is accepted as it is
assertEquals(ChangelogMode.insertOnly(), sink.getChangelogMode(ChangelogMode.insertOnly()));
assertEquals(ChangelogMode.insertOnly(), sink.copy().getChangelogMode(ChangelogMode.insertOnly()));
}

@Test
void testChangelogModeForInputWithUpdatesOrDeletes() {
HoodieTableSink sink = new HoodieTableSink(new Configuration(), TestConfigurations.TABLE_SCHEMA);

// the row kinds of an input with updates or deletes are kept, UPDATE_BEFORE is not needed
assertEquals(ChangelogModes.UPSERT, sink.getChangelogMode(ChangelogMode.all()));
assertEquals(ChangelogModes.UPSERT, sink.getChangelogMode(ChangelogMode.upsert()));
assertEquals(
changelogMode(RowKind.INSERT, RowKind.UPDATE_AFTER),
sink.getChangelogMode(changelogMode(RowKind.INSERT, RowKind.UPDATE_BEFORE, RowKind.UPDATE_AFTER)));
assertEquals(
changelogMode(RowKind.INSERT, RowKind.DELETE),
sink.getChangelogMode(changelogMode(RowKind.INSERT, RowKind.DELETE)));
assertEquals(
changelogMode(RowKind.UPDATE_AFTER),
sink.getChangelogMode(changelogMode(RowKind.UPDATE_AFTER)));
}

@Test
void testChangelogModeWithChangelogEnabled() {
Configuration conf = new Configuration();
conf.set(FlinkOptions.CHANGELOG_ENABLED, true);
HoodieTableSink sink = new HoodieTableSink(conf, TestConfigurations.TABLE_SCHEMA);

// changelog.enabled keeps all the changes, whatever the input carries
assertEquals(ChangelogModes.FULL, sink.getChangelogMode(ChangelogMode.insertOnly()));
assertEquals(ChangelogModes.FULL, sink.getChangelogMode(ChangelogMode.upsert()));
assertEquals(ChangelogModes.FULL, sink.getChangelogMode(ChangelogMode.all()));
}

private static ChangelogMode changelogMode(RowKind... kinds) {
ChangelogMode.Builder builder = ChangelogMode.newBuilder();
for (RowKind kind : kinds) {
builder.addContainedKind(kind);
}
return builder.build();
}

@Test
void testOverwriteAndRowLevelOperations() {
Configuration conf = new Configuration();
Expand Down
Loading
Loading