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 t
is 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 = 1
is valid because there is a filter onf
. - Query
select * from (select f from t) where f = 1
is valid because there is a filter onf
. - Query
select f from t where b0 = 1
is 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 t
results infilterFields
= [],bypassFields
= [b0
,b1
],remnantFilterFields
= [f
]. The query is invalid because it is a top-level query andremnantFilterFields
is not empty. - Query
select * from (select b0, b1 from t) where b0 = 1
is valid. When unwrapping the subquery we get the sameFilterRequirement
as the previous example:filterFields
= [],bypassFields
= [b0
,b1
],remnantFilterFields
= [f
]. But when unwrapping the top-level query, the filter onb0
defuses theremnantFilterField
requirement of [f
] because it originated in the same table, resulting in the following:filterFields
= [],bypassFields
= [b0
,b1
],remnantFilterFields
= []. The query is valid becauseremnantFilterFields
is now empty.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ImmutableBitSet
Ordinals (in the row type) of the "bypass" fields, fields that can defuse validation errors onfilterFields
if filtered on.static final FilterRequirement
Empty filter requirement.final ImmutableBitSet
Ordinals (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 ofSqlQualified
instances 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 onfilterFields
if filtered on. -
remnantFilterFields
Set ofSqlQualified
instances 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.
-