mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-27 18:30:38 +00:00
Update src/common/function/src/scalars/json/json_get.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> impl `json_get_int` for new json type Signed-off-by: luofucong <luofc@foxmail.com>
This commit is contained in:
@@ -97,6 +97,80 @@ ORDER BY count DESC, event ASC";
|
||||
+-----------------------+-------+-------+"#;
|
||||
execute_sql_and_expect(frontend, sql, expected).await;
|
||||
|
||||
// query 3:
|
||||
let sql = "\
|
||||
SELECT \
|
||||
json_get_string(data, '$.commit.collection') AS event, \
|
||||
date_part('hour', to_timestamp_micros(json_get_int(data, '$.time_us'))) as hour_of_day, \
|
||||
count() AS count \
|
||||
FROM bluesky \
|
||||
WHERE \
|
||||
(json_get_string(data, '$.kind') = 'commit') AND \
|
||||
(json_get_string(data, '$.commit.operation') = 'create') AND \
|
||||
json_get_string(data, '$.commit.collection') IN \
|
||||
('app.bsky.feed.post', 'app.bsky.feed.repost', 'app.bsky.feed.like') \
|
||||
GROUP BY event, hour_of_day \
|
||||
ORDER BY hour_of_day, event";
|
||||
let expected = r#"
|
||||
+----------------------+-------------+-------+
|
||||
| event | hour_of_day | count |
|
||||
+----------------------+-------------+-------+
|
||||
| app.bsky.feed.like | 16 | 3 |
|
||||
| app.bsky.feed.post | 16 | 3 |
|
||||
| app.bsky.feed.repost | 16 | 1 |
|
||||
+----------------------+-------------+-------+"#;
|
||||
execute_sql_and_expect(frontend, sql, expected).await;
|
||||
|
||||
// query 4:
|
||||
let sql = "\
|
||||
SELECT
|
||||
json_get_string(data, '$.did') as user_id,
|
||||
min(to_timestamp_micros(json_get_int(data, '$.time_us'))) AS first_post_ts
|
||||
FROM bluesky
|
||||
WHERE
|
||||
(json_get_string(data, '$.kind') = 'commit') AND
|
||||
(json_get_string(data, '$.commit.operation') = 'create') AND
|
||||
(json_get_string(data, '$.commit.collection') = 'app.bsky.feed.post')
|
||||
GROUP BY user_id
|
||||
ORDER BY first_post_ts ASC, user_id DESC
|
||||
LIMIT 3";
|
||||
let expected = r#"
|
||||
+----------------------------------+----------------------------+
|
||||
| user_id | first_post_ts |
|
||||
+----------------------------------+----------------------------+
|
||||
| did:plc:yj3sjq3blzpynh27cumnp5ks | 2024-11-21T16:25:49.000167 |
|
||||
| did:plc:l5o3qjrmfztir54cpwlv2eme | 2024-11-21T16:25:49.001905 |
|
||||
| did:plc:s4bwqchfzm6gjqfeb6mexgbu | 2024-11-21T16:25:49.003907 |
|
||||
+----------------------------------+----------------------------+"#;
|
||||
execute_sql_and_expect(frontend, sql, expected).await;
|
||||
|
||||
// query 5:
|
||||
let sql = "
|
||||
SELECT
|
||||
json_get_string(data, '$.did') as user_id,
|
||||
date_part(
|
||||
'epoch',
|
||||
max(to_timestamp_micros(json_get_int(data, '$.time_us'))) -
|
||||
min(to_timestamp_micros(json_get_int(data, '$.time_us')))
|
||||
) AS activity_span
|
||||
FROM bluesky
|
||||
WHERE
|
||||
(json_get_string(data, '$.kind') = 'commit') AND
|
||||
(json_get_string(data, '$.commit.operation') = 'create') AND
|
||||
(json_get_string(data, '$.commit.collection') = 'app.bsky.feed.post')
|
||||
GROUP BY user_id
|
||||
ORDER BY activity_span DESC, user_id DESC
|
||||
LIMIT 3";
|
||||
let expected = r#"
|
||||
+----------------------------------+---------------+
|
||||
| user_id | activity_span |
|
||||
+----------------------------------+---------------+
|
||||
| did:plc:yj3sjq3blzpynh27cumnp5ks | 0.0 |
|
||||
| did:plc:s4bwqchfzm6gjqfeb6mexgbu | 0.0 |
|
||||
| did:plc:l5o3qjrmfztir54cpwlv2eme | 0.0 |
|
||||
+----------------------------------+---------------+"#;
|
||||
execute_sql_and_expect(frontend, sql, expected).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user