Comments (2)
This functionality is supported in BigQuery as described here.
One use case is to simplify queries that process arrays. Instead of doing a cross join, you can use the ARRAY function on a subquery. For example, you can do this:
select d.id,
ARRAY(SELECT CAST(ROW(
date_trunc('day',s.timestamp),
s.user_id,
s.path_id,
s.accept_source
) as ROW(occurred_at TIMESTAMP,
id varchar,
path_id varchar,
accept_source varchar))
FROM UNNEST(ARRAY_CONCAT(
previous_states,
current_state) s
) AS all_states
FROM my_data d
instead of this:
WITH arrayed_data AS (
SELECT d.created_at, d.id,
ARRAY_CONCAT(d.previous_states,
current_state) as accepted
FROM my_data d
)
select all_a.id,
ARRAY_AGG(CAST(ROW(
date_trunc('day',a.timestamp),
a.user_id,
a.path_id,
a.accept_source
) as ROW(occurred_at TIMESTAMP,
id varchar,
path_id varchar,
accept_source varchar)))
FROM arrayed_data as all_a
CROSS JOIN UNNEST(all_a.accepted) AS a
GROUP BY all_a.id
from trino.
Below are a few standalone tests that show the current and desired behavior.
Example of query we'd like to support:
SELECT a,
ARRAY(SELECT cast(row(d.x, d.y) as row(e VARCHAR, f VARCHAR))
FROM UNNEST(c) as d)
FROM (VALUES(1,0,
ARRAY[cast(row('a','1') as row(x varchar, y varchar)),
cast(row('b','2') as row(x varchar, y varchar)),
cast(row('c','3') as row(x varchar, y varchar))])) t(a,b,c)
Desired output:
Row # | a | d |
---|---|---|
1 | 1 | a, 1 |
b, 2 | ||
c, 3 |
Example of query that produces the same output today, but requires an aggregation:
SELECT a,array_agg(cast(row(d.x, d.y) as row(e VARCHAR, f VARCHAR)))
FROM (VALUES(1,0,
ARRAY[cast(row('a','1') as row(x varchar, y varchar)),
cast(row('b','2') as row(x varchar, y varchar)),
cast(row('c','3') as row(x varchar, y varchar))])) t(a,b,c)
CROSS JOIN UNNEST(c) as d
GROUP BY a
Example of query that produces one row per array element:
SELECT a,cast(row(d.x, d.y) as row(e VARCHAR, f VARCHAR))
FROM (VALUES(1,0,
ARRAY[cast(row('a','1') as row(x varchar, y varchar)),
cast(row('b','2') as row(x varchar, y varchar)),
cast(row('c','3') as row(x varchar, y varchar))])) t(a,b,c)
CROSS JOIN UNNEST(c) as d
Output:
Row # | a | d |
---|---|---|
1 | 1 | a, 1 |
2 | 1 | b, 2 |
3 | 1 | c, 3 |
from trino.
Related Issues (20)
- trino-client conflicts with okhttp
- Reason why exchange.sink-max-file-size does not limit writing file size on disk?
- Convert trino opensearch plugin to use the supported opensearch java client
- Returns scientific notation when converting double to varchar HOT 2
- TrinoException: Concatenated string is too large,Can I Increase the size of DEFAULT-MAX-PAGE-SIZE-IN_BYTES? HOT 1
- Incorrect results for correlated query with aggregation HOT 11
- Use point-in-time (PIT) search instead of scroll search in OpenSearch connector HOT 1
- Trino client and jdbc driver, kerberos authentication doesn't work with IBM java HOT 4
- Dropping a MATERIALIZED VIEW fails in the latest versions. HOT 4
- Support Iceberg Nessie Catalog OAuth2 Authentication Type HOT 3
- Trino-verifier: Not returning any results
- Can the issue of comparison value type having to be consistent with the table field's own type in query conditions be resolved? HOT 4
- Support Optimizer rewriting of queries using Materialized Views
- Support query result caching HOT 1
- How can I add a aggration function like any_value bug has second param about isIgnoreNull? HOT 1
- system.jdbc Tables not following visibility rules HOT 1
- Trino 380 cannot verify JWT Audience HOT 5
- Trino Druid connector does not provide the exact semantic/syntax error with query. HOT 5
- `SHOW CREATE TABLE` shouldn't be allowed on metadata tables HOT 2
- Remove deprecated constructors from DriverConnectionFactory
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trino.