You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "tianz101 (via GitHub)" <gi...@apache.org> on 2026/04/13 18:56:03 UTC
[PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
tianz101 opened a new pull request, #38167:
URL: https://github.com/apache/beam/pull/38167
**Please** add a meaningful description for your change here
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "chenxuesdu (via GitHub)" <gi...@apache.org>.
chenxuesdu commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3096851436
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java:
##########
@@ -2754,6 +2774,50 @@ static String resolveSpannerProjectId(SpannerConfig config) {
: config.getProjectId().get();
}
+ @VisibleForTesting
+ static void checkTvfExistence(DatabaseClient databaseClient, List<String> tvfNameList) {
+ if (tvfNameList == null || tvfNameList.isEmpty()) {
+ return;
+ }
+ Dialect dialect = databaseClient.getDialect();
+ try (ReadOnlyTransaction tx = databaseClient.readOnlyTransaction()) {
+ StringBuilder sql =
+ new StringBuilder(
+ "SELECT routine_name FROM information_schema.routines WHERE routine_type LIKE '%FUNCTION' AND routine_name IN (");
+ for (int i = 0; i < tvfNameList.size(); i++) {
+ if (dialect == Dialect.POSTGRESQL) {
+ sql.append("$").append(i + 1);
+ } else {
+ sql.append("@p").append(i);
+ }
+ if (i < tvfNameList.size() - 1) {
+ sql.append(", ");
+ }
+ }
+ sql.append(")");
+ Statement.Builder builder = Statement.newBuilder(sql.toString());
+ for (int i = 0; i < tvfNameList.size(); i++) {
Review Comment:
If we call escapeTvfName for each tvf before storing in tvfNameList and store them, we don't need to escape again when use the tvf name. Is that right?
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "jiangzzhu (via GitHub)" <gi...@apache.org>.
jiangzzhu commented on PR #38167:
URL: https://github.com/apache/beam/pull/38167#issuecomment-4239386372
/gemini review
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #38167:
URL: https://github.com/apache/beam/pull/38167#issuecomment-4238877957
## Summary of Changes
Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces functionality to allow SpannerIO to query and union multiple change stream TVFs. This change involves updating the partition metadata model to track TVF names, modifying the data access layer to handle composed partition tokens, and updating the SpannerIO read pipeline to support these new configurations. Additionally, necessary dependency updates were made to support the latest Spanner libraries.
### Highlights
* **SpannerIO Change Stream TVF Support**: Added support for querying and unioning a list of change stream Table-Valued Functions (TVFs) in SpannerIO.readChangeStream().
* **Partition Metadata Updates**: Updated partition metadata to include TVF names, ensuring correct tracking and querying of partitions across multiple TVFs.
* **Dependency Management**: Added google-cloud-spanner-bom to the project dependencies and updated the Gradle configuration to manage Spanner-related libraries.
🧠**New Feature in Public Preview:** You can now enable **Memory** to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | `/gemini help` | Displays a list of available commands.
<b>Customization</b>
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3112925718
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java:
##########
@@ -2754,6 +2774,50 @@ static String resolveSpannerProjectId(SpannerConfig config) {
: config.getProjectId().get();
}
+ @VisibleForTesting
+ static void checkTvfExistence(DatabaseClient databaseClient, List<String> tvfNameList) {
+ if (tvfNameList == null || tvfNameList.isEmpty()) {
+ return;
+ }
+ Dialect dialect = databaseClient.getDialect();
+ try (ReadOnlyTransaction tx = databaseClient.readOnlyTransaction()) {
+ StringBuilder sql =
+ new StringBuilder(
+ "SELECT routine_name FROM information_schema.routines WHERE routine_type LIKE '%FUNCTION' AND routine_name IN (");
+ for (int i = 0; i < tvfNameList.size(); i++) {
+ if (dialect == Dialect.POSTGRESQL) {
+ sql.append("$").append(i + 1);
+ } else {
+ sql.append("@p").append(i);
+ }
+ if (i < tvfNameList.size() - 1) {
+ sql.append(", ");
+ }
+ }
+ sql.append(")");
+ Statement.Builder builder = Statement.newBuilder(sql.toString());
+ for (int i = 0; i < tvfNameList.size(); i++) {
Review Comment:
Yes, this is a good idea and I will do that and refresh the commit. Thanks.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #38167:
URL: https://github.com/apache/beam/pull/38167#issuecomment-4248853800
Assigning reviewers:
R: @Abacn for label java.
R: @nielm for label spanner.
Note: If you would like to opt out of this review, comment `assign to next reviewer`.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3089234365
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java:
##########
@@ -2042,6 +2052,7 @@ && getInclusiveStartAt().toSqlTimestamp().after(getInclusiveEndAt().toSqlTimesta
getInclusiveEndAt().compareTo(MAX_INCLUSIVE_END_AT) > 0
? MAX_INCLUSIVE_END_AT
: getInclusiveEndAt();
Review Comment:
I will approve myself once the data verification test is finished.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3076143708
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dao/ChangeStreamDao.java:
##########
@@ -117,16 +124,29 @@ public ChangeStreamResultSet changeStreamQuery(
.to(heartbeatMillis)
.build();
} else {
- query =
- "SELECT * FROM READ_"
- + changeStreamName
- + "("
- + " start_timestamp => @startTimestamp,"
- + " end_timestamp => @endTimestamp,"
- + " partition_token => @partitionToken,"
- + " read_options => null,"
- + " heartbeat_milliseconds => @heartbeatMillis"
- + ")";
+ if (this.isMutableChangeStream && tvfName != null && !tvfName.equals(DEFAULT_TVF_NAME)) {
+ query =
+ "SELECT * FROM "
+ + tvfName
Review Comment:
When the code reaches here, the tvfName has been validated already.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3127527588
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dao/PartitionMetadataDao.java:
##########
@@ -132,14 +134,41 @@ public List<String> findAllTableIndexes() {
return result;
}
+ public static String escapeTvfName(String tvfName) {
+ return tvfName.replace("'", "").replace("\"", "");
+ }
Review Comment:
The TVF name itself will not contain quotes, but users may qute the tvf name with various quotes. We need to escape them and validate the tvf name itself.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3127521855
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java:
##########
@@ -2042,6 +2052,7 @@ && getInclusiveStartAt().toSqlTimestamp().after(getInclusiveEndAt().toSqlTimesta
getInclusiveEndAt().compareTo(MAX_INCLUSIVE_END_AT) > 0
? MAX_INCLUSIVE_END_AT
: getInclusiveEndAt();
Review Comment:
unit test, integration test and e2e test have been done.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #38167:
URL: https://github.com/apache/beam/pull/38167#issuecomment-4307893719
## [Codecov](https://app.codecov.io/gh/apache/beam/pull/38167?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `61.92893%` with `75 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 56.73%. Comparing base ([`357862a`](https://app.codecov.io/gh/apache/beam/commit/357862aee376153ebd49763dc902c4529a80b4ec?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`a5d05b6`](https://app.codecov.io/gh/apache/beam/commit/a5d05b66c3682cb7e84d3ade8e1f41736d751b42?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 1 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/beam/pull/38167?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...gcp/spanner/changestreams/dofn/InitializeDoFn.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2Fchangestreams%2Fdofn%2FInitializeDoFn.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvY2hhbmdlc3RyZWFtcy9kb2ZuL0luaXRpYWxpemVEb0ZuLmphdmE=) | 44.44% | [23 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...panner/changestreams/dao/PartitionMetadataDao.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2Fchangestreams%2Fdao%2FPartitionMetadataDao.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvY2hhbmdlc3RyZWFtcy9kYW8vUGFydGl0aW9uTWV0YWRhdGFEYW8uamF2YQ==) | 59.32% | [21 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [.../org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2FSpannerIO.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvU3Bhbm5lcklPLmphdmE=) | 58.97% | [12 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...gcp/spanner/changestreams/dao/ChangeStreamDao.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2Fchangestreams%2Fdao%2FChangeStreamDao.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvY2hhbmdlc3RyZWFtcy9kYW8vQ2hhbmdlU3RyZWFtRGFvLmphdmE=) | 33.33% | [2 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [.../changestreams/action/QueryChangeStreamAction.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2Fchangestreams%2Faction%2FQueryChangeStreamAction.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvY2hhbmdlc3RyZWFtcy9hY3Rpb24vUXVlcnlDaGFuZ2VTdHJlYW1BY3Rpb24uamF2YQ==) | 86.66% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...spanner/changestreams/model/PartitionMetadata.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2Fchangestreams%2Fmodel%2FPartitionMetadata.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvY2hhbmdlc3RyZWFtcy9tb2RlbC9QYXJ0aXRpb25NZXRhZGF0YS5qYXZh) | 75.00% | [0 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...angestreams/action/PartitionStartRecordAction.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2Fchangestreams%2Faction%2FPartitionStartRecordAction.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvY2hhbmdlc3RyZWFtcy9hY3Rpb24vUGFydGl0aW9uU3RhcnRSZWNvcmRBY3Rpb24uamF2YQ==) | 75.00% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...k/io/gcp/spanner/changestreams/dao/DaoFactory.java](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fspanner%2Fchangestreams%2Fdao%2FDaoFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL3NwYW5uZXIvY2hhbmdlc3RyZWFtcy9kYW8vRGFvRmFjdG9yeS5qYXZh) | 66.66% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/beam/pull/38167?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #38167 +/- ##
============================================
- Coverage 58.51% 56.73% -1.78%
+ Complexity 15430 3441 -11989
============================================
Files 2851 1182 -1669
Lines 280074 188935 -91139
Branches 12336 3613 -8723
============================================
- Hits 163884 107194 -56690
+ Misses 109772 78338 -31434
+ Partials 6418 3403 -3015
```
| [Flag](https://app.codecov.io/gh/apache/beam/pull/38167/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [java](https://app.codecov.io/gh/apache/beam/pull/38167/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `71.84% <61.92%> (+7.25%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/beam/pull/38167?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on PR #38167:
URL: https://github.com/apache/beam/pull/38167#issuecomment-4324453396
Run Java PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #38167:
URL: https://github.com/apache/beam/pull/38167#issuecomment-4239851967
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3075606168
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java:
##########
@@ -2754,6 +2774,44 @@ static String resolveSpannerProjectId(SpannerConfig config) {
: config.getProjectId().get();
}
+ @VisibleForTesting
+ static void checkTvfExistence(DatabaseClient databaseClient, List<String> tvfNameList) {
+ if (tvfNameList == null || tvfNameList.isEmpty()) {
+ return;
+ }
+ try (ReadOnlyTransaction tx = databaseClient.readOnlyTransaction()) {
+ StringBuilder inClauseBuilder = new StringBuilder();
+ for (int i = 0; i < tvfNameList.size(); i++) {
+ inClauseBuilder
+ .append("'")
+ .append(PartitionMetadataDao.escapeTvfName(tvfNameList.get(i)))
+ .append("'");
+ if (i < tvfNameList.size() - 1) {
+ inClauseBuilder.append(", ");
+ }
+ }
+ String inClause = inClauseBuilder.toString();
+ // Note routine_type for GSQL is 'TABLE FUNCTION', for PostgreSQL is 'FUNCTION'.
+ String query =
+ "SELECT routine_name FROM information_schema.routines WHERE routine_type LIKE '%FUNCTION' AND routine_name IN ("
+ + inClause
+ + ")";
+
+ Statement statement = Statement.newBuilder(query).build();
+ ResultSet resultSet = tx.executeQuery(statement);
Review Comment:

Building SQL queries using string concatenation is a security risk and can lead to SQL injection. It is also less efficient and more error-prone than using query parameters. Consider using a parameterized query with the `IN` clause. This approach is safer and dialect-neutral.
```java
StringBuilder sql = new StringBuilder("SELECT routine_name FROM information_schema.routines WHERE routine_type LIKE '%FUNCTION' AND routine_name IN (");
for (int i = 0; i < tvfNameList.size(); i++) {
sql.append("@p").append(i);
if (i < tvfNameList.size() - 1) {
sql.append(", ");
}
}
sql.append(")");
Statement.Builder builder = Statement.newBuilder(sql.toString());
for (int i = 0; i < tvfNameList.size(); i++) {
builder.bind("p" + i).to(tvfNameList.get(i));
}
Statement statement = builder.build();
ResultSet resultSet = tx.executeQuery(statement);
```
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dao/ChangeStreamDao.java:
##########
@@ -95,10 +98,14 @@ public ChangeStreamResultSet changeStreamQuery(
if (this.isPostgres()) {
// Ensure we have determined whether change stream uses mutable key range
if (this.isMutableChangeStream) {
- query =
- "SELECT * FROM \"spanner\".\"read_proto_bytes_"
- + changeStreamName
- + "\"($1, $2, $3, $4, null)";
+ if (tvfName == null || tvfName.equals(DEFAULT_TVF_NAME)) {
+ query =
+ "SELECT * FROM \"spanner\".\"read_proto_bytes_"
+ + changeStreamName
+ + "\"($1, $2, $3, $4, null)";
+ } else {
+ query = "SELECT * FROM \"spanner\".\"" + tvfName + "\"($1, $2, $3, $4, null)";
Review Comment:

Directly concatenating `tvfName` into the SQL query string is a security risk (SQL injection). While TVF names cannot be parameterized in the `FROM` clause, they should be strictly validated or properly quoted using the database dialect's identifier quoting rules (e.g., double quotes for PostgreSQL) to ensure safety and correctness.
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dao/ChangeStreamDao.java:
##########
@@ -117,16 +124,29 @@ public ChangeStreamResultSet changeStreamQuery(
.to(heartbeatMillis)
.build();
} else {
- query =
- "SELECT * FROM READ_"
- + changeStreamName
- + "("
- + " start_timestamp => @startTimestamp,"
- + " end_timestamp => @endTimestamp,"
- + " partition_token => @partitionToken,"
- + " read_options => null,"
- + " heartbeat_milliseconds => @heartbeatMillis"
- + ")";
+ if (this.isMutableChangeStream && tvfName != null && !tvfName.equals(DEFAULT_TVF_NAME)) {
+ query =
+ "SELECT * FROM "
+ + tvfName
Review Comment:

Directly concatenating `tvfName` into the SQL query string is a security risk (SQL injection). For GoogleSQL dialect, identifiers should be wrapped in backticks and properly escaped if they contain backticks themselves. Since the TVF name is validated against `information_schema` at pipeline construction, the risk is reduced, but it remains a poor practice that can lead to issues with special characters in identifiers.
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dao/PartitionMetadataDao.java:
##########
@@ -132,14 +134,41 @@ public List<String> findAllTableIndexes() {
return result;
}
+ public static String escapeTvfName(String tvfName) {
+ return tvfName.replace("'", "").replace("\"", "");
+ }
Review Comment:

The `escapeTvfName` method is destructive as it removes all single and double quotes from the TVF name. This will cause validation and queries to fail if a TVF name legitimately contains these characters (e.g., delimited identifiers in Spanner). Instead of removing these characters, the code should handle them by using proper quoting when the name is used in SQL queries. Additionally, this simple replacement is not a robust way to prevent SQL injection.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3076041724
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java:
##########
@@ -2754,6 +2774,44 @@ static String resolveSpannerProjectId(SpannerConfig config) {
: config.getProjectId().get();
}
+ @VisibleForTesting
+ static void checkTvfExistence(DatabaseClient databaseClient, List<String> tvfNameList) {
+ if (tvfNameList == null || tvfNameList.isEmpty()) {
+ return;
+ }
+ try (ReadOnlyTransaction tx = databaseClient.readOnlyTransaction()) {
+ StringBuilder inClauseBuilder = new StringBuilder();
+ for (int i = 0; i < tvfNameList.size(); i++) {
+ inClauseBuilder
+ .append("'")
+ .append(PartitionMetadataDao.escapeTvfName(tvfNameList.get(i)))
+ .append("'");
+ if (i < tvfNameList.size() - 1) {
+ inClauseBuilder.append(", ");
+ }
+ }
+ String inClause = inClauseBuilder.toString();
+ // Note routine_type for GSQL is 'TABLE FUNCTION', for PostgreSQL is 'FUNCTION'.
+ String query =
+ "SELECT routine_name FROM information_schema.routines WHERE routine_type LIKE '%FUNCTION' AND routine_name IN ("
+ + inClause
+ + ")";
+
+ Statement statement = Statement.newBuilder(query).build();
+ ResultSet resultSet = tx.executeQuery(statement);
Review Comment:
done
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "tianz101 (via GitHub)" <gi...@apache.org>.
tianz101 commented on code in PR #38167:
URL: https://github.com/apache/beam/pull/38167#discussion_r3076142073
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dao/ChangeStreamDao.java:
##########
@@ -95,10 +98,14 @@ public ChangeStreamResultSet changeStreamQuery(
if (this.isPostgres()) {
// Ensure we have determined whether change stream uses mutable key range
if (this.isMutableChangeStream) {
- query =
- "SELECT * FROM \"spanner\".\"read_proto_bytes_"
- + changeStreamName
- + "\"($1, $2, $3, $4, null)";
+ if (tvfName == null || tvfName.equals(DEFAULT_TVF_NAME)) {
+ query =
+ "SELECT * FROM \"spanner\".\"read_proto_bytes_"
+ + changeStreamName
+ + "\"($1, $2, $3, $4, null)";
+ } else {
+ query = "SELECT * FROM \"spanner\".\"" + tvfName + "\"($1, $2, $3, $4, null)";
Review Comment:
when the code reaches here, the tvfName has been validated already.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow SpannerIO.readChangeStream() to query & union a list of change stream TVF's [beam]
Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn merged PR #38167:
URL: https://github.com/apache/beam/pull/38167
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org