zhangjun0x01 commented on code in PR #584: URL: https://github.com/apache/incubator-paimon/pull/584#discussion_r1145077502
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/DataTableSource.java: ########## @@ -163,15 +167,44 @@ public ScanRuntimeProvider getScanRuntimeProvider(ScanContext scanContext) { .withProjection(projectFields) .withPredicate(predicate) .withLimit(limit) - .withParallelism( - Options.fromMap(table.schema().options()) - .get(FlinkConnectorOptions.SCAN_PARALLELISM)) + .withParallelism(inferParallelism()) .withWatermarkStrategy(watermarkStrategy); return new PaimonDataStreamScanProvider( !streaming, env -> sourceBuilder.withEnv(env).build()); } + private Integer inferParallelism() { + Options options = Options.fromMap(this.table.schema().options()); + Integer parallelism = options.get(FlinkConnectorOptions.SCAN_PARALLELISM); + + if (options.get(FlinkConnectorOptions.INFER_SCAN_PARALLELISM)) { + // for streaming mode, set the default parallelism to the bucket number. + if (streaming) { + parallelism = options.get(CoreOptions.BUCKET); + } else { + int splitSize = 1; + if (table instanceof AbstractFileStoreTable) { + List<Split> splitList = ((AbstractFileStoreTable) table).splits(); + if (null != splitList) { + splitSize = splitList.size(); + } + } + parallelism = splitSize; + + if (null != limit && limit > 0) { + int limitCount = + limit >= Integer.MAX_VALUE ? Integer.MAX_VALUE : limit.intValue(); + parallelism = Math.min(parallelism, limitCount); + } + + // parallelism must be positive. + parallelism = Math.max(1, parallelism); Review Comment: To prevent the user set an incorrect value for `scan.parallelism`, for -1 or 0. -- 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: issues-unsubscr...@paimon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org