Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riR7d-00H8xr-N8 for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Mar 2024 03:42:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1riR7c-009t0O-1H for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Mar 2024 03:42:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riR7b-009t0F-Kv for pgsql-hackers@lists.postgresql.org; Fri, 08 Mar 2024 03:42:12 +0000 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1riR7X-003Pn8-LX for pgsql-hackers@lists.postgresql.org; Fri, 08 Mar 2024 03:42:10 +0000 Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-78822adc835so91106785a.3 for ; Thu, 07 Mar 2024 19:42:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1709869327; x=1710474127; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=5nvdLCarBpCLSG5ucJmN/+W6iVtnH8G0ULahjhHQOjQ=; b=aFJDC4ZTKRf3aBHvcsaPi7YTXX0ZaFcxHO1IYOElFTq+8910ZxBPQyjM54jY/oXHOU gDujSCdgQv1WlZP0axoejN2MximGK0ZBRqs22pBXZvidE4tfW9472Nx+hJ4rEMvUEhdp mnTEwosWhgWYl4NLwjMmdevCBulS+xbtsydXEPwEho7QULfKZsMZpI+YmypGHler5Pjb V6Qfisj3QQ4JG1TQmQr9125b74e5tvpKvildMcMJOQMvAImwKJdgnOA5U2tuxN0Bc4Fe dhSc1Kamsk4DVltrIcgbzXJ3aXQ28UEVF0rBaIp2svoOyCJg0bmoIfAWy2b/5wRywq3w i4pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709869327; x=1710474127; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5nvdLCarBpCLSG5ucJmN/+W6iVtnH8G0ULahjhHQOjQ=; b=POKPHKK2b5LXzM/8MaXa1+O/XvrWAvPPDr8gRtG+su2iR4IV6XCyFQUB5LnSTjWAOl Rx9+UzjcWN8zqxPy7HyAmH902ZfGrtWEAGUV7j6zSBmG59nVPNJgBt+rrAsjVR5G1AgL V7ywvAAj9CWptYcADCuRLvgJm17MxB5YFSZ32jKv+lHtFbMaKTIcARD/WJqczJ6LAyHS gyDT3bccTq2FxMSOEjt90764SJmImPXJW/T/5iivscuZiOkzHSgDkK99MlzGfTQUL/FQ k8wewwrMcHuvbWImMLd8HIBrC7OPKjKrybSUGAS6o/80Y2QCyM5eyF48Y2DTnIwPoDj9 A/bA== X-Forwarded-Encrypted: i=1; AJvYcCXt/2G4E1WIlLBMS9G8N9GkMUZQEK9G76zVdRQmx7w8u2IQW9Ksvid48FzLKO7gXrkXR2PcWf+z2vHmwq0alBkWdwoOqtgzVviDPcsM/FbD/tbL X-Gm-Message-State: AOJu0Ywa1+67Wfjgvooj//DIfBcksDSaSCfi35o70H7hBQNK++2+eIFx kigy0ytkV+BhDtGP9xMkLGICksw5kzu3rl3KFAmA7TTDc6ZBoY+LCcdaeO5wWt8= X-Google-Smtp-Source: AGHT+IGx53GSLAlynUZOunCCeF07jNcNKSZKZDjeZ0ymRhMbb0BVQA/98ji5QmKKNc29NPtBd2sFsQ== X-Received: by 2002:a05:620a:1598:b0:788:2b1c:1e4c with SMTP id d24-20020a05620a159800b007882b1c1e4cmr8890341qkk.10.1709869327307; Thu, 07 Mar 2024 19:42:07 -0800 (PST) Received: from ?IPV6:2605:a601:91f3:1900::2bb? ([2605:a601:91f3:1900::2bb]) by smtp.googlemail.com with ESMTPSA id ay12-20020a05620a178c00b007884435812csm1689231qkb.54.2024.03.07.19.42.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 19:42:06 -0800 (PST) Message-ID: <682c8fff-355c-a04f-57ac-81055c4ccda8@dunslane.net> Date: Thu, 7 Mar 2024 22:42:06 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: Jacob Champion Cc: Robert Haas , Peter Smith , PostgreSQL Hackers References: <7b0a51d6-0d9d-7366-3a1a-f74397a02f55@dunslane.net> <99332c8b-0bea-1ef4-efa6-406635eb34b7@dunslane.net> <8cc158a4-5d51-737c-16a1-8885d04e4cab@dunslane.net> <3892d996-0ec8-3a56-1a6c-b397a3c31516@dunslane.net> <3efe8333-3285-1d9d-5ad3-0f9784d5c1c4@dunslane.net> <1778cdac-bb93-5bbd-1505-5684e95b0094@dunslane.net> <1b30469a-9d29-c021-f28a-74e248760aa4@dunslane.net> From: Andrew Dunstan Subject: Re: WIP Incremental JSON Parser In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-03-07 Th 10:28, Jacob Champion wrote: > Some more observations as I make my way through the patch: > > In src/common/jsonapi.c, > >> +#define JSON_NUM_NONTERMINALS 6 > Should this be 5 now? Yep. > >> + res = pg_parse_json_incremental(&(incstate->lex), &(incstate->sem), >> + chunk, size, is_last); >> + >> + expected = is_last ? JSON_SUCCESS : JSON_INCOMPLETE; >> + >> + if (res != expected) >> + json_manifest_parse_failure(context, "parsing failed"); > This leads to error messages like > > pg_verifybackup: error: could not parse backup manifest: parsing failed > > which I would imagine is going to lead to confused support requests in > the event that someone does manage to corrupt their manifest. Can we > make use of json_errdetail() and print the line and column numbers? > Patch 0001 over at [1] has one approach to making json_errdetail() > workable in frontend code. Looks sound on a first look. Maybe we should get that pushed ASAP so we can take advantage of it. > > Top-level scalars like `false` or `12345` do not parse correctly if > the chunk size is too small; instead json_errdetail() reports 'Token > "" is invalid'. With small chunk sizes, json_errdetail() additionally > segfaults on constructions like `[tru]` or `12zz`. Ugh. Will investigate. > > For my local testing, I'm carrying the following diff in > 001_test_json_parser_incremental.pl: > >> - ok($stdout =~ /SUCCESS/, "chunk size $size: test succeeds"); >> - ok(!$stderr, "chunk size $size: no error output"); >> + like($stdout, qr/SUCCESS/, "chunk size $size: test succeeds"); >> + is($stderr, "", "chunk size $size: no error output"); > This is particularly helpful when a test fails spuriously due to code > coverage spray on stderr. > Makes sense, thanks. I'll have a fresh patch set soon which will also take care of the bitrot. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com