Skip to content

Commit

Permalink
#1376 change from postgres quantile to percentile_disc
Browse files Browse the repository at this point in the history
  • Loading branch information
cproof committed Sep 23, 2024
1 parent d82bc39 commit 0555244
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public PreparedStatement createPreparedStatement(Connection con) throws SQLExcep
final String sql = "SELECT" +
" count(t.open_test_uuid)," +
" extract(hour from t.time AT TIME ZONE t.timezone) AS hour," +
" quantile(t.speed_download :: bigint, ?) quantile_down," +
" quantile(t.speed_upload :: bigint, ?) quantile_up," +
" quantile(t.ping_median :: bigint, ?) quantile_ping" +
" percentile_disc(?) WITHIN GROUP (ORDER BY t.speed_download :: bigint) AS quantile_down," +
" percentile_disc(?) WITHIN GROUP (ORDER BY t.speed_upload :: bigint) AS quantile_up," +
" percentile_disc(?) WITHIN GROUP (ORDER BY t.ping_median :: bigint) AS quantile_ping" +
" FROM test t " +
queryParser.getJoins() +
" WHERE t.deleted = false" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ private PreparedStatement getPreparedStatementSelectProviders(final Connection c
.format("SELECT" +
(group ? " p.name, p.shortname, " : "") +
" count(t.uid) count," +
" quantile(speed_download::bigint, ?::double precision) quantile_down," +
" quantile(speed_upload::bigint, ?::double precision) quantile_up," +
" quantile(%1$s::bigint, ?::double precision) quantile_signal," +
" quantile(ping_median::bigint, ?::double precision) quantile_ping," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_download :: bigint) AS quantile_down," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_upload :: bigint) AS quantile_up," +
" percentile_disc(?) WITHIN GROUP (ORDER BY %1$s :: bigint) AS quantile_signal," +
" percentile_disc(?) WITHIN GROUP (ORDER BY ping_median :: bigint) AS quantile_ping," +

getClausesFor("speed_download", "down", ultraGreen, false) + "," +
getClausesFor("speed_upload", "up", ultraGreen, false) + "," +
Expand Down Expand Up @@ -236,10 +236,10 @@ private PreparedStatement getPreparedStatementSelectProviders(final Connection c
((group && useMobileProvider) ? " p.name AS name, p.shortname AS shortname, p.mccmnc AS sim_mcc_mnc, " : "") +
((group && !useMobileProvider) ? " public_ip_as_name AS name, public_ip_as_name AS shortname, t.public_ip_asn AS asn, " : "") +
" count(t.uid) count," +
" quantile(speed_download::bigint, ?::double precision) quantile_down," +
" quantile(speed_upload::bigint, ?::double precision) quantile_up," +
" quantile(%1$s::bigint, ?::double precision) quantile_signal," +
" quantile(ping_median::bigint, ?::double precision) quantile_ping," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_download :: bigint) AS quantile_down," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_upload :: bigint) AS quantile_up," +
" percentile_disc(?) WITHIN GROUP (ORDER BY %1$s :: bigint) AS quantile_signal," +
" percentile_disc(?) WITHIN GROUP (ORDER BY ping_median :: bigint) AS quantile_ping," +

getClausesFor("speed_download", "down", ultraGreen, false) + "," +
getClausesFor("speed_upload", "up", ultraGreen, false) + "," +
Expand Down Expand Up @@ -370,9 +370,10 @@ private static PreparedStatement setFieldsPreparedStatementSelectDevices(float q
private static PreparedStatement getPreparedStatementSelectDevices(Connection conn, boolean group, double accuracy, String country, boolean useMobileProvider, String where, int maxDevices, Timestamp endDate, int province) throws SQLException {
String sql = String.format("SELECT" +
(group ? " COALESCE(adm.fullname, t.model) model," : "") +
" count(t.uid) count," + " quantile(speed_download::bigint, ?::double precision) quantile_down," +
" quantile(speed_upload::bigint, ?::double precision) quantile_up," +
" quantile(ping_median::bigint, ?::double precision) quantile_ping" +
" count(t.uid) count," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_download :: bigint) AS quantile_down," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_upload :: bigint) AS quantile_up," +
" percentile_disc(?) WITHIN GROUP (ORDER BY ping_median :: bigint) AS quantile_ping" +
" FROM test t" +
" LEFT JOIN device_map adm ON adm.codename=t.model" +
" LEFT JOIN network_type nt ON nt.uid=t.network_type" +
Expand All @@ -394,9 +395,10 @@ private static PreparedStatement getPreparedStatementSelectDevices(Connection co
if (country != null) {
sql = String.format("SELECT" +
(group ? " COALESCE(adm.fullname, t.model) model," : "") +
" count(t.uid) count," + " quantile(speed_download::bigint, ?::double precision) quantile_down," +
" quantile(speed_upload::bigint, ?::double precision) quantile_up," +
" quantile(ping_median::bigint, ?::double precision) quantile_ping" +
" count(t.uid) count," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_download :: bigint) AS quantile_down," +
" percentile_disc(?) WITHIN GROUP (ORDER BY speed_upload :: bigint) AS quantile_up," +
" percentile_disc(?) WITHIN GROUP (ORDER BY ping_median :: bigint) AS quantile_ping" +
" FROM test t" +
" LEFT JOIN device_map adm ON adm.codename=t.model" +
" LEFT JOIN network_type nt ON nt.uid=t.network_type" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
class HourlyStatisticRepositoryImplTest {

private static final String SQL_QUERY = "SELECT count(t.open_test_uuid), " +
"extract(hour from t.time AT TIME ZONE t.timezone) AS hour, " +
"quantile(t.speed_download :: bigint, ?) quantile_down, " +
"quantile(t.speed_upload :: bigint, ?) quantile_up, " +
"quantile(t.ping_median :: bigint, ?) quantile_ping " +
"extract(hour from t.time AT TIME ZONE t.timezone) AS hour," +
" percentile_disc(?) WITHIN GROUP (ORDER BY t.speed_download :: bigint) AS quantile_down," +
" percentile_disc(?) WITHIN GROUP (ORDER BY t.speed_upload :: bigint) AS quantile_up," +
" percentile_disc(?) WITHIN GROUP (ORDER BY t.ping_median :: bigint) AS quantile_ping " +
"FROM test t LEFT JOIN network_type nt ON nt.uid=t.network_type " +
"LEFT JOIN test_loopmode l ON (l.test_uuid = t.uuid) " +
"LEFT JOIN device_map adm ON adm.codename=t.model " +
Expand Down

0 comments on commit 0555244

Please sign in to comment.