Skip to content

Hanging request extracting data from CL OLAP YDB #18802

Open
@vitalyisaev2

Description

@vitalyisaev2

This request cannot be completed in a reasonable time:

IAM_TOKEN=$(yc --profile preprod-fed-user iam create-token) ydb \
   --endpoint "u-lb.cc8jliaf18k2b9ae2bio.ydb.mdb.cloud-preprod.yandex.net:2135" \
   --database "/pre-prod_vla/yc.logs.cloud/cc8jliaf18k2b9ae2bio" \
   sql -f query.sql -i parameters.json --format=csv > ~/troubles/YQ-2614/dump.csv 2>&1

query.sql:

DECLARE $p0 AS Timestamp;
DECLARE $p1 AS Timestamp;

$build_labels = ($j) -> {
	$y = Yson::ParseJson(CAST ($j as STRING));
	$a = DictItems(Yson::ConvertToDict($y));
	$f = ListFilter($a, ($x) -> { return StartsWith($x.0, "labels.") });
	$g = ListMap($f, ($x) -> { return (substring($x.0, 7), $x.1) });
	return Yson::SerializeJson(Yson::From(ToDict($g)));
};

$build_pure_meta = ($j) -> {
	$y = Yson::ParseJson(CAST ($j as STRING));
	$a = DictItems(Yson::ConvertToDict($y));
	$f = ListFilter($a, ($x) -> { return StartsWith($x.0, "meta.")});
	$g = ListMap($f, ($x) -> { return (substring($x.0, 5), $x.1) });
    return $g;
};

$hostname_keys = AsList(
    "host", "hostname", "host.name"
);

$trace_id_keys = AsList(
    "trace.id", "trace_id", "traceId", "traceID",
);

$span_id_keys = AsList(
    "span.id", "span_id", "spanId", "spanID",
);

$excluded_from_meta = ListExtend(
    $hostname_keys,
    $trace_id_keys,
    $span_id_keys
);

$build_other_meta = ($j) -> {
	$y = Yson::ParseJson(CAST ($j as STRING));
	$a = DictItems(Yson::ConvertToDict($y));
	$f = ListFilter($a, ($x) -> { 
        return 
            NOT StartsWith($x.0, "labels.") 
                AND 
            NOT StartsWith($x.0, "meta.")
                AND
            $x.0 NOT IN $excluded_from_meta
    });
	$g = ListMap($f, ($x) -> { return ($x.0, $x.1) });
    return $g;
};

$build_meta = ($j) -> {
    $pure = $build_pure_meta($j);
    $other = $build_other_meta($j);
    return Yson::SerializeJson(Yson::From(ToDict(ListExtend($pure, $other))));
};

$build_hostname = ($j) -> {
    $y = Yson::ParseJson(CAST ($j as STRING));
	$a = DictItems(Yson::ConvertToDict($y));
	$f = ListFilter($a, ($x) -> { return $x.0 IN $hostname_keys });
    return CAST(Yson::ConvertToString($f[0].1) AS Utf8);
};

$build_span_id = ($j) -> {
    $y = Yson::ParseJson(CAST ($j as STRING));
	$a = DictItems(Yson::ConvertToDict($y));
	$f = ListFilter($a, ($x) -> { return $x.0 IN $span_id_keys });
    return CAST(Yson::ConvertToString($f[0].1) AS Utf8);
};

$build_trace_id = ($j) -> {
    $y = Yson::ParseJson(CAST ($j as STRING));
	$a = DictItems(Yson::ConvertToDict($y));
	$f = ListFilter($a, ($x) -> { return $x.0 IN $trace_id_keys });
    return CAST(Yson::ConvertToString($f[0].1) AS Utf8);
};

$build_level = ($src) -> {
    RETURN CAST(
        CASE $src
            WHEN 1 THEN "TRACE"
            WHEN 2 THEN "DEBUG"
            WHEN 3 THEN "INFO"
            WHEN 4 THEN "WARN"
            WHEN 5 THEN "ERROR"
            WHEN 6 THEN "FATAL"
            ELSE "UNKNOWN"
        END AS Utf8
    );
};

SELECT 
  CAST("aoe3cidh5dfee2s6cqu5" AS Utf8) AS cluster, 
  $build_hostname(json_payload) AS hostname, 
  json_payload, 
  $build_labels(json_payload) AS labels, 
  $build_level(level) AS level, 
  message, 
  CAST("aoeoqusjtbo4m549jrom" AS Utf8) AS project, 
  CAST("af3731rdp83d8gd8fjcv" AS Utf8) AS service, 
  $build_span_id(json_payload) AS span_id, 
  timestamp, 
  $build_trace_id(json_payload) AS trace_id 
FROM 
  `logs/origin/aoeoqusjtbo4m549jrom/aoe3cidh5dfee2s6cqu5/af3731rdp83d8gd8fjcv` WITH TabletId = '72075186234644932' 
WHERE 
  (
    COALESCE(
      (`timestamp` >= $p0), 
      false
    ) 
    AND COALESCE(
      (`timestamp` < $p1), 
      false
    )
  )

parameters.json (please don't forget to refresh the dates while reproducing):

{
	"p0": "2025-05-24T16:00:00Z",
	"p1": "2025-05-25T16:00:00Z"
}

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions