Чтобы настроить мониторинг, я пытаюсь получить длительность вызова определенного файла, объединить эти данные и передать их в графану, но мой запрос продолжает давать сбой по странной причине, хотя я дважды проверил все, что яМогуcode:
select created,
useragent,
position('"pathname":"/api/player/screenName' in resource) as pos1,
right( resource, len(resource) - pos1) as pathname_start_string,
position(',{' in pathname_start_string) as pos2,
left (pathname_start_string, pos2-1) as pathname_tail,
concat(left (resource, pos1 + pos2 - 1), ']') as string3,
json_array_length(string3) as arr_len,
json_extract_array_element_text ( string3 , arr_len-1) as commons_element,
is_valid_json(commons_element) as "test"
from prodloadtimes
where resource like '%"pathname":"/api/player/screenName"%'
and created between '2018-12-01' and '2018-12-18 12:00'
and pos2 > 0
Итак, в основном я нахожу необходимый элемент в массиве, вырезаю все последующие элементы, поэтому мне нужен последний, а затем извлекаю этот элемент с помощью функции json_extract_array_element_text (string3, arr_len-1)
Теперь этот код, который я использую для извлечения необходимых мне данных:
select created,
useragent,
json_extract_path_text(commons_element,'duration') as duration,
json_extract_path_text(commons_element,'transferSize') as transfersize,
json_extract_path_text(commons_element,'name', 'pathname') as pathname,
json_extract_path_text(commons_element,'encodedBodySize') as size,
commons_element,
is_valid_json(commons_element) as "test"
from (
select created,
useragent,
position('"pathname":"/api/player/screenName' in resource) as pos1,
right( resource, len(resource) - pos1) as pathname_start_string,
position(',{' in pathname_start_string) as pos2,
left (pathname_start_string, pos2-1) as pathname_tail,
concat(left (resource, pos1 + pos2 - 1), ']') as string3,
json_array_length(string3) as arr_len,
json_extract_array_element_text ( string3 , arr_len-1) as commons_element,
is_valid_json(commons_element) as "test"
from prodloadtimes
where resource like '%"pathname":"/api/player/screenName"%'
and created between '2018-12-01' and '2018-12-18 12:00'
and pos2 > 0
)
where transfersize > 0
and duration > 0)
И он работает просто отлично, но когда я пытаюсь сделать процентили для этих данных с этим:
select floor(extract(epoch from created)/900)*900 AS "time",
percentile_cont(0.5) within group (order by cast(duration as float4) asc) AS "50th",
percentile_cont(0.75) within group (order by cast(duration as float4) asc) AS "75th",
percentile_cont(0.95) within group (order by cast(duration as float4) asc) AS "95th"
from (
select created,
useragent,
json_extract_path_text(commons_element,'duration') as duration,
json_extract_path_text(commons_element,'transferSize') as transfersize,
json_extract_path_text(commons_element,'name', 'pathname') as pathname,
json_extract_path_text(commons_element,'encodedBodySize') as size,
commons_element,
is_valid_json(commons_element) as "test"
from (
select created,
useragent,
position('"pathname":"/api/player/screenName' in resource) as pos1,
right( resource, len(resource) - pos1) as pathname_start_string,
position(',{' in pathname_start_string) as pos2,
left (pathname_start_string, pos2-1) as pathname_tail,
concat(left (resource, pos1 + pos2 - 1), ']') as string3,
json_array_length(string3) as arr_len,
json_extract_array_element_text ( string3 , arr_len-1) as commons_element,
is_valid_json(commons_element) as "test"
from prodloadtimes
where resource like '%"pathname":"/api/player/screenName"%'
and created between '2018-12-01' and '2018-12-18 12:00'
and pos2 > 0
)
where transfersize > 0
and duration > 0)
group by "time"
Redshift отвечает с ошибкой
Недопустимая операция Amazon: ошибка синтаксического анализа JSON Подробности:
ошибка: код ошибки синтаксического анализа JSON: 8001 контекст: недопустимый объект массива json
Я не понимаю, как этот commons_element
может быть недопустимым объектом JSON, учитывая, что это вывод встроенной функции json_extract_array_element_text
, поэтому любые советы будут оценены.
PS Я знаю, что это немного грязный подход, в котором все эти встроенные выборки, но это больше похоже на версию разработки, которую я сделал шаг за шагом, и я думал, что она будет работать.