Skip to content

Add aggregate functions distinctDynamicTypes/distinctJSONPaths/distinctJSONPathsAndTypes#68463

Merged
Avogar merged 16 commits intoClickHouse:masterfrom
Avogar:dynamic-json-distinct-aggregate-functions
Sep 3, 2024
Merged

Add aggregate functions distinctDynamicTypes/distinctJSONPaths/distinctJSONPathsAndTypes#68463
Avogar merged 16 commits intoClickHouse:masterfrom
Avogar:dynamic-json-distinct-aggregate-functions

Conversation

@Avogar
Copy link
Copy Markdown
Member

@Avogar Avogar commented Aug 16, 2024

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Add aggregate functions distinctDynamicTypes/distinctJSONPaths/distinctJSONPathsAndTypes for better introspection of JSON column type content

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Run only fuzzers related jobs (libFuzzer fuzzers, AST fuzzers, etc.)
  • Exclude: AST fuzzers

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@Avogar Avogar mentioned this pull request Aug 16, 2024
56 tasks
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-feature Pull request with new product feature label Aug 16, 2024
@robot-ch-test-poll1
Copy link
Copy Markdown
Contributor

robot-ch-test-poll1 commented Aug 16, 2024

This is an automated comment for commit ed2da41 with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@antaljanosbenjamin antaljanosbenjamin self-assigned this Aug 28, 2024
@Avogar
Copy link
Copy Markdown
Member Author

Avogar commented Aug 29, 2024

Stateless tests (asan) [2/2] — Job failed, exit code: 210. Server died, fail: 14, passed: 2213, skipped: 33

#67606

@Avogar Avogar added this pull request to the merge queue Sep 3, 2024
Merged via the queue into ClickHouse:master with commit 17baa4f Sep 3, 2024
@Avogar Avogar deleted the dynamic-json-distinct-aggregate-functions branch September 3, 2024 18:27
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 3, 2024
@nakulogale
Copy link
Copy Markdown

nakulogale commented Sep 23, 2024

Hello,
I was trying to add an index to my JSON data type using distinctJSONPaths(json).
Table definition is

CREATE TABLE test
(
    `ingest_timestamp` DateTime64(3) CODEC(Delta(8), ZSTD(1)),
    `fields` Map(LowCardinality(String), String) CODEC(ZSTD(1)),
    `json` JSON, 
    INDEX idx_log_fields_key mapKeys(fields) TYPE bloom_filter(0.01) GRANULARITY 1,
    INDEX idx_log_fields_value mapValues(fields) TYPE bloom_filter(0.01) GRANULARITY 1,
    INDEX idx_text lower(text) TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1
)
ENGINE = MergeTree
PARTITION BY toDate(ingest_timestamp)
ORDER BY ( toUnixTimestamp64Milli(ingest_timestamp))
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1 

Trying to add it so,
alter table test add index idx_json_paths distinctJSONPaths(json) TYPE bloom_filter(0.01) GRANULARITY 1;

Exception Trace:
`

2024.09.23 11:00:41.951108 [ 8781811 ] {query_id} executeQuery: (from [::1]:59855) alter table test add index idx_json_paths distinctJSONPaths(json) TYPE bloom_filter(0.01) GRANULARITY 1; (stage: Complete)
2024.09.23 11:00:41.951858 [ 8781811 ] {query_id} executeQuery: Code: 184. DB::Exception: Aggregate function distinctJSONPaths(json) is found in wrong place in query: While processing distinctJSONPaths(json). (ILLEGAL_AGGREGATION) (version 24.9.1.3018 (official build)) (from [::1]:59855) (in query: alter table test add index idx_json_paths distinctJSONPaths(json) TYPE bloom_filter(0.01) GRANULARITY 1;), Stack trace (when copying this message, always include the lines below):

  1. Poco::Exception::Exception(String const&, int) @ 0x000000011258513d
  2. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000010b6aa95f
  3. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000106acb034
  4. DB::Exception::Exception<String, String>(int, FormatStringHelperImpl<std::type_identity::type, std::type_identity::type>, String&&, String&&) @ 0x0000000106acc66f
  5. DB::GetAggregatesMatcher::visit(DB::ASTFunction const&, std::shared_ptrDB::IAST const&, DB::GetAggregatesMatcher::Data&) @ 0x000000010f5d4564
  6. DB::InDepthNodeVisitor<DB::GetAggregatesMatcher, true, false, std::shared_ptrDB::IAST const>::doVisit(std::shared_ptrDB::IAST const&) @ 0x000000010f5d41cd
  7. void DB::InDepthNodeVisitor<DB::GetAggregatesMatcher, true, false, std::shared_ptrDB::IAST const>::visitChildren(std::shared_ptrDB::IAST const&) @ 0x000000010f5d4839
  8. DB::TreeRewriter::analyze(std::shared_ptrDB::IAST&, DB::NamesAndTypesList const&, std::shared_ptr<DB::IStorage const>, std::shared_ptrDB::StorageSnapshot const&, bool, bool, bool, bool) const @ 0x000000010f9df059
  9. DB::IndexDescription::getIndexFromAST(std::shared_ptrDB::IAST const&, DB::ColumnsDescription const&, std::shared_ptr<DB::Context const>) @ 0x0000000110224551
  10. DB::AlterCommand::apply(DB::StorageInMemoryMetadata&, std::shared_ptr<DB::Context const>) const @ 0x00000001101dbeff
  11. DB::AlterCommands::apply(DB::StorageInMemoryMetadata&, std::shared_ptr<DB::Context const>) const @ 0x00000001101e0241
  12. DB::MergeTreeData::checkAlterIsPossible(DB::AlterCommands const&, std::shared_ptr<DB::Context const>) const @ 0x000000011073bfb4
  13. DB::InterpreterAlterQuery::executeToTable(DB::ASTAlterQuery const&) @ 0x000000010f625542
  14. DB::InterpreterAlterQuery::execute() @ 0x000000010f6236b1
  15. DB::executeQueryImpl(char const*, char const*, std::shared_ptrDB::Context, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x000000010fa3a8e8
  16. DB::executeQuery(String const&, std::shared_ptrDB::Context, DB::QueryFlags, DB::QueryProcessingStage::Enum) @ 0x000000010fa370b8
  17. DB::TCPHandler::runImpl() @ 0x0000000110c696cc
  18. DB::TCPHandler::run() @ 0x0000000110c81b1c
  19. Poco::Net::TCPServerConnection::start() @ 0x0000000112636e6c
  20. Poco::Net::TCPServerDispatcher::run() @ 0x00000001126373de
  21. Poco::PooledThread::run() @ 0x00000001125e1292
  22. Poco::ThreadImpl::runnableEntry(void*) @ 0x00000001125dea41
  23. _pthread_start @ 0x00007ff81af8918b
  24. thread_start @ 0x00007ff81af84ae3

Elapsed: 0.002 sec.

Received exception from server (version 24.9.1):
Code: 184. DB::Exception: Received from DB::Exception: Aggregate function distinctJSONPaths(json) is found in wrong place in query: While processing distinctJSONPaths(json). (ILLEGAL_AGGREGATION)

`

Is there something fundamentally wrong the way I am using the aggregate 'distinctJSONPaths' function?
Is this an expected error?

I wish to create a similar index as created for the fields value.

@Avogar
Copy link
Copy Markdown
Member Author

Avogar commented Sep 23, 2024

Is there something fundamentally wrong the way I am using the aggregate 'distinctJSONPaths' function?
Is this an expected error?

Yes, it's expected. You cannot use aggregate functions in the INDEX expressions. You can use usual functions. For JSON you can use function JSONAllPaths that returns the list of paths stored in each row

@nakulogale
Copy link
Copy Markdown

Is there something fundamentally wrong the way I am using the aggregate 'distinctJSONPaths' function?
Is this an expected error?

Yes, it's expected. You cannot use aggregate functions in the INDEX expressions. You can use usual functions. For JSON you can use function JSONAllPaths that returns the list of paths stored in each row

Thank you, JSONAllPaths worked.

@nakulogale
Copy link
Copy Markdown

Is there any function which can extract Values from a JSON/ string containing JSON ?
Something similar to 'JSONExtractKeys' function, say JSONExtractValues().
In continuation to the quoted scenario, I wish to create an index on both, JSON paths and the values.

Hello, I was trying to add an index to my JSON data type using distinctJSONPaths(json). Table definition is

CREATE TABLE test
(
    `ingest_timestamp` DateTime64(3) CODEC(Delta(8), ZSTD(1)),
    `fields` Map(LowCardinality(String), String) CODEC(ZSTD(1)),
    `json` JSON, 
    INDEX idx_log_fields_key mapKeys(fields) TYPE bloom_filter(0.01) GRANULARITY 1,
    INDEX idx_log_fields_value mapValues(fields) TYPE bloom_filter(0.01) GRANULARITY 1,
    INDEX idx_text lower(text) TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1
)
ENGINE = MergeTree
PARTITION BY toDate(ingest_timestamp)
ORDER BY ( toUnixTimestamp64Milli(ingest_timestamp))
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1 

Trying to add it so, alter table test add index idx_json_paths distinctJSONPaths(json) TYPE bloom_filter(0.01) GRANULARITY 1;

Exception Trace: `

2024.09.23 11:00:41.951108 [ 8781811 ] {query_id} executeQuery: (from [::1]:59855) alter table test add index idx_json_paths distinctJSONPaths(json) TYPE bloom_filter(0.01) GRANULARITY 1; (stage: Complete)
2024.09.23 11:00:41.951858 [ 8781811 ] {query_id} executeQuery: Code: 184. DB::Exception: Aggregate function distinctJSONPaths(json) is found in wrong place in query: While processing distinctJSONPaths(json). (ILLEGAL_AGGREGATION) (version 24.9.1.3018 (official build)) (from [::1]:59855) (in query: alter table test add index idx_json_paths distinctJSONPaths(json) TYPE bloom_filter(0.01) GRANULARITY 1;), Stack trace (when copying this message, always include the lines below):

  1. Poco::Exception::Exception(String const&, int) @ 0x000000011258513d
  2. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000010b6aa95f
  3. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000106acb034
  4. DB::Exception::Exception<String, String>(int, FormatStringHelperImpl<std::type_identity::type, std::type_identity::type>, String&&, String&&) @ 0x0000000106acc66f
  5. DB::GetAggregatesMatcher::visit(DB::ASTFunction const&, std::shared_ptrDB::IAST const&, DB::GetAggregatesMatcher::Data&) @ 0x000000010f5d4564
  6. DB::InDepthNodeVisitor<DB::GetAggregatesMatcher, true, false, std::shared_ptrDB::IAST const>::doVisit(std::shared_ptrDB::IAST const&) @ 0x000000010f5d41cd
  7. void DB::InDepthNodeVisitor<DB::GetAggregatesMatcher, true, false, std::shared_ptrDB::IAST const>::visitChildren(std::shared_ptrDB::IAST const&) @ 0x000000010f5d4839
  8. DB::TreeRewriter::analyze(std::shared_ptrDB::IAST&, DB::NamesAndTypesList const&, std::shared_ptr<DB::IStorage const>, std::shared_ptrDB::StorageSnapshot const&, bool, bool, bool, bool) const @ 0x000000010f9df059
  9. DB::IndexDescription::getIndexFromAST(std::shared_ptrDB::IAST const&, DB::ColumnsDescription const&, std::shared_ptr<DB::Context const>) @ 0x0000000110224551
  10. DB::AlterCommand::apply(DB::StorageInMemoryMetadata&, std::shared_ptr<DB::Context const>) const @ 0x00000001101dbeff
  11. DB::AlterCommands::apply(DB::StorageInMemoryMetadata&, std::shared_ptr<DB::Context const>) const @ 0x00000001101e0241
  12. DB::MergeTreeData::checkAlterIsPossible(DB::AlterCommands const&, std::shared_ptr<DB::Context const>) const @ 0x000000011073bfb4
  13. DB::InterpreterAlterQuery::executeToTable(DB::ASTAlterQuery const&) @ 0x000000010f625542
  14. DB::InterpreterAlterQuery::execute() @ 0x000000010f6236b1
  15. DB::executeQueryImpl(char const*, char const*, std::shared_ptrDB::Context, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x000000010fa3a8e8
  16. DB::executeQuery(String const&, std::shared_ptrDB::Context, DB::QueryFlags, DB::QueryProcessingStage::Enum) @ 0x000000010fa370b8
  17. DB::TCPHandler::runImpl() @ 0x0000000110c696cc
  18. DB::TCPHandler::run() @ 0x0000000110c81b1c
  19. Poco::Net::TCPServerConnection::start() @ 0x0000000112636e6c
  20. Poco::Net::TCPServerDispatcher::run() @ 0x00000001126373de
  21. Poco::PooledThread::run() @ 0x00000001125e1292
  22. Poco::ThreadImpl::runnableEntry(void*) @ 0x00000001125dea41
  23. _pthread_start @ 0x00007ff81af8918b
  24. thread_start @ 0x00007ff81af84ae3

Elapsed: 0.002 sec.
Received exception from server (version 24.9.1):
Code: 184. DB::Exception: Received from DB::Exception: Aggregate function distinctJSONPaths(json) is found in wrong place in query: While processing distinctJSONPaths(json). (ILLEGAL_AGGREGATION)

`

Is there something fundamentally wrong the way I am using the aggregate 'distinctJSONPaths' function? Is this an expected error?

I wish to create a similar index as created for the fields value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants