Skip to content

[PYF-260] Add flink statement result list command and display results on create --wait#3261

Open
Zander Matheson (awmatheson) wants to merge 1 commit intoconfluentinc:mainfrom
awmatheson:PYF-260
Open

[PYF-260] Add flink statement result list command and display results on create --wait#3261
Zander Matheson (awmatheson) wants to merge 1 commit intoconfluentinc:mainfrom
awmatheson:PYF-260

Conversation

@awmatheson
Copy link

@awmatheson Zander Matheson (awmatheson) commented Feb 14, 2026

Summary

  • Add new confluent flink statement result list <statement-name> command that fetches and displays SQL statement result rows from the Flink Gateway API
    • Supports --output human/json/yaml, --wait, and --max-rows flags
    • Rejects unbounded/streaming queries with a clear error directing users to the Flink shell
  • Enhance confluent flink statement create --wait to automatically fetch and display results for bounded queries (e.g. SHOW DATABASES), falling through to existing metadata output for DDL statements and unbounded queries
  • Cloud-only for now; on-prem (CMF) support can follow in a separate change

Test plan

  • go build ./... compiles successfully
  • New TestFlinkStatementResultList integration tests pass (human, JSON, YAML, failed, pending, no-results, unbounded)
  • Existing TestFlinkStatementCreate tests pass (including --wait)
  • Existing TestFlinkStatement tests pass (2 pre-existing failures unrelated to this change)
  • Help golden tests pass for both cloud and on-prem
  • Golden fixture files created for all output formats, edge cases, and help text
  • Manual test with live compute pool: SHOW DATABASES, SHOW TABLES, DDL, JSON/YAML output, --max-rows truncation
  • Manual test confirmed unbounded streaming queries no longer hang

Test & Review

Integration tests cover 7 scenarios:

  1. Happy path - bounded results in human table format
  2. JSON output format
  3. YAML output format
  4. Failed statement - returns error with status detail
  5. Pending statement - returns error suggesting --wait
  6. No results (DDL) - prints "Statement has no results to display."
  7. Unbounded statement - returns error directing to Flink shell

Manual testing performed against live Confluent Cloud with SHOW DATABASES, SHOW TABLES, CREATE TABLE (DDL), and streaming SELECT queries.

Screenshot 2026-02-24 at 10 29 33 PM Screenshot 2026-02-24 at 10 29 05 PM Screenshot 2026-02-24 at 10 28 52 PM

Checklist

  • I have successfully built and used a custom CLI binary, without linter issues from this PR.
  • I have clearly specified in the What section below whether this PR applies to Confluent Cloud, Confluent Platform, or both.
  • I have verified this PR in Confluent Cloud pre-prod or production environment, if applicable.
  • I have verified this PR in Confluent Platform on-premises environment, if applicable.
  • I have attached manual CLI verification results or screenshots in the Test & Review section below.
  • I have added appropriate CLI integration or unit tests for any new or updated commands and functionality.
  • [ x I confirm that this PR introduces no breaking changes or backward compatibility issues.
  • [ x I have indicated the potential customer impact if something goes wrong in the Blast Radius section below.
  • I have put checkmarks below confirming that the feature associated with this PR is enabled in:
    • Confluent Cloud prod
    • Confluent Cloud stag
    • Confluent Platform
    • Check this box if the feature is enabled for certain organizations only

What

Adds non-interactive result fetching for bounded Flink SQL statements. This enables scripting and automation use cases like listing catalogs, databases, and tables via Flink SQL from the command line, which were previously only possible through the interactive Flink shell (REPL).

Key design decisions:

  • Uses traits.GetIsBounded() from the Flink Gateway API to distinguish bounded (snapshot) queries from unbounded (streaming) queries
  • Bounded queries: results are fetched with pagination up to --max-rows (default 100)
  • Unbounded queries: result list returns an error; create --wait falls through to metadata output
  • result sub-command registered only for cloud login (on-prem can be added later with a separate child command)

Blast Radius

  • Low risk. This is a new additive command (flink statement result list) with no changes to existing command behavior
  • The only modification to existing behavior is flink statement create --wait, which now additionally displays results for bounded queries instead of only showing metadata. Unbounded queries and DDL statements behave exactly as before
  • Cloud-only; no impact to Confluent Platform users

References

@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

traits := statement.Status.GetTraits()
schema := traits.GetSchema()
if columns := schema.GetColumns(); len(columns) > 0 && traits.GetIsBounded() {
statementResults, err := fetchAllResults(client, environmentId, name, c.Context.LastOrgId, schema, defaultMaxResultRows)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's no --max-rows support on create --wait

The logic hardcodes defaultMaxResultRows (100) and doesn't print a truncation warning. If a query returns >100 rows, the output is silently truncated. Compare with result list which both allows --max-rows and prints a truncation warning to stderr. Could we either:

  • Add --max-rows flag, or
  • Print truncation warning?

return fmt.Errorf("statement %q is still pending, use --wait to wait for it to complete", args[0])
}

err = retry.Retry(time.Second, 2*time.Minute, func() error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional that the timeout is 2x longer for result list compared to create? Otherwise it looks like an inconsistency.

schema := traits.GetSchema()
columns := schema.GetColumns()
if len(columns) == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "Statement has no results to display.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a DDL statement has no schema (empty columns), the code prints a plain text message regardless of --output flag.
So user would get plain text instead of a structured JSON response if running flink statement result list no-results -o json. Contrast this with the printStatementResults function which correctly handles the serialized case for empty rows, we should be able to handle serialized output here as well.

maxRows, err := cmd.Flags().GetInt("max-rows")
if err != nil {
return err
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a check to make sure max-rows is positive value?

if maxRows < 1 {
      return fmt.Errorf("--max-rows must be a positive integer")
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants