/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Description : Test multiple window functions in a single statement
* Expected Res : SUCCESS
*/
drop dataverse test if exists;
create dataverse test;
use test;
create type test.t1Type as open {
c1 : bigint
};
create dataset t1(t1Type) primary key c1;
create function q1_mixed(P, N, D) {
from
t1,
range(t1.one, P) p,
range(t1.one, N) n,
range(t1.one, D) d
let
rank_result_expected = (N - n) * D + 1,
rank_result_actual = rank() over ( partition by t1.c2, p order by n desc ),
rank_result_delta = rank_result_expected - rank_result_actual,
percent_rank_result_expected = (rank_result_expected - 1) / (N * D - 1),
percent_rank_result_actual = percent_rank() over ( partition by t1.c2, p order by n desc ),
percent_rank_result_delta_raw = percent_rank_result_expected - percent_rank_result_actual,
percent_rank_result_delta = case when percent_rank_result_delta_raw < 0.001 then 0 else percent_rank_result_delta_raw end
select
min(rank_result_delta) rank_min_delta,
max(rank_result_delta) rank_max_delta,
min(percent_rank_result_delta) percent_rank_min_delta,
max(percent_rank_result_delta) percent_rank_max_delta
};
q1_mixed(2, 2, 2);