trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.49k stars 3.02k forks source link

Faker: Override generator expression in select statement #24078

Closed brybacki closed 1 week ago

brybacki commented 1 week ago

Description

Faker: Add a possibility to override the generator expression in the select statement. It is possible to do something like this:

SELECT name FROM person WHERE name='#{Name.first_name}' limit 1

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required. ( ) Release notes are required. Please propose a release note for me. ( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`issuenumber`)
brybacki commented 1 week ago

Using a condition in the where clause to specify the pattern to use for generation is an abuse of the semantics of the where clause.

Specifically, when a column is compared to a string, the result should be such that the values of that column match exactly the provided string. This is not the case here.

That is true, thanks for the comment. I think we can do a virtual column. Or maybe we can drop this PR and just improve documentation.

brybacki commented 1 week ago

There is already a way to do what we wanted from SQL with Faker connector function random_string.

SELECT id, random_string('#{Name.first_name}') AS name
FROM faker.default.table
LIMIT 50
UNION ALL
SELECT id random_string('#{Name.first_name} #{Name.first_name}') AS name
FROM faker.default.table
LIMIT 50