Skip to content

[SPARK-46179][SQL][FOLLOW UP][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing#57172

Closed
andylam-db wants to merge 3 commits into
apache:masterfrom
andylam-db:andylam-db/postgres-subquery-tests
Closed

[SPARK-46179][SQL][FOLLOW UP][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing#57172
andylam-db wants to merge 3 commits into
apache:masterfrom
andylam-db:andylam-db/postgres-subquery-tests

Conversation

@andylam-db

@andylam-db andylam-db commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR removes the --ONLY_IF spark directive from the IN/EXISTS subquery golden-file tests under sql/core/src/test/resources/sql-tests/inputs/subquery/ and rewrites their temporary-view DDL from the Spark-specific

create temporary view t1 as select * from values
  ("t1a", 6S, 8, 10L, float(15.0), 20D, 20E2BD, ...) as t1(t1a, t1b, ...);

form into the portable

create temporary view t1(t1a, t1b, ...) as values
  ('t1a', 6, 8, 10, 15.0, 20.0, 2000.0, ...);

form, using ANSI-compatible literals (single-quoted strings, no S/L/D/E2BD type suffixes). This lets the query files run against PostgreSQL through CrossDbmsQueryTestSuite.

Why are the changes needed?

The subquery test inputs were guarded by --ONLY_IF spark, so they never exercised the cross-DBMS path. Their view DDL relied on Spark-only syntax (typed literal suffixes, select * from values ... as t(...)) that PostgreSQL rejects. Making the DDL portable lets these tests validate Spark's subquery semantics against PostgreSQL as an independent oracle, catching correctness divergences.

Does this PR introduce any user-facing change?

No. Test-only change.

How was this patch tested?

Existing golden-file tests. The golden .out files are regenerated with SPARK_GENERATE_GOLDEN_FILES=1 and the PostgreSQL cross-DBMS run is exercised via CrossDbmsQueryTestSuite.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Anthropic)

…sts to enable PostgreSQL cross-DBMS testing

Remove the `--ONLY_IF spark` guard from the IN/EXISTS subquery golden-file
tests and rewrite their temporary-view DDL into the portable
`CREATE TEMPORARY VIEW t(cols) AS VALUES ...` form with ANSI-compatible
literals, so the same query files can run against PostgreSQL under
CrossDbmsQueryTestSuite. Also add debug/error logging to
CrossDbmsQueryTestSuite to make per-query cross-DBMS mismatches easier to
diagnose.

Golden .out files still need to be regenerated with
SPARK_GENERATE_GOLDEN_FILES=1.
@andylam-db andylam-db changed the title [WIP][SPARK-XXXXX][SQL][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing [SQL][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing Jul 9, 2026
Generated with SPARK_GENERATE_GOLDEN_FILES=1 after removing --ONLY_IF spark
and rewriting the temporary-view DDL to the portable CREATE TEMPORARY VIEW
t(cols) AS VALUES form. The literal-type changes (dropping S/L/float/BD
suffixes) shift column types (smallint->int, float/double->decimal), which
is reflected in the regenerated schemas.
@andylam-db andylam-db marked this pull request as ready for review July 9, 2026 23:39

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to file a JIRA issue before making it ready, @andylam-db .

@dongjoon-hyun dongjoon-hyun marked this pull request as draft July 9, 2026 23:47
@andylam-db andylam-db changed the title [SQL][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing [SPARK-46179 FOLLOW UP][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing Jul 9, 2026
@andylam-db andylam-db marked this pull request as ready for review July 9, 2026 23:50

@cloud-fan cloud-fan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 blocking, 0 non-blocking, 0 nits.
Clean, well-executed test-portability change. No findings.

Verification

Verified the DDL rewrite is result-preserving: after normalizing decimal display (2600 vs 2600.0), a row-by-row comparison across all 19 regenerated results goldens shows zero result-row value changes -- every diff is decimal-scale display or a schema type-name change -- and no query newly errors (20E2BD = 2000 -> 2000.0 is value-preserving). The dropped explicit-type literals narrow some column types (smallint/bigint -> int, float/double -> decimal), but this is correct for CrossDbmsQueryTestSuite: it compares rendered output text and ignores schema (schema = None, CrossDbmsQueryTestSuite.scala:145), so a type change is unobservable unless a row value changes -- and none does. The harness change is logging-only; control flow and assertResult calls are unchanged.

@cloud-fan

Copy link
Copy Markdown
Contributor

The test failures are directly caused by this PR

These 8 files produce genuine Spark-vs-PostgreSQL divergences when run
through PostgresSQLQueryTestSuite: timestamp fractional-second formatting
(Spark '...00.0' vs Postgres '...00'), AVG decimal scale (Spark '8.0' vs
Postgres '8.0000000000000000'), and implicit-cross-join syntax
(FROM t1 JOIN t3 WHERE ... which Postgres rejects). Since --ONLY_IF is a
whole-file directive with no per-query granularity, restore it on these
files to keep them Spark-only, matching the option documented in
PostgresSQLQueryTestSuite. The portable view DDL is retained (harmless).
The remaining subquery files still run cross-DBMS against Postgres.

@szehon-ho szehon-ho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also, checking, we dont remove test coverage right?

we have adequate AS SELECT * FROM VALUES tests?


val outputs: Seq[QueryTestOutput] = queries.map { sql =>
val outputs: Seq[QueryTestOutput] = queries.zipWithIndex.map { case (sql, queryIdx) =>
log.debug(s"[${testCase.name}] Executing query #$queryIdx against $DATABASE_NAME: " +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are these very useful? (asking if its better to remove)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, I think it's harmless.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was concerned it will spam the logs, but will leave you to.

@andylam-db

Copy link
Copy Markdown
Contributor Author

checking, we dont remove test coverage right?

No, basically we're just adjusting to postgres syntax.

@andylam-db andylam-db requested a review from szehon-ho July 10, 2026 22:01
@szehon-ho szehon-ho changed the title [SPARK-46179 FOLLOW UP][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing [SPARK-46179] [FOLLOW UP][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing Jul 10, 2026
@szehon-ho szehon-ho changed the title [SPARK-46179] [FOLLOW UP][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing [SPARK-46179][SQL][FOLLOW UP][TESTS] Remove --ONLY_IF spark from subquery SQL tests to enable PostgreSQL cross-DBMS testing Jul 10, 2026
@szehon-ho szehon-ho closed this in 5e3509f Jul 10, 2026
szehon-ho pushed a commit that referenced this pull request Jul 10, 2026
…query SQL tests to enable PostgreSQL cross-DBMS testing

### What changes were proposed in this pull request?

This PR removes the `--ONLY_IF spark` directive from the IN/EXISTS subquery golden-file tests under `sql/core/src/test/resources/sql-tests/inputs/subquery/` and rewrites their temporary-view DDL from the Spark-specific

```sql
create temporary view t1 as select * from values
  ("t1a", 6S, 8, 10L, float(15.0), 20D, 20E2BD, ...) as t1(t1a, t1b, ...);
```

form into the portable

```sql
create temporary view t1(t1a, t1b, ...) as values
  ('t1a', 6, 8, 10, 15.0, 20.0, 2000.0, ...);
```

form, using ANSI-compatible literals (single-quoted strings, no `S`/`L`/`D`/`E2BD` type suffixes). This lets the query files run against PostgreSQL through `CrossDbmsQueryTestSuite`.

### Why are the changes needed?

The subquery test inputs were guarded by `--ONLY_IF spark`, so they never exercised the cross-DBMS path. Their view DDL relied on Spark-only syntax (typed literal suffixes, `select * from values ... as t(...)`) that PostgreSQL rejects. Making the DDL portable lets these tests validate Spark's subquery semantics against PostgreSQL as an independent oracle, catching correctness divergences.

### Does this PR introduce _any_ user-facing change?

No. Test-only change.

### How was this patch tested?

Existing golden-file tests. The golden `.out` files are regenerated with `SPARK_GENERATE_GOLDEN_FILES=1` and the PostgreSQL cross-DBMS run is exercised via `CrossDbmsQueryTestSuite`.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Anthropic)

Closes #57172 from andylam-db/andylam-db/postgres-subquery-tests.

Authored-by: Andy Lam <andy.lam@databricks.com>
Signed-off-by: Szehon Ho <szehon.apache@gmail.com>
(cherry picked from commit 5e3509f)
Signed-off-by: Szehon Ho <szehon.apache@gmail.com>
@szehon-ho

Copy link
Copy Markdown
Member

Merged to master, 4.x, thanks!

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for finalizing and landing this, @andylam-db and all.

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.

4 participants