Class FilterRequirement
"Must-filter" fields must be filtered for a query to be considered valid; and "bypass" fields can defuse the errors if they are filtered on as an alternative.
Filter requirements originate in a SemanticTable in the model
and propagate to any query that uses that table.
For example, consider table t,
which has a must-filter field f
and bypass-fields b0 and b1,
and the following queries:
- Query
select f from tis invalid because there is no filter onf. - Query
select * from (select f from t)gives an error in the subquery because there is no filter onf. - Query
select f from t where f = 1is valid because there is a filter onf. - Query
select * from (select f from t) where f = 1is valid because there is a filter onf. - Query
select f from t where b0 = 1is valid because there is a filter on the bypass-fieldb0.
FilterRequirement is immutable, and has an instance EMPTY
with no filters.
Notes on remnantFilterFields
remnantFilterFields identifies whether the query should error
at the top level query. It is populated with the filter-field value when a
filter-field is not selected or filtered on, but a bypass-field for the
table is selected.
A remnant-filter field is no longer accessible by the enclosing query, and so the query can no longer be defused by filtering on it. We must keep track of the remnant-filter field because the query can still be defused by filtering on a bypass-field.
For example, consider table t with a must-filter field f
and bypass-fields b0 and b1.
- Query
select b0, b1 from tresults infilterFields= [],bypassFields= [b0,b1],remnantFilterFields= [f]. The query is invalid because it is a top-level query andremnantFilterFieldsis not empty. - Query
select * from (select b0, b1 from t) where b0 = 1is valid. When unwrapping the subquery we get the sameFilterRequirementas the previous example:filterFields= [],bypassFields= [b0,b1],remnantFilterFields= [f]. But when unwrapping the top-level query, the filter onb0defuses theremnantFilterFieldrequirement of [f] because it originated in the same table, resulting in the following:filterFields= [],bypassFields= [b0,b1],remnantFilterFields= []. The query is valid becauseremnantFilterFieldsis now empty.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ImmutableBitSetOrdinals (in the row type) of the "bypass" fields, fields that can defuse validation errors onfilterFieldsif filtered on.static final FilterRequirementEmpty filter requirement.final ImmutableBitSetOrdinals (in the row type) of the "must-filter" fields, fields that must be filtered in a query.final com.google.common.collect.ImmutableSet<SqlQualified>Set ofSqlQualifiedinstances representing fields that have not been defused in the current query, but can still be defused by filtering on a bypass field in the enclosing query. -
Method Summary
-
Field Details
-
EMPTY
Empty filter requirement. -
filterFields
Ordinals (in the row type) of the "must-filter" fields, fields that must be filtered in a query. -
bypassFields
Ordinals (in the row type) of the "bypass" fields, fields that can defuse validation errors onfilterFieldsif filtered on. -
remnantFilterFields
Set ofSqlQualifiedinstances representing fields that have not been defused in the current query, but can still be defused by filtering on a bypass field in the enclosing query.
-