Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6219] Must Filter validation #3688

Closed

Conversation

olivrlee
Copy link
Contributor

No description provided.

olivrlee and others added 12 commits February 2, 2024 22:19
Added many tests and cleaned up

Fix style, delete unused

add return in case block

Fix all checkstyle and add java docs

Remove unused

remove unused inport

checkstyle spacing fix and forbiddenApi removal

Update validateClause()

checkstyleMain test fix

Missing @OverRide annotation

Add missing @OverRide

Add missing Override annotation

Change to static annotation
…ss all tests

Next step is to remove AlwaysFilterValidatorImpl and fix the various TODO
@olivrlee olivrlee changed the title [CALCITE-6219] Always Filter [CALCITE-6219] Must Filter validation Feb 14, 2024
Copy link

sonarcloud bot commented Feb 15, 2024

julianhyde added a commit to julianhyde/calcite that referenced this pull request Feb 17, 2024
julianhyde added a commit to julianhyde/calcite that referenced this pull request Feb 17, 2024
A table can declare that some of its columns must be filtered
by implementing `interface SemanticTable`. If such columns
are not filtered in a WHERE or HAVING clause, the validator
throws.

There are several purposes of these columns, one of which is
to prevent expensive full-table scans (for example, reading
all Orders without restricting on orderDate).

Implementation is via the method
SqlValidatorNamespace.getMustFilterFields(). For a table
namespace, that method returns the declared must-filter
fields. For a query namespce, that method returns any
must-filter fields that have not been filtered in that query;
such fields become the responsibility of the enclosing query.

If a field is must-filter and is not in the SELECT clause of a
sub-query, that is also an error, because of course it is now
impossible for the enclosing query to filter it.

Close apache#3688

Co-authored-by: Julian Hyde <jhyde@apache.org>
julianhyde added a commit to julianhyde/calcite that referenced this pull request Feb 17, 2024
A table can declare that some of its columns must be filtered
by implementing `interface SemanticTable`. If such columns
are not filtered in a WHERE or HAVING clause, the validator
throws.

There are several purposes of these columns, one of which is
to prevent expensive full-table scans (for example, reading
all Orders without restricting on orderDate).

Implementation is via the method
SqlValidatorNamespace.getMustFilterFields(). For a table
namespace, that method returns the declared must-filter
fields. For a query namespce, that method returns any
must-filter fields that have not been filtered in that query;
such fields become the responsibility of the enclosing query.

If a field is must-filter and is not in the SELECT clause of a
sub-query, that is also an error, because of course it is now
impossible for the enclosing query to filter it.

Close apache#3688

Co-authored-by: Julian Hyde <jhyde@apache.org>

if (validator.config().identifierExpansion()) {
SqlValidatorTable table = resolvedNamespace.getTable();
if (table != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to tell on github but could we remove a level of nesting if we change this to if (table == null) { break; }?

@@ -245,6 +244,24 @@ private SqlValidatorNamespace resolveImpl(SqlIdentifier id) {
return rowType;
}

@Override public void validateAlwaysFilter(Set<String> alwaysFilterFields) {
resolvedNamespace = resolveImpl(id);
if (resolvedNamespace instanceof TableNamespace) {
Copy link
Contributor

Choose a reason for hiding this comment

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

similar comment for some of these checks, we could change it to check if something is NOT true, and if it isn't then we just return, otherwise continue.

julianhyde added a commit to julianhyde/calcite that referenced this pull request Feb 27, 2024
A table can declare that some of its columns must be filtered
by implementing `interface SemanticTable`. If such columns
are not filtered in a WHERE or HAVING clause, the validator
throws.

There are several purposes of these columns, one of which is
to prevent expensive full-table scans (for example, reading
all Orders without restricting on orderDate).

Implementation is via the method
SqlValidatorNamespace.getMustFilterFields(). For a table
namespace, that method returns the declared must-filter
fields. For a query namespce, that method returns any
must-filter fields that have not been filtered in that query;
such fields become the responsibility of the enclosing query.

If a field is must-filter and is not in the SELECT clause of a
sub-query, that is also an error, because of course it is now
impossible for the enclosing query to filter it.

Close apache#3688

Co-authored-by: Julian Hyde <jhyde@apache.org>
@olivrlee olivrlee deleted the olivrlee/6219-always-filter_revised branch February 27, 2024 19:57
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.

3 participants