Пример #1
0
        public static async ValueTask <ServerErrorMessage> Read(ClickHouseBinaryProtocolReader reader, bool async, CancellationToken cancellationToken)
        {
            var errorCode = await reader.ReadInt32(async, cancellationToken);

            var name = await reader.ReadString(async, cancellationToken);

            var errorMessage = await reader.ReadString(async, cancellationToken);

            var stackTrace = await reader.ReadString(async, cancellationToken);

            bool hasNested = await reader.ReadBool(async, cancellationToken);

            ClickHouseServerException exception;

            if (hasNested)
            {
                var nested = await Read(reader, async, cancellationToken);

                exception = new ClickHouseServerException(errorCode, name, errorMessage, stackTrace, nested.Exception);
            }
            else
            {
                exception = new ClickHouseServerException(errorCode, name, errorMessage, stackTrace);
            }

            return(new ServerErrorMessage(exception));
        }
Пример #2
0
        public static async Task <ServerHelloMessage> Read(ClickHouseBinaryProtocolReader reader, bool async, CancellationToken cancellationToken)
        {
            var serverName = await reader.ReadString(async, cancellationToken);

            var mj = await reader.Read7BitInt32(async, cancellationToken);

            var mr = await reader.Read7BitInt32(async, cancellationToken);

            var rv = await reader.Read7BitInt32(async, cancellationToken);

            if (rv < ClickHouseProtocolRevisions.MinSupportedRevision)
            {
                throw new ClickHouseException(
                          ClickHouseErrorCodes.ProtocolRevisionNotSupported,
                          $"The revision {rv} of ClickHouse server is not supported. Minimal supported revision is {ClickHouseProtocolRevisions.MinSupportedRevision}.");
            }

            var tz = await reader.ReadString(async, cancellationToken);

            var displayName = await reader.ReadString(async, cancellationToken);

            var b = await reader.ReadByte(async, cancellationToken);

            var serverVersion = new ClickHouseVersion(mj, mr, b);

            var serverInfo = new ClickHouseServerInfo(serverName, serverVersion, rv, tz, displayName);

            return(new ServerHelloMessage(serverInfo));
        }
Пример #3
0
            public SequenceSize ReadNext(ReadOnlySequence <byte> sequence)
            {
                if (_layouts.Count >= _rowCount)
                {
                    throw new ClickHouseException(ClickHouseErrorCodes.DataReaderError, "Internal error. Attempt to read after the end of the column.");
                }

                int expectedElementsCount = _rowCount - _layouts.Count;
                int elementsCount = 0, bytesCount = 0;

                while (elementsCount < expectedElementsCount)
                {
                    var slice = sequence.Slice(bytesCount);
                    if (!ClickHouseBinaryProtocolReader.TryRead7BitInteger(slice, out var longSize, out var bytesRead))
                    {
                        break;
                    }

                    var size = (int)longSize;
                    if (slice.Length - bytesRead < size)
                    {
                        break;
                    }

                    if (size == 0)
                    {
                        _layouts.Add((0, 0, 0));
                    }
                    else
                    {
                        var lastSegment = _segments.Count == 0 ? default : _segments[^ 1];
Пример #4
0
        public static async ValueTask <ServerTableColumnsMessage> Read(ClickHouseBinaryProtocolReader reader, bool async, CancellationToken cancellationToken)
        {
            await reader.ReadString(async, cancellationToken);

            var columns = await reader.ReadString(async, cancellationToken);

            return(new ServerTableColumnsMessage(columns));
        }
Пример #5
0
        public static async ValueTask <ServerDataMessage> Read(ClickHouseBinaryProtocolReader reader, ServerMessageCode messageCode, bool async, CancellationToken cancellationToken)
        {
            string?tempTableName = await reader.ReadString(async, cancellationToken);

            if (tempTableName == string.Empty)
            {
                tempTableName = null;
            }

            return(new ServerDataMessage(messageCode, tempTableName));
        }
Пример #6
0
        public static async ValueTask <ServerProgressMessage> Read(ClickHouseBinaryProtocolReader reader, bool async, CancellationToken cancellationToken)
        {
            int rows = await reader.Read7BitInt32(async, cancellationToken);

            int bytes = await reader.Read7BitInt32(async, cancellationToken);

            int totals = await reader.Read7BitInt32(async, cancellationToken);

            int writtenRows = await reader.Read7BitInt32(async, cancellationToken);

            int writtenBytes = await reader.Read7BitInt32(async, cancellationToken);

            return(new ServerProgressMessage(rows, bytes, totals, writtenRows, writtenBytes));
        }
        public static async ValueTask <ServerProfileInfoMessage> Read(ClickHouseBinaryProtocolReader reader, bool async, CancellationToken cancellationToken)
        {
            ulong rows = await reader.Read7BitUInt64(async, cancellationToken);

            ulong blocks = await reader.Read7BitUInt64(async, cancellationToken);

            ulong bytes = await reader.Read7BitUInt64(async, cancellationToken);

            bool limitApplied = await reader.ReadBool(async, cancellationToken);

            ulong rowsBeforeLimit = await reader.Read7BitUInt64(async, cancellationToken);

            bool calculatedRowsBeforeLimit = await reader.ReadBool(async, cancellationToken);

            return(new ServerProfileInfoMessage(rows, blocks, bytes, limitApplied, rowsBeforeLimit, calculatedRowsBeforeLimit));
        }