forked from apache/calcite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-6219] 'Must-filter' columns
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 <[email protected]>
- Loading branch information
1 parent
96485c0
commit 2558c13
Showing
15 changed files
with
560 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/java/org/apache/calcite/sql/validate/SemanticTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.calcite.sql.validate; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* Extension to {@link SqlValidatorTable} with extra, optional metadata. | ||
* | ||
* <p>Used to flag individual columns as 'must-filter'. | ||
*/ | ||
public interface SemanticTable { | ||
/** Returns the filter expression for {@code column} | ||
* if it is a {@link #mustFilter(int) must-filter} column, | ||
* or null if it is not a must-filter column. | ||
* | ||
* @param column Column ordinal (0-based) | ||
* | ||
* @throws IndexOutOfBoundsException if column ordinal is out of range */ | ||
default @Nullable String getFilter(int column) { | ||
return null; | ||
} | ||
|
||
/** Returns whether {@code column} must be filtered in any query | ||
* that references this table. | ||
* | ||
* @param column Column ordinal (0-based) | ||
* | ||
* @throws IndexOutOfBoundsException if column ordinal is out of range */ | ||
default boolean mustFilter(int column) { | ||
return getFilter(column) != null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.