Skip to content

Commit

Permalink
[SPARK-51022][SQL] Remove unused tableSampleClause in build() met…
Browse files Browse the repository at this point in the history
…hod of `MsSqlServerSQLQueryBuilder` and `DB2SQLQueryBuilder`

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

This PR aims to remove unused `tableSampleClause` in `build()` method of `MsSqlServerSQLQueryBuilder` and `DB2SQLBuilder`.

From the discussion here: #49711 (comment)

### Why are the changes needed?

Currently, `MsSqlServerDialect` and `DB2Dialect` don't support `tableSample` (default value of `supportsTableSample` is `false`), so `tableSampleClause` is unnecessary when building sql in the `build()` method.

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

No.

### How was this patch tested?

Updated a  related test case and passed GA.

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

No.

Closes #49714 from wayneguow/jdbc_tablesample.

Authored-by: Wei Guo <[email protected]>
Signed-off-by: beliefer <[email protected]>
  • Loading branch information
wayneguow authored and beliefer committed Jan 29, 2025
1 parent 42898c6 commit 840f74a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD

// scalastyle:off
assert(getExternalEngineQuery(df.queryExecution.executedPlan) ==
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE (CASE WHEN ("name" = 'Legolas') THEN IIF(("name" = 'Elf'), 1, 0) ELSE IIF(("name" <> 'Wizard'), 1, 0) END = 1) """
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE (CASE WHEN ("name" = 'Legolas') THEN IIF(("name" = 'Elf'), 1, 0) ELSE IIF(("name" <> 'Wizard'), 1, 0) END = 1) """
)
// scalastyle:on
df.collect()
Expand All @@ -186,7 +186,7 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD

// scalastyle:off
assert(getExternalEngineQuery(df.queryExecution.executedPlan) ==
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE (CASE WHEN ("name" = 'Legolas') THEN IIF(("name" = 'Elf'), 1, 0) ELSE 1 END = 1) """
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE (CASE WHEN ("name" = 'Legolas') THEN IIF(("name" = 'Elf'), 1, 0) ELSE 1 END = 1) """
)
// scalastyle:on
df.collect()
Expand All @@ -203,7 +203,7 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD

// scalastyle:off
assert(getExternalEngineQuery(df.queryExecution.executedPlan) ==
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE (CASE WHEN ("name" = 'Legolas') THEN IIF((CASE WHEN ("name" = 'Elf') THEN IIF(("name" = 'Elrond'), 1, 0) ELSE IIF(("name" = 'Gandalf'), 1, 0) END = 1), 1, 0) ELSE IIF(("name" = 'Sauron'), 1, 0) END = 1) """
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE (CASE WHEN ("name" = 'Legolas') THEN IIF((CASE WHEN ("name" = 'Elf') THEN IIF(("name" = 'Elrond'), 1, 0) ELSE IIF(("name" = 'Gandalf'), 1, 0) END = 1), 1, 0) ELSE IIF(("name" = 'Sauron'), 1, 0) END = 1) """
)
// scalastyle:on
df.collect()
Expand All @@ -220,7 +220,7 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD

// scalastyle:off
assert(getExternalEngineQuery(df.queryExecution.executedPlan) ==
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE ("name" IS NOT NULL) AND ((CASE WHEN "name" = 'Legolas' THEN CASE WHEN "name" = 'Elf' THEN 'Elf' ELSE 'Wizard' END ELSE 'Sauron' END) = "name") """
"""SELECT "dept","name","salary","bonus" FROM "employee" WHERE ("name" IS NOT NULL) AND ((CASE WHEN "name" = 'Legolas' THEN CASE WHEN "name" = 'Elf' THEN 'Elf' ELSE 'Wizard' END ELSE 'Sauron' END) = "name") """
)
// scalastyle:on
df.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private case class DB2Dialect() extends JdbcDialect with SQLConfHelper with NoLe
val offsetClause = dialect.getOffsetClause(offset)

options.prepareQuery +
s"SELECT $columnList FROM ${options.tableOrQuery} $tableSampleClause" +
s"SELECT $columnList FROM ${options.tableOrQuery}" +
s" $whereClause $groupByClause $orderByClause $offsetClause $limitClause"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr

options.prepareQuery +
s"SELECT $limitClause $columnList FROM ${options.tableOrQuery}" +
s" $tableSampleClause $whereClause $groupByClause $orderByClause"
s" $whereClause $groupByClause $orderByClause"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ class JDBCSuite extends QueryTest with SharedSparkSession {
.withLimit(123)
.build()
.trim() ==
"SELECT a,b FROM test FETCH FIRST 123 ROWS ONLY")
"SELECT a,b FROM test FETCH FIRST 123 ROWS ONLY")
}

test("table exists query by jdbc dialect") {
Expand Down

0 comments on commit 840f74a

Please sign in to comment.