Skip to content

Move ingest validation to the Calcite validator#13903

Closed
paul-rogers wants to merge 7 commits intoapache:masterfrom
paul-rogers:230308-validate
Closed

Move ingest validation to the Calcite validator#13903
paul-rogers wants to merge 7 commits intoapache:masterfrom
paul-rogers:230308-validate

Conversation

@paul-rogers
Copy link
Copy Markdown
Contributor

@paul-rogers paul-rogers commented Mar 8, 2023

This PR was split out of the "big" catalog PR.

Refactors the Druid planner to move INSERT and REPLACE validation out of the statement handers and into the Calcite validator. This is the right place for validation in general, and is required for the catalog integration to be added in a separate PR.

  • Validation for MSQ statements moves out of the handers into a Druid-specific version of the SQL validator.
  • Druid-specific Calcite operator to represent a Druid ingest.
  • Extends the PARTITION BY clause to accept string literals for the time partitioning

Most changes are purely mechanical. One that is not is the way that the PARTITIONED BY grain is represented in the AST. Prior to this commit, PARTITIONED BY was represented as a Druid granularity object. However, the Calcite validator requires that all properties of an AST node be a subclass of SqlNode, which Granularity is not. To solve this, the granularity is represented as a string SqlLiteral in the AST, and validated into a Druid granularity in the validator. This is probably a better choice, now that we can do it. A side effect of this change is that the parser can now allow string literals for PARTITIONED BY. Example: PARTITIONED BY 'P1D'. This seems safe because, in Druid, partitioning is always by time and gives the segment grain. We are unlikely to change the segment grain idea any time soon.

This PR also forbids the use of the WEEK (or P1W) granularity, since earlier feedback indicated we no longer wish to support that gain.

Release note

This PR introduces another option for how to specify time granularity: by using ISO-8601 periods and Druid period names as a string argument to PARTITIONED BY. See reference.md for details.

Hints to reviewers

The real core of this PR is sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidSqlValidator.java: the place where we moved the former ad-hoc INSERT and REPLACE validation to instead run within the SQL validator.

No runtime code was changed: all the non-trivial changes are in the SQL planner.

The code here is identical to that in the "full" PR: all prior review comments are reflected. The only difference is that the validator in this PR omits the catalog integration from the full PR.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

* String literals for PARTITIONED BY
* Revise handlers to use new validation logic
Comment on lines 224 to +230
Map<String, Object> context = ImmutableMap.<String, Object>builder()
.putAll(DEFAULT_MSQ_CONTEXT)
.put(
MultiStageQueryContext.CTX_CLUSTER_STATISTICS_MERGE_MODE,
ClusterStatisticsMergeMode.SEQUENTIAL.toString()
)
.build();
.putAll(DEFAULT_MSQ_CONTEXT)
.put(
MultiStageQueryContext.CTX_CLUSTER_STATISTICS_MERGE_MODE,
ClusterStatisticsMergeMode.SEQUENTIAL.toString()
)
.build();

Check notice

Code scanning / CodeQL

Possible confusion of local and field

Potentially confusing name: method [testInsertOnFoo1WithTimeFunctionWithSequential](1) also refers to field [context](2) (as this.context).
@paul-rogers paul-rogers marked this pull request as draft March 22, 2023 19:50
@techdocsmith
Copy link
Copy Markdown
Contributor

techdocsmith commented May 19, 2023

@paul-rogers , this PR #14023 moved some things around, including docs/multi-stage-query/reference.md so that may be the cause of some merge conflicts.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 9, 2024

This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the dev@druid.apache.org list.
Thank you for your contributions.

@github-actions github-actions Bot added the stale label Feb 9, 2024
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 8, 2024

This pull request/issue has been closed due to lack of activity. If you think that
is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants