Skip to content
Permalink
Browse files
Merge branch 'gerrit/neo'
Change-Id: Iae10a9a8b2f64117fd2272dcc80dc0d2d375ef0f
  • Loading branch information
mblow committed Feb 25, 2022
2 parents c1c5bec + 55ef99b commit 51543d9d28f13107514d900e0b3bb4e7b09ccc58
Showing 69 changed files with 3,040 additions and 63 deletions.
@@ -130,10 +130,16 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.http.Consts;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.AuthState;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
@@ -157,6 +163,7 @@
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpCoreContext;
import org.apache.http.util.EntityUtils;
import org.apache.hyracks.algebricks.common.utils.Pair;
import org.apache.hyracks.http.server.utils.HttpUtil;
@@ -673,8 +680,8 @@ protected HttpResponse executeAndCheckHttpRequest(HttpUriRequest method, Predica
protected HttpResponse executeHttpRequest(HttpUriRequest method) throws Exception {
// https://issues.apache.org/jira/browse/ASTERIXDB-2315
ExecutorService executor = Executors.newSingleThreadExecutor();
CloseableHttpClient client =
HttpClients.custom().setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE).build();
CloseableHttpClient client = HttpClients.custom().addInterceptorFirst(new PreemptiveAuthInterceptor())
.setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE).build();
Future<HttpResponse> future = executor.submit(() -> {
try {
return client.execute(method, getHttpContext());
@@ -2902,4 +2909,25 @@ private static boolean isCcEndPointPath(String endPoint) {
private static boolean containsPort(String endPoint) {
return StringUtils.contains(endPoint, ':');
}

// adapted from https://stackoverflow.com/questions/2014700/preemptive-basic-authentication-with-apache-httpclient-4
static class PreemptiveAuthInterceptor implements HttpRequestInterceptor {

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
// if no auth scheme available yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
CredentialsProvider credsProvider =
(CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
if (credsProvider != null) {
HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
Credentials creds =
credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds != null) {
authState.update(new BasicScheme(), creds);
}
}
}
}
}
}
@@ -18,49 +18,32 @@
*/

/*
* Test plan for CH2 Q8
* Test plan for CH2 Q1
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT
GET_YEAR(DATE(rn1coolis.o_entry_d)) AS l_year,
ROUND((SUM(CASE WHEN sun2.n_name = 'Germany' THEN rn1coolis.ol_amount ELSE 0 END) / SUM(rn1coolis.ol_amount)),2)
AS mkt_share
FROM (
SELECT rn1cooli.o_entry_d, rn1cooli.ol_amount, s.s_w_id, s.s_i_id
FROM stock s
JOIN (
SELECT o.o_entry_d, ol.ol_i_id, ol.ol_amount, ol.ol_supply_w_id
FROM orders o, o.o_orderline ol, item i
JOIN (
SELECT c.c_id,c.c_w_id, c.c_d_id
FROM customer c
JOIN (
SELECT n1.n_nationkey
FROM nation n1, region r
WHERE n1.n_regionkey = r.r_regionkey AND r.r_name = 'Europe'
) nr ON nr.n_nationkey = string_to_codepoint(c.c_state)[0]
) cnr ON cnr.c_id = o.o_c_id
AND cnr.c_w_id = o.o_w_id AND cnr.c_d_id = o.o_d_id AND i.i_data LIKE '%b'
AND i.i_id = ol.ol_i_id AND ol.ol_i_id < 1000
AND o.o_entry_d BETWEEN '2017-01-01 00:00:00.000000' AND '2018-12-31 00:00:00.000000'
) rn1cooli ON rn1cooli.ol_i_id = s.s_i_id AND rn1cooli.ol_supply_w_id = s.s_w_id
) rn1coolis
JOIN (
SELECT su.su_suppkey, n2.n_name
FROM supplier su, nation n2
WHERE su.su_nationkey = n2.n_nationkey
) sun2 ON rn1coolis.s_w_id * rn1coolis.s_i_id MOD 10000 = sun2.su_suppkey
GROUP BY get_year(date(rn1coolis.o_entry_d))
ORDER BY l_year;
SELECT ol.ol_number,
SUM(ol.ol_quantity) as sum_qty,
SUM(ol.ol_amount) as sum_amount,
AVG(ol.ol_quantity) as avg_qty,
AVG(ol.ol_amount) as avg_amount,
COUNT(*) as COUNT_order
FROM orders o, o.o_orderline ol
WHERE ol.ol_delivery_d > '2014-07-01 00:00:00'
GROUP BY ol.ol_number
ORDER BY ol.ol_number;
@@ -0,0 +1,50 @@
/*
* 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.
*/

/*
* Test plan for CH2 Q10
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT c.c_id, c.c_last, SUM(ol.ol_amount) as revenue, c.c_city, c.c_phone, n.n_name
FROM nation n, customer c, orders o, o.o_orderline ol
WHERE c.c_id = o.o_c_id
AND c.c_w_id = o.o_w_id
AND c.c_d_id = o.o_d_id
AND o.o_entry_d >= '2015-10-01 00:00:00.000000'
AND o.o_entry_d < '2016-01-01 00:00:00.000000'
AND n.n_nationkey = string_to_codepoint(c.c_state)[0]
GROUP BY c.c_id, c.c_last, c.c_city, c.c_phone, n.n_name
ORDER BY revenue DESC
LIMIT 20;
@@ -0,0 +1,52 @@
/*
* 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.
*/

/*
* Test plan for CH2 Q11
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT s.s_i_id, SUM(s.s_order_cnt) as ordercount
FROM nation n, supplier su, stock s
WHERE s.s_w_id * s.s_i_id MOD 10000 = su.su_suppkey
AND su.su_nationkey = n.n_nationkey
AND n.n_name = 'Germany'
GROUP BY s.s_i_id
HAVING SUM(s.s_order_cnt) >
(SELECT VALUE SUM(s1.s_order_cnt) * 0.00005
FROM nation n1, supplier su1, stock s1
WHERE s1.s_w_id * s1.s_i_id MOD 10000 = su1.su_suppkey
AND su1.su_nationkey = n1.n_nationkey
AND n1.n_name = 'Germany')[0]
ORDER BY ordercount DESC;
@@ -0,0 +1,49 @@
/*
* 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.
*/

/*
* Test plan for CH2 Q12
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT o.o_ol_cnt,
SUM (case WHEN o.o_carrier_id = 1 or o.o_carrier_id = 2
THEN 1 ELSE 0 END) AS high_line_COUNT,
SUM (case WHEN o.o_carrier_id <> 1 AND o.o_carrier_id <> 2
THEN 1 ELSE 0 END) AS low_line_COUNT
FROM orders o, o.o_orderline ol
WHERE o.o_entry_d <= ol.ol_delivery_d
AND ol.ol_delivery_d >= '2016-01-01 00:00:00.000000' AND ol.ol_delivery_d < '2017-01-01 00:00:00.000000'
GROUP BY o.o_ol_cnt
ORDER BY o.o_ol_cnt;
@@ -0,0 +1,49 @@
/*
* 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.
*/

/*
* Test plan for CH2 Q13
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT c_orders.c_count, COUNT(*) as custdist
FROM (SELECT c.c_id, COUNT(o.o_id) as c_count
FROM customer c LEFT OUTER JOIN orders o ON (
c.c_w_id = o.o_w_id
AND c.c_d_id = o.o_d_id
AND c.c_id = o.o_c_id
AND o.o_carrier_id > 8)
GROUP BY c.c_id) as c_orders
GROUP BY c_orders.c_count
ORDER BY custdist DESC, c_orders.c_count DESC;
@@ -0,0 +1,44 @@
/*
* 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.
*/

/*
* Test plan for CH2 Q14
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT 100.00 * SUM(CASE WHEN i.i_data LIKE 'pr%'
THEN ol.ol_amount ELSE 0 END) / (1+SUM(ol.ol_amount)) AS promo_revenue
FROM item i, orders o, o.o_orderline ol
WHERE ol.ol_i_id = i.i_id
AND ol.ol_delivery_d >= '2017-09-01 00:00:00.000000' AND ol.ol_delivery_d < '2017-10-01 00:00:00.000000';

0 comments on commit 51543d9

Please sign in to comment.