Skip to content

Add support for JSON type options#309

Merged
ruslandoga merged 2 commits intoplausible:masterfrom
JVMartyns:feat/accept_json_with_settings
Apr 20, 2026
Merged

Add support for JSON type options#309
ruslandoga merged 2 commits intoplausible:masterfrom
JVMartyns:feat/accept_json_with_settings

Conversation

@JVMartyns
Copy link
Copy Markdown
Contributor

@JVMartyns JVMartyns commented Apr 16, 2026

Parse JSON(...) options into {:json, opts} with settings, type_hints and skips, and encode them back to "JSON(...)". Handle {:json, opts} in Ch.Types, Ch.RowBinary (encode/decoding) and Ch.cast. Add tests covering settings, type hints and skip directives for RowBinary insertion.

#308

Parse JSON(...) options into {:json, opts} with settings,
type_hints and skips, and encode them back to "JSON(...)".
Handle {:json, opts} in Ch.Types, Ch.RowBinary (encode/decoding)
and Ch.cast. Add tests covering settings, type hints and skip
directives for RowBinary insertion.
Comment thread lib/ch/types.ex Outdated
def decode("JSON" <> _options), do: :json

def decode("JSON" <> options) do
case String.trim(options) do
Copy link
Copy Markdown
Collaborator

@ruslandoga ruslandoga Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @JVMartyns

Thank you for the PR!

Since we are not using these options, maybe we can keep them as-is, as a string, with trailing ) trimmed?

Copy link
Copy Markdown
Contributor Author

@JVMartyns JVMartyns Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to fix the line breaks and sort the type hints.

{
  :error,
  %Ch.Error{
    __exception__: true,
    code: 117,
    message: "Code: 117. DB::Exception: Type of 'json' must be JSON(max_dynamic_types=254, max_dynamic_paths=10000, age UInt8, name String, SKIP `pass.body_part`, SKIP REGEXP 't.*'), not JSON(\n  max_dynamic_types=254,\n  max_dynamic_paths=10000,\n  age UInt8, name String,\n  SKIP `pass.body_part`,\n  SKIP REGEXP 't.*'\n)\n: (while reading header): While executing WaitForAsyncInsert. (INCORRECT_DATA) (version 26.3.3.20 (official build))\n"
  }
}

Simplify parsing of JSON(...) options by trimming and splitting in a
single pipeline, removing the earlier case branch while keeping the
{:json, ...} result shape.

Add unit tests covering JSON decoding, the json helper and encode
roundtrip for various option combinations.
@JVMartyns JVMartyns requested a review from ruslandoga April 20, 2026 11:25
@ruslandoga
Copy link
Copy Markdown
Collaborator

Thank you!

@ruslandoga ruslandoga merged commit a1f1ead into plausible:master Apr 20, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants