You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "milosstojanovic (via GitHub)" <gi...@apache.org> on 2025/02/24 09:39:05 UTC
[PR] Add rpad and lpad support for PostgreDialect and MsSQLServerDialect [spark]
milosstojanovic opened a new pull request, #50060:
URL: https://github.com/apache/spark/pull/50060
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50060:
URL: https://github.com/apache/spark/pull/50060#issuecomment-2701050798
cc @dongjoon-hyun @MaxGekk
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1977211867
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -84,6 +84,17 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case _ => super.dialectFunctionName(funcName)
}
+ override def visitSQLFunction(funcName: String, inputs: Array[String]): String =
+ funcName match {
+ case "RPAD" =>
+ val Array(str, len, pad) = inputs
+ s"LEFT(CONCAT($str, REPLICATE($pad, $len)), $len)"
+ case "LPAD" =>
+ val Array(str, len, pad) = inputs
+ s"RIGHT(CONCAT(REPLICATE($pad, $len), $str), $len)"
+ case _ => super.visitSQLFunction(funcName, inputs)
+ }
Review Comment:
Do you think `MsSqlServerDialect` supports pushdown `RPAD` and `LPAD`?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1981166899
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/PostgresIntegrationSuite.scala:
##########
@@ -355,4 +355,16 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JDBCT
parameters = Map("pos" -> "0", "type" -> "\"ARRAY<ARRAY<INT>>\"")
)
}
+
+ test("SPARK-51321: Postgres pushdown for RPAD expression on string column") {
+ val df = sql(
+ s"""|SELECT name FROM $catalogName.employee
+ |WHERE rpad(name, 10, 'x') = 'amyxxxxxxx'
+ |""".stripMargin
+ )
+ checkFilterPushed(df)
+ val rows = df.collect()
+ assert(rows.length === 1)
+ assert(rows(0).getString(0) === "amy")
+ }
Review Comment:
Please also add tests for `lpad`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1977512925
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
I created extra table to avoid any side effects in other tests with extra rows, but can re-use the same table
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50060:
URL: https://github.com/apache/spark/pull/50060#issuecomment-2678235174
Please create an issue for track down.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on PR #50060:
URL: https://github.com/apache/spark/pull/50060#issuecomment-2692835887
@beliefer - added tests cases
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1981464212
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala:
##########
@@ -48,7 +48,8 @@ private case class PostgresDialect()
private val supportedAggregateFunctions = Set("MAX", "MIN", "SUM", "COUNT", "AVG",
"VAR_POP", "VAR_SAMP", "STDDEV_POP", "STDDEV_SAMP", "COVAR_POP", "COVAR_SAMP", "CORR",
"REGR_INTERCEPT", "REGR_R2", "REGR_SLOPE", "REGR_SXY")
- private val supportedFunctions = supportedAggregateFunctions
+ private val supportedStringFunctions = Set("RPAD", "LPAD")
+ private val supportedFunctions = supportedAggregateFunctions ++ supportedStringFunctions
Review Comment:
Please add these code to `MsSqlServerDialect` too.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1981494859
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala:
##########
@@ -48,7 +48,8 @@ private case class PostgresDialect()
private val supportedAggregateFunctions = Set("MAX", "MIN", "SUM", "COUNT", "AVG",
"VAR_POP", "VAR_SAMP", "STDDEV_POP", "STDDEV_SAMP", "COVAR_POP", "COVAR_SAMP", "CORR",
"REGR_INTERCEPT", "REGR_R2", "REGR_SLOPE", "REGR_SXY")
- private val supportedFunctions = supportedAggregateFunctions
+ private val supportedStringFunctions = Set("RPAD", "LPAD")
+ private val supportedFunctions = supportedAggregateFunctions ++ supportedStringFunctions
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1977206479
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
Please create extra table, you can reuse `employee`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1977510615
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -84,6 +84,17 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case _ => super.dialectFunctionName(funcName)
}
+ override def visitSQLFunction(funcName: String, inputs: Array[String]): String =
+ funcName match {
+ case "RPAD" =>
+ val Array(str, len, pad) = inputs
+ s"LEFT(CONCAT($str, REPLICATE($pad, $len)), $len)"
+ case "LPAD" =>
+ val Array(str, len, pad) = inputs
+ s"RIGHT(CONCAT(REPLICATE($pad, $len), $str), $len)"
+ case _ => super.visitSQLFunction(funcName, inputs)
+ }
Review Comment:
What do you mean? With my change in this PR `MsSqlServerDialect` will support pushdown of `RPAD` and `LPAD` using custom implementations since MsSQLServer does not support `RPAD` and `LPAD` natively
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1976798658
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/PostgresIntegrationSuite.scala:
##########
@@ -355,4 +356,16 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JDBCT
parameters = Map("pos" -> "0", "type" -> "\"ARRAY<ARRAY<INT>>\"")
)
}
+
+ test("SPARK-51321: Postgres pushdown for RPAD expression on string column") {
+ val df = sql(s"SELECT * FROM $catalogName.employee WHERE rpad(name, 10, 'x') = 'xxxxxxxxxx'")
+ val pushedQuery = df.queryExecution.executedPlan.toString().toLowerCase(Locale.ROOT)
Review Comment:
Please use `checkFilterPushed` here.
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -225,4 +226,44 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
// scalastyle:on
df.collect()
}
+
+ test("SPARK-51321: SQLServer pushdown for RPAD expression on string column") {
+ // Query that applies RPAD on the "name" column, expecting a padded result of 10 characters.
+ val df = sql(s"SELECT * FROM $catalogName.employee WHERE rpad(name, 10, 'x') = 'xxxxxxxxxx'")
+ val pushedQuery = getExternalEngineQuery(df.queryExecution.executedPlan)
+ .toLowerCase(Locale.ROOT)
+
+ // Check that the pushed-down query contains the expected function calls.
+ assert(pushedQuery.contains("left("),
+ s"Expected LEFT function call in the pushed-down query, but got: $pushedQuery")
+ assert(pushedQuery.contains("concat("),
+ s"Expected CONCAT function call in the pushed-down query, but got: $pushedQuery")
+ assert(pushedQuery.contains("replicate("),
+ s"Expected REPLICATE function call in the pushed-down query, but got: $pushedQuery")
+
+ assert(!pushedQuery.contains("filterexec"),
+ s"Expected the filter to be pushed down, but found a Spark-side filter in: $pushedQuery")
+
+ df.collect()
+ }
+
+ test("SPARK-51321: SQLServer pushdown for LPAD expression on string column") {
+ // Query that applies LPAD on the "name" column, expecting a padded result of 10 characters.
+ val df = sql(s"SELECT * FROM $catalogName.employee WHERE lpad(name, 10, 'x') = 'xxxxxxxxxx'")
+ val pushedQuery = getExternalEngineQuery(df.queryExecution.executedPlan)
Review Comment:
Please use `checkFilterPushed` here.
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala:
##########
@@ -48,7 +48,10 @@ private case class PostgresDialect()
private val supportedAggregateFunctions = Set("MAX", "MIN", "SUM", "COUNT", "AVG",
"VAR_POP", "VAR_SAMP", "STDDEV_POP", "STDDEV_SAMP", "COVAR_POP", "COVAR_SAMP", "CORR",
"REGR_INTERCEPT", "REGR_R2", "REGR_SLOPE", "REGR_SXY")
- private val supportedFunctions = supportedAggregateFunctions
+ private val supportedStringFunctions = Set("RPAD")
+ private val supportedFunctions =
+ supportedAggregateFunctions ++
+ supportedStringFunctions
Review Comment:
```suggestion
private val supportedFunctions = supportedAggregateFunctions ++ supportedStringFunctions
```
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -225,4 +226,44 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
// scalastyle:on
df.collect()
}
+
+ test("SPARK-51321: SQLServer pushdown for RPAD expression on string column") {
+ // Query that applies RPAD on the "name" column, expecting a padded result of 10 characters.
+ val df = sql(s"SELECT * FROM $catalogName.employee WHERE rpad(name, 10, 'x') = 'xxxxxxxxxx'")
+ val pushedQuery = getExternalEngineQuery(df.queryExecution.executedPlan)
Review Comment:
ditto
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -84,6 +84,17 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case _ => super.dialectFunctionName(funcName)
}
+ override def visitSQLFunction(funcName: String, inputs: Array[String]): String =
+ funcName match {
+ case "RPAD" =>
+ val Array(str, len, pad) = inputs
+ s"LEFT(CONCAT($str, REPLICATE($pad, $len)), $len)"
+ case "LPAD" =>
+ val Array(str, len, pad) = inputs
+ s"RIGHT(CONCAT(REPLICATE($pad, $len), $str), $len)"
+ case _ => super.visitSQLFunction(funcName, inputs)
+ }
Review Comment:
Are you sure it works well?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50060:
URL: https://github.com/apache/spark/pull/50060#issuecomment-2684866885
Please add test cases.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1977208076
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/PostgresIntegrationSuite.scala:
##########
@@ -139,6 +139,15 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JDBCT
.executeUpdate()
connection.prepareStatement("INSERT INTO unsupported_array_of_array_of_int " +
"VALUES (array[array[1],array[2]]), (array[3])").executeUpdate()
+
+ connection.prepareStatement("CREATE TABLE employee_rpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
ditto.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #50060:
URL: https://github.com/apache/spark/pull/50060#issuecomment-2703810297
thanks, merging to master!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on PR #50060:
URL: https://github.com/apache/spark/pull/50060#issuecomment-2684639209
> Please create an issue for track down.
Done SPARK-51321
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1978890809
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
Please refer to https://github.com/apache/spark/pull/50068
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1978820582
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
some tests already present in both suites are relying on current data in employee tables and if I add additional rows they start failing
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1977148496
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -84,6 +84,17 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case _ => super.dialectFunctionName(funcName)
}
+ override def visitSQLFunction(funcName: String, inputs: Array[String]): String =
+ funcName match {
+ case "RPAD" =>
+ val Array(str, len, pad) = inputs
+ s"LEFT(CONCAT($str, REPLICATE($pad, $len)), $len)"
+ case "LPAD" =>
+ val Array(str, len, pad) = inputs
+ s"RIGHT(CONCAT(REPLICATE($pad, $len), $str), $len)"
+ case _ => super.visitSQLFunction(funcName, inputs)
+ }
Review Comment:
Do you have any concerns with the implementation? Yes, tested it. Also, this is a common implementation you can find on internet, for example:" https://databaserookies.wordpress.com/2017/01/06/sqlserverlearning-string-padding-in-sql-server-lpadrpad/
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1979075627
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1978561794
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -84,6 +84,17 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case _ => super.dialectFunctionName(funcName)
}
+ override def visitSQLFunction(funcName: String, inputs: Array[String]): String =
+ funcName match {
+ case "RPAD" =>
+ val Array(str, len, pad) = inputs
+ s"LEFT(CONCAT($str, REPLICATE($pad, $len)), $len)"
+ case "LPAD" =>
+ val Array(str, len, pad) = inputs
+ s"RIGHT(CONCAT(REPLICATE($pad, $len), $str), $len)"
+ case _ => super.visitSQLFunction(funcName, inputs)
+ }
Review Comment:
https://github.com/apache/spark/pull/50143
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] Add rpad and lpad support for PostgreDialect and MsSQLServerDialect [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic closed pull request #50060: Add rpad and lpad support for PostgreDialect and MsSQLServerDialect
URL: https://github.com/apache/spark/pull/50060
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #50060: [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown
URL: https://github.com/apache/spark/pull/50060
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1978531530
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/MsSqlServerDialect.scala:
##########
@@ -84,6 +84,17 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
case _ => super.dialectFunctionName(funcName)
}
+ override def visitSQLFunction(funcName: String, inputs: Array[String]): String =
+ funcName match {
+ case "RPAD" =>
+ val Array(str, len, pad) = inputs
+ s"LEFT(CONCAT($str, REPLICATE($pad, $len)), $len)"
+ case "LPAD" =>
+ val Array(str, len, pad) = inputs
+ s"RIGHT(CONCAT(REPLICATE($pad, $len), $str), $len)"
+ case _ => super.visitSQLFunction(funcName, inputs)
+ }
Review Comment:
Uh, there is no way to accurate it. I will create a PR to fix it.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1978531895
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
Which side effects?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "milosstojanovic (via GitHub)" <gi...@apache.org>.
milosstojanovic commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1977786135
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
It messes up other tests if I re-use the same table and add more rows so would create dedicated one if it is not an issue
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51321][SQL] Add rpad and lpad support for PostgresDialect and MsSQLServerDialect expression pushdown [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50060:
URL: https://github.com/apache/spark/pull/50060#discussion_r1978888621
##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/MsSqlServerIntegrationSuite.scala:
##########
@@ -91,6 +91,14 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD
|)
""".stripMargin
).executeUpdate()
+ connection.prepareStatement("CREATE TABLE employee_rpadlpad_test (dept INTEGER, name VARCHAR(32)")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (1, 'spark'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (2, 'xxxx'")
+ .executeUpdate()
+ connection.prepareStatement("INSERT INTO employee_rpadlpad_test VALUES (3, 'xxxxxxxxxx'")
+ .executeUpdate()
Review Comment:
I think you don't need add extra rows.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org