danny0405 commented on code in PR #20866:
URL: https://github.com/apache/hudi/pull/20866#discussion_r4675303157
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/HoodieTableSource.java:
##########
@@ -293,11 +293,10 @@ private DataStream<RowData> produceLegacySourceDataStream(
* @return the configured HoodieSource instance
*/
private HoodieSource<RowData> createHoodieSource() {
- ValidationUtils.checkState(metaClient != null, "MetaClient must be
initialized before creating HoodieSource");
ValidationUtils.checkState(hadoopConf != null, "Hadoop configuration must
be initialized");
ValidationUtils.checkState(conf != null, "Configuration must be
initialized");
- HoodieSchema tableSchema = !tableDataExists() ? inferSchemaFromDdl() :
getTableSchema();
+ HoodieSchema tableSchema = tableDataExists() ? getTableSchema() :
inferSchemaFromDdl();
Review Comment:
**P1 — A late-created merge-on-read table can lose deletes.** Planning from
the DDL also fixes `emitDelete` a few lines below. If the reader omits
`table.type`, the default is `COPY_ON_WRITE`. With `changelog.enabled=true`, I
started the reader before the writer created a `MERGE_ON_READ` table, wrote an
insert and a delete, and read the delete split. It emitted zero deletes.
Reading the same split with `table.type=MERGE_ON_READ` emitted one. Could we
derive `emitDelete` from the actual table type when the split reader opens the
split and cover the omitted-option case with a regression test?
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/HoodieTableSource.java:
##########
@@ -348,9 +348,9 @@ private HoodieScanContext createHoodieScanContext(RowType
rowType) {
.maxPendingSplits(conf.get(FlinkOptions.READ_SPLITS_LIMIT))
.partitionPruner(partitionPruner)
Review Comment:
**P1 — This partition pruner can discard matching rows.** If the reader
starts before table creation and its DDL omits the Hive-style partitioning
option, the pruner captures the default plain-directory layout. I filtered on
`partition = 'par1'` and had the writer create `partition=par1`. Discovery
compared the whole directory name with `par1` and returned zero splits,
allowing the offset to advance past the matching commit. Could we build the
pruner after reading the table properties, or let Flink apply the filter while
the layout is unknown?
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/split/DefaultHoodieSplitDiscover.java:
##########
@@ -58,11 +57,12 @@ public DefaultHoodieSplitDiscover(
@Override
public HoodieContinuousSplitBatch discoverSplits(String lastInstant) {
- if (metaClient == null) {
+ HoodieTableMetaClient client = getOrCreateMetaClient();
Review Comment:
**Small simplification.** `getOrCreateMetaClient()` can check `metaClient ==
null && tableExists(...)`, assign the field inside that guard, and end with a
single `return metaClient`. This keeps the retry behavior while the table is
absent and preserves the cached fast path after creation.
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/TestHoodieTableSource.java:
##########
@@ -167,6 +171,25 @@ void testStreamingInputFormatPlanning() {
assertThrows(HoodieException.class, () ->
tableSource.getInputFormat(true));
}
+ @ParameterizedTest(name = "read.source-v2.enabled={0}")
+ @ValueSource(booleans = {false, true})
+ void testStreamingSourcePlanningBeforeFirstWrite(boolean isSourceV2) {
+ Configuration conf =
TestConfigurations.getDefaultConf(tempFile.getAbsolutePath());
+ conf.set(FlinkOptions.READ_AS_STREAMING, true);
+ conf.set(FlinkOptions.READ_SOURCE_V2_ENABLED, isSourceV2);
+ conf.set(FlinkOptions.INDEX_TYPE, HoodieIndex.IndexType.BUCKET.name());
+ HoodieTableSource tableSource = createHoodieTableSource(conf);
Review Comment:
**Follow-up on schema evolution.** With `hoodie.schema.on.read.enable=true`
and an empty table path, this source-construction call still throws a
`NullPointerException`. `InternalSchemaManager.get()` asks
`TableSchemaResolver` for the active timeline before a meta client exists. This
predates the PR and matches the scope stated in its description. A follow-up
could defer internal-schema lookup until the table exists and cover that
configuration here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]