Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format SQL in prepration for SQLFluff v2 #3364

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_01.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_01: % of pages having headings
CREATE TEMPORARY FUNCTION getElements(payload STRING)
RETURNS ARRAY<STRING> LANGUAGE js AS '''
RETURNS ARRAY<STRING>
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var elements = JSON.parse($._element_count);
Expand Down
19 changes: 11 additions & 8 deletions sql/2019/accessibility/09_01b.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_01b: % of pages having any heading
CREATE TEMPORARY FUNCTION hasHeading(payload STRING)
RETURNS BOOLEAN LANGUAGE js AS '''
RETURNS BOOLEAN
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var elements = JSON.parse($._element_count);
Expand All @@ -20,12 +22,13 @@ SELECT
COUNT(0) AS total_pages,
COUNTIF(has_heading) AS total_with_heading,
ROUND(COUNTIF(has_heading) * 100 / COUNT(0), 2) AS pct_with_heading
FROM (
SELECT
_TABLE_SUFFIX AS client,
hasHeading(payload) AS has_heading
FROM
`httparchive.pages.2019_07_01_*`
)
FROM
(
SELECT
_TABLE_SUFFIX AS client,
hasHeading(payload) AS has_heading
FROM
`httparchive.pages.2019_07_01_*`
)
GROUP BY
client
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_02.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# 09_02: % of pages having minimum set of accessible elements
# Compliant pages have: header, footer, nav, and main (or [role=main]) elements
CREATE TEMPORARY FUNCTION getCompliantElements(payload STRING)
RETURNS ARRAY<STRING> LANGUAGE js AS '''
RETURNS ARRAY<STRING>
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var elements = JSON.parse($._element_count);
Expand Down
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_03.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# 09_03: % of pages having elements (see also 03_02a)
# For 09_12 we can invert the pct to get the % of pages with no h1
CREATE TEMPORARY FUNCTION getElements(payload STRING)
RETURNS ARRAY<STRING> LANGUAGE js AS '''
RETURNS ARRAY<STRING>
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var elements = JSON.parse($._element_count);
Expand Down
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_04.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_04: % of pages having more than one "main" landmark
CREATE TEMPORARY FUNCTION getMainCount(payload STRING)
RETURNS INT64 LANGUAGE js AS '''
RETURNS INT64
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var elements = JSON.parse($._element_count);
Expand Down
21 changes: 11 additions & 10 deletions sql/2019/accessibility/09_05b.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ SELECT
COUNT(0) AS total_sites,
COUNTIF(uses_roles) AS total_using_roles,
ROUND(COUNTIF(uses_roles) * 100 / COUNT(0), 2) AS perc_using_roles
FROM (
SELECT
client,
REGEXP_CONTAINS(body, r'role=[\'"]?([\w-]+)') AS uses_roles
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firstHtml
)
FROM
(
SELECT
client,
REGEXP_CONTAINS(body, r'role=[\'"]?([\w-]+)') AS uses_roles
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firstHtml
)
GROUP BY
client
38 changes: 20 additions & 18 deletions sql/2019/accessibility/09_06.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ SELECT
COUNT(DISTINCT page) AS pages,
total,
ROUND(COUNT(DISTINCT page) * 100 / total, 2) AS pct
FROM (
SELECT
client,
total,
page,
id,
COUNT(0) AS freq
FROM
(SELECT client, page, body FROM `httparchive.almanac.summary_response_bodies` WHERE date = '2019-07-01' AND firstHtml),
UNNEST(REGEXP_EXTRACT_ALL(body, '(?i)\\sid=[\'"]?([^\'"\\s]+)')) AS id
JOIN
(SELECT _TABLE_SUFFIX AS client, COUNT(0) AS total FROM `httparchive.pages.2019_07_01_*` GROUP BY _TABLE_SUFFIX)
USING (client)
GROUP BY
client,
total,
page,
id)
FROM
(
SELECT
client,
total,
page,
id,
COUNT(0) AS freq
FROM
(SELECT client, page, body FROM `httparchive.almanac.summary_response_bodies` WHERE date = '2019-07-01' AND firstHtml),
UNNEST(REGEXP_EXTRACT_ALL(body, '(?i)\\sid=[\'"]?([^\'"\\s]+)')) AS id
JOIN
(SELECT _TABLE_SUFFIX AS client, COUNT(0) AS total FROM `httparchive.pages.2019_07_01_*` GROUP BY _TABLE_SUFFIX)
USING (client)
GROUP BY
client,
total,
page,
id
)
WHERE
freq > 1
GROUP BY
Expand Down
18 changes: 11 additions & 7 deletions sql/2019/accessibility/09_07.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# 09_07: % of pages having a captions track when necessary
# Caveat: This does not necessarily enforce that the track is within the media element.
CREATE TEMPORARY FUNCTION getMediaElements(payload STRING)
RETURNS ARRAY<STRING> LANGUAGE js AS '''
RETURNS ARRAY<STRING>
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var elements = JSON.parse($._element_count);
Expand All @@ -19,12 +21,14 @@ SELECT
COUNTIF('track' IN UNNEST(media_elements)) AS freq,
COUNT(0) AS total,
ROUND(COUNTIF('track' IN UNNEST(media_elements)) * 100 / COUNT(0), 2) AS pct
FROM (
SELECT
_TABLE_SUFFIX AS client,
getMediaElements(payload) AS media_elements
FROM
`httparchive.pages.2019_07_01_*`)
FROM
(
SELECT
_TABLE_SUFFIX AS client,
getMediaElements(payload) AS media_elements
FROM
`httparchive.pages.2019_07_01_*`
)
WHERE
'audio' IN UNNEST(media_elements) OR
'video' IN UNNEST(media_elements)
Expand Down
14 changes: 8 additions & 6 deletions sql/2019/accessibility/09_08.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ SELECT
ROUND(COUNTIF(has_lang) * 100 / COUNT(0), 2) AS pct_has_of_total,
ROUND(COUNTIF(valid_lang) * 100 / COUNT(0), 2) AS pct_valid_of_total,
ROUND(COUNTIF(valid_lang) * 100 / COUNTIF(has_lang), 2) AS pct_valid_of_has
FROM (
SELECT
JSON_EXTRACT_SCALAR(report, "$.audits['html-has-lang'].score") = '1' AS has_lang,
JSON_EXTRACT_SCALAR(report, "$.audits['html-valid-lang'].score") = '1' AS valid_lang
FROM
`httparchive.lighthouse.2019_07_01_mobile`)
FROM
(
SELECT
JSON_EXTRACT_SCALAR(report, "$.audits['html-has-lang'].score") = '1' AS has_lang,
JSON_EXTRACT_SCALAR(report, "$.audits['html-valid-lang'].score") = '1' AS valid_lang
FROM
`httparchive.lighthouse.2019_07_01_mobile`
)
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_10.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_10: % of pages having skip links
CREATE TEMPORARY FUNCTION getEarlyHash(payload STRING)
RETURNS INT64 LANGUAGE js AS '''
RETURNS INT64
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var almanac = JSON.parse($._almanac);
Expand Down
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_11.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_11: % pages with headings that skip levels
CREATE TEMPORARY FUNCTION includesSkippedHeading(headings ARRAY<STRING>)
RETURNS BOOLEAN LANGUAGE js AS '''
RETURNS BOOLEAN
LANGUAGE js
AS '''
var previous = null;
for (h of headings) {
h = parseInt(h);
Expand Down
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_13.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_13: % pages with headings out of order
CREATE TEMPORARY FUNCTION includesUnorderedHeading(headings ARRAY<STRING>)
RETURNS BOOLEAN LANGUAGE js AS '''
RETURNS BOOLEAN
LANGUAGE js
AS '''
var previous = null;
var seen = new Set();
for (h of headings) {
Expand Down
32 changes: 21 additions & 11 deletions sql/2019/accessibility/09_14.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ SELECT
total,
ROUND(COUNTIF(aria_keyshortcuts) * 100 / total, 2) AS pct_aria_keyshortcuts,
ROUND(COUNTIF(accesskey) * 100 / total, 2) AS pct_accesskey
FROM (
SELECT
client,
REGEXP_CONTAINS(body, '(?i)<[^>]+aria-keyshortcuts=') AS aria_keyshortcuts,
REGEXP_CONTAINS(body, '(?i)<[^>]+accesskey=') AS accesskey
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firstHtml)
FROM
(
SELECT
client,
REGEXP_CONTAINS(body, '(?i)<[^>]+aria-keyshortcuts=') AS aria_keyshortcuts,
REGEXP_CONTAINS(body, '(?i)<[^>]+accesskey=') AS accesskey
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firstHtml
)
JOIN
(SELECT _TABLE_SUFFIX AS client, COUNT(0) AS total FROM `httparchive.pages.2019_07_01_*` GROUP BY _TABLE_SUFFIX)
(
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total
FROM
`httparchive.pages.2019_07_01_*`
GROUP BY
_TABLE_SUFFIX
)
USING (client)
GROUP BY
client,
Expand Down
36 changes: 22 additions & 14 deletions sql/2019/accessibility/09_15.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
#standardSQL
# 09_15: % pages using duplicate aria-keyshortcuts, accesskey attrs
CREATE TEMPORARY FUNCTION hasDuplicates(values ARRAY<STRING>)
RETURNS BOOLEAN LANGUAGE js AS '''
CREATE TEMPORARY FUNCTION HASDUPLICATES(values ARRAY<STRING>)
RETURNS BOOLEAN
LANGUAGE js
AS '''
return values.length != new Set(values).size;
''';

SELECT
client,
COUNTIF(hasDuplicates(aria_keyshortcuts)) AS freq_aria_keyshortcuts,
COUNTIF(hasDuplicates(accesskeys)) AS freq_accesskey
FROM (
SELECT
client,
REGEXP_EXTRACT_ALL(LOWER(body), '<[^>]+aria-keyshortcuts=[\'"]?([^\\s\'"]+)') AS aria_keyshortcuts,
REGEXP_EXTRACT_ALL(LOWER(body), '<[^>]+accesskey=[\'"]?([^\\s\'"]+)') AS accesskeys
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firstHtml)
COUNTIF(HASDUPLICATES(aria_keyshortcuts)) AS freq_aria_keyshortcuts,
COUNTIF(HASDUPLICATES(accesskeys)) AS freq_accesskey
FROM
(
SELECT
client,
REGEXP_EXTRACT_ALL(
LOWER(body), '<[^>]+aria-keyshortcuts=[\'"]?([^\\s\'"]+)'
) AS aria_keyshortcuts,
REGEXP_EXTRACT_ALL(
LOWER(body), '<[^>]+accesskey=[\'"]?([^\\s\'"]+)'
) AS accesskeys
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firsthtml
)
GROUP BY
client
31 changes: 17 additions & 14 deletions sql/2019/accessibility/09_16b.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_16b: % page with forms using invalid/required
CREATE TEMPORARY FUNCTION getTotalInputsUsed(payload STRING)
RETURNS INT64 LANGUAGE js AS '''
RETURNS INT64
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
if (!$._element_count) {
Expand Down Expand Up @@ -33,19 +35,20 @@ SELECT
ROUND(COUNTIF(uses_aria_required) * 100 / COUNTIF(total_inputs > 0), 2) AS perc_applicable_aria_required,
ROUND(COUNTIF(uses_required) * 100 / COUNTIF(total_inputs > 0), 2) AS perc_applicable_required,
ROUND(COUNTIF(uses_aria_required OR uses_required) * 100 / COUNTIF(total_inputs > 0), 2) AS perc_applicable_either_required
FROM (
SELECT
client,
page,
REGEXP_CONTAINS(body, '<input[^>]+aria-invalid\\b') AS uses_aria_invalid,
REGEXP_CONTAINS(body, '<input[^>]+(aria-required)\\b') AS uses_aria_required,
REGEXP_CONTAINS(body, '<input[^>]+[^-](required)\\b') AS uses_required
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firstHtml
)
FROM
(
SELECT
client,
page,
REGEXP_CONTAINS(body, '<input[^>]+aria-invalid\\b') AS uses_aria_invalid,
REGEXP_CONTAINS(body, '<input[^>]+(aria-required)\\b') AS uses_aria_required,
REGEXP_CONTAINS(body, '<input[^>]+[^-](required)\\b') AS uses_required
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
date = '2019-07-01' AND
firstHtml
)
JOIN (
SELECT
_TABLE_SUFFIX AS client,
Expand Down
4 changes: 3 additions & 1 deletion sql/2019/accessibility/09_17.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#standardSQL
# 09_17: % pages using tables with headings
CREATE TEMPORARY FUNCTION getTableInfo(payload STRING)
RETURNS STRUCT<has_table BOOLEAN, has_th BOOLEAN> LANGUAGE js AS '''
RETURNS STRUCT<has_table BOOLEAN, has_th BOOLEAN>
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var elements = JSON.parse($._element_count);
Expand Down
Loading