Skip to content

Commit

Permalink
Filter derived predicates for fact-check warnings
Browse files Browse the repository at this point in the history
Summary:
[Bug fix] For lint check in daiquery.

For a predicate in query, we check if it has any facts in the current db. The warning has been showing when predicate was derived , thus facts might exist even though warning appears.

Filter the predicates, so we're not checking derived predicate, unless they're stored.

Reviewed By: iamirzhan

Differential Revision: D66834784

fbshipit-source-id: f79eb501e12ab1416f3f97ba81332d142eda1307
  • Loading branch information
Julia Molin authored and facebook-github-bot committed Dec 13, 2024
1 parent 678941d commit 858c7aa
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions glean/db/Glean/Query/UserQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ userQueryImpl
(envDebug env)

predDiag <- if Thrift.queryDebugOptions_pred_has_facts debug then
getPredDiags env repo preds
getPredDiags env repo schema preds
else return []
let
irDiag =
Expand Down Expand Up @@ -694,17 +694,26 @@ data CompileInfo = CompileInfo {
getPredDiags
:: Database.Env
-> Thrift.Repo
-> DbSchema
-> [TcPred]
-> IO [Text]
getPredDiags env repo preds = do
getPredDiags env repo schema preds = do
predStats <- PredicateStats.predicateStats env repo StackedDbOpts.IncludeBase
predsMissing <- filterM (\p -> do not <$> tcPredExist p predStats) preds
let predsMissing = filter (\p -> not (tcPredExist p predStats)) preds
return $ map warnDiag predsMissing
where
tcPredExist (PidRef pid _, _) predStats =
case Map.lookup (fromPid pid) predStats of
Just stat -> return $ Thrift.predicateStats_count stat > 0
Nothing -> return False
derived schema pid || hasFacts predStats pid
-- we assume derived predicates "exist" since we won't find any facts
derived schema pid = case lookupPid pid schema of
Just details -> case predicateDeriving details of
Derive DeriveOnDemand _ -> True
Derive DeriveIfEmpty _ -> True
_ -> False
Nothing -> error "Unknown Pid in getPredDiags"
hasFacts predStats pid = case Map.lookup (fromPid pid) predStats of
Just stat -> Thrift.predicateStats_count stat > 0
Nothing -> False
warnDiag :: TcPred -> Text
warnDiag (PidRef _ (PredicateId predRef _), Some span) = Text.pack $
"Warning: "
Expand Down

0 comments on commit 858c7aa

Please sign in to comment.