agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
876 stars 47 forks source link

Hangs when :showrelvars with isomorphic schema in tutd #349

Closed hisaket closed 1 year ago

hisaket commented 1 year ago

When I perform the following steps as per the Isomorphic Schemas tutorial, the program hangs at the time of :showrelvars, contrary to the results in the documentation.

$ stack --stack-yaml stack.ghc8.10.yaml exec tutd
Warning: Haskell scripting disabled: ScriptingDisabled
Project:M36 TutorialD Interpreter 0.9.4
Type ":help" for more information.
A full tutorial is available at:
https://github.com/agentm/project-m36/blob/master/docs/tutd_tutorial.markdown
TutorialD (master/main): x1:=relation{tuple{y 3}, tuple{y 4}}
TutorialD (master/main): x2:=relation{tuple{y 5}, tuple{y 6}}
TutorialD (master/main): :addschema spam (isorestrict "x" "x1" "x2" lt(@y,5), isopassthrough "true", isopassthrough "false")
TutorialD (master/main): :setschema spam
TutorialD (master/spam): :showexpr x
┌──────────┐
│y::Integer│
├──────────┤
│6         │
│3         │
│5         │
│4         │
└──────────┘
TutorialD (master/spam): :showrelvars

The hang seems to be caused by the relation variables true and false; if I do :undefine true and false, instead I get the following error:

$ stack --stack-yaml stack.ghc8.10.yaml exec tutd
Warning: Haskell scripting disabled: ScriptingDisabled
Project:M36 TutorialD Interpreter 0.9.4
Type ":help" for more information.
A full tutorial is available at:
https://github.com/agentm/project-m36/blob/master/docs/tutd_tutorial.markdown
TutorialD (master/main): undefine true
TutorialD (master/main): undefine false
TutorialD (master/main): x1:=relation{tuple{y 3}, tuple{y 4}}
TutorialD (master/main): x2:=relation{tuple{y 5}, tuple{y 6}}
TutorialD (master/main): :addschema spam (isorestrict "x" "x1" "x2" lt(@y,5))
TutorialD (master/main): :setschema spam
TutorialD (master/spam): :showexpr x
┌──────────┐
│y::Integer│
├──────────┤
│3         │
│4         │
│5         │
│6         │
└──────────┘
TutorialD (master/spam): :showrelvars
ERR: RelVarNotDefinedError "x1"
TutorialD (master/spam):

However, instead of an error the following result should be expected:

TutorialD (master/spam): :showrelvars
┌─────────────────────────────────────────────────────────────────┬──────────────────┐
│attributes::relation {attribute::TextAtomType,type::TextAtomType}│name::TextAtomType│
├─────────────────────────────────────────────────────────────────┼──────────────────┤
│┌───────────────────────┬──────────────────┐                     │"x"               │
││attribute::TextAtomType│type::TextAtomType│                     │                  │
│├───────────────────────┼──────────────────┤                     │                  │
││"y"                    │"IntAtomType"     │                     │                  │
│└───────────────────────┴──────────────────┘                     │                  │
└─────────────────────────────────────────────────────────────────┴──────────────────┘

Also, the cause seems to be the library itself, not tutd. For example, the following code using the Client API (ProjectM36.Client) hangs as well:

testShowrelvarsWithSchema :: IO ()
testShowrelvarsWithSchema = do
    conn <- assertEither =<< connectProjectM36 (InProcessConnectionInfo NoPersistence (\_ _ -> pure ()) [])
    sid <- assertEither =<< createSessionAtHead conn defaultHeadName
    assertEither =<< executeSchemaExpr sid conn (AddSubschema "spam" [IsoRename "true" "true", IsoRename "false" "false"])
    assertEither =<< setCurrentSchemaName sid conn "spam"
    r <- assertEither =<< relationVariablesAsRelation sid conn
    print r
    pure ()

assertEither :: (Show a) => Either a b -> IO b
assertEither x = case x of
    Left err -> error $ show err
    Right val -> pure val

To Reproduce:

  1. git clone https://github.com/agentm/project-m36
  2. cd project-m36
  3. stack --stack-yaml stack.ghc8.10.yaml build --flag project-m36:-haskell-scripting

Note: I have disabled Haskell scripting because without it I get the following error in my environment. I believe this is probably unrelated, but if this is the cause I am very sorry.

$ stack --stack-yaml stack.ghc8.10.yaml run tutd
tutd: Ambiguous module name ‘Prelude’:
  it was found in multiple packages:
  base-4.14.3.0 incipit-base-0.1.0.3 incipit-core-0.1.0.3

Environments:

agentm commented 1 year ago

Thanks for the detailed instructions! I am able to reproduce this and it looks like the code may have an infinite loop. I'll fix this shortly. Thanks!

agentm commented 1 year ago

This turned out to be caused by a poor refactoring after the data independence architectural change.

hisaket commented 1 year ago

Thanks for the fast fix and for adding the test!