Skip to content

Conversation

@berkaysynnada
Copy link
Contributor

Which issue does this PR close?

Closes #7367.

Rationale for this change

There are 2 different REPLACE usages in some other platforms: One of them is like:

SELECT product_id, 
REPLACE(product_name, 'OldBrand', 'NewBrand') AS modified_product_name,
price
FROM products;

which already works successfully, and the second one is like:

SELECT * REPLACE (price*2 AS price) FROM products 

for more examples: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#select_replace
which is parsed and put into WildcardAdditionalOptions, but not evaluated. This PR completes the second version of REPLACE usage.

What changes are included in this PR?

After expanding wildcards, replace option in the SelectItem is checked. If it is Some, the corresponding expression is found and replaced with the new expression, but the name of that column is kept the same, by providing an alias as the original column name.

Are these changes tested?

Yes, with .slt tests

Are there any user-facing changes?

@github-actions github-actions bot added sql SQL Planner logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Aug 22, 2023
@alamb alamb changed the title New REPLACE Support Support REPLACE SQL alias syntax Aug 23, 2023
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

LGTM -- thank you @berkaysynnada

@alamb alamb merged commit bd90e4a into apache:main Aug 23, 2023
@berkaysynnada berkaysynnada deleted the feature/replace branch August 23, 2023 19:10
@andygrove andygrove added the enhancement New feature or request label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request logical-expr Logical plan and expressions sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two Different REPLACE Usages

4 participants