drop view if exists otel.otel_traces on cluster default sync;
create view if not exists otel.otel_traces on cluster default as
select Timestamp,
       TraceId,
       SpanId,
       ParentSpanId,
       TraceState,
       SpanName,
       multiIf(SpanKind=1, 'SPAN_KIND_INTERNAL',
           SpanKind=2, 'SPAN_KIND_SERVER',
               SpanKind=3, 'SPAN_KIND_CLIENT',
               SpanKind=4, 'SPAN_KIND_PRODUCER',
               SpanKind=5, 'SPAN_KIND_CONSUMER',
               'SPAN_KIND_UNSPECIFIED') as SpanKind,
       ServiceName,
       ResourceAttributes,
       SpanAttributes,
       ScopeName,
       ScopeVersion,
       Duration,
       multiIf(StatusCode=0, 'STATUS_CODE_UNSET',
               StatusCode=1, 'STATUS_CODE_OK',
               StatusCode=2, 'STATUS_CODE_ERROR',
               'UNKNOWN') as StatusCode,
       StatusMessage,
       `Events.Timestamp`,
       `Events.Name`,
       `Events.Attributes`,
       `Links.TraceId`,
       `Links.SpanId`,
       `Links.TraceState`,
       `Links.Attributes`,
       HttpCode,
       HttpMethod,
       HttpURL,
       ContainerId,
       srcIP,
       srcPort,
       targetIP,
       targetPort,
       RPCName,
       dbStatement,
       dbConnectionString,
       AppAlias
from otel.traces;
