Skip to content

Instantly share code, notes, and snippets.

import java.util.*;
public class MyTest {
private static int shortestPath(int[] from, int[] to, int source, int destination) {
Map<Integer, Set<Integer>> graph = getGraph(from, to);
return iterate(graph, new HashSet<>(), source, destination);
}
select
user_id,
LAST_VALUE(location)over w,
event_time
from my_users
window as (user_id by category order by event_time)
select
user_id,
LAST_VALUE(location)over w,
event_time
from my_users
window as (
user_id by category
order by event_time
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
)
select
user_id,
LAST_VALUE(location)over w,
event_time
from my_users
window as (
user_id by category
order by event_time
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
)

+------------+-----------------+---------------------------+ | Category | Product Name | Product Description | +------------+-----------------+---------------------------+ | Casual | Black Shoe | This is a shoe | | Electronic | Washing Machine | This is a washing machine | | Electronic | TV | This is a tv | | Casual | Blue Trousers | This is trousers | | Casual | White Shoe | This is a shoe | | Casual | Blue Shoe | This is a shoe | +------------+-----------------+---------------------------+

This is shoe
Category Product Name Product Description
Casual Black Shoe
SELECT
p.category,
p.product_name,
p.product_description
FROM (
SELECT
p.category,
p.product_name,
p.product_description,
rank() over w1 rnk
Category Product Name Product Description
Casual Black Shoe This is a shoe
Electronic Washing Machine This is a washing machine
Electronic TV This is a tv
Casual Blue Trousers This is trousers
SELECT
p.category,
p.product_name,
p.product_description
FROM (
SELECT
p.category,
p.product_name,
p.product_description,
(percent_rank() OVER w1) * 100 AS percent_rnk
Category Product Name Product Description
Casual Black Shoe This is a shoe
Electronic Washing Machine This is a washing machine
Casual Blue Trousers This is trousers