CategoricalData / CQL

Categorical Query Language IDE
http://categoricaldata.net
299 stars 22 forks source link

options timeout doesn't appear to be respected #45

Closed o1lo01ol1o closed 4 years ago

o1lo01ol1o commented 4 years ago

I have a large schema in postgres I'm trying to import but seem to be unable to set the timeout option. The entirety of my CQL file is:

options 
   timeout = 6000
   gui_rows_to_display = 600
   gui_max_table_size = 6000
   gui_max_graph_size = 6000
   gui_max_string_size = 6000
   always_reload = true

schema sourcedata = import_jdbc_all  "jdbc:postgresql://foo/bar"

This seems to always throw:

Timeout after 5 seconds. 

Possible solution: add options timeout=X where X > 5 is how many seconds to wait.

If I connect to the baz db on the same server, I'm able to retrieve the schema, presumably because it is able to query the data in under 5 seconds.

Am I doing something wrong?

EDIT: having just written the above, I stumbled on the static_timeout option and setting that = 6000 seems to have made progress. However, I now get a Null pointer runtime error:

$ java -Xms2048m -Xmx4096m -cp "postgresql-42.2.14.jar:./CQL.jar" catdata.ide.IDE
objc[4173]: Class FIFinderSyncExtensionHost is implemented in both /System/Library/PrivateFrameworks/FinderKit.framework/Versions/A/FinderKit (0x7fff8d9173d8) and /System/Library/PrivateFrameworks/FileProvider.framework/OverrideBundles/FinderSyncCollaborationFileProviderOverride.bundle/Contents/MacOS/FinderSyncCollaborationFileProviderOverride (0x166e32f50). One of the two will be used. Which one is undefined.
Warning: Nashorn engine is planned to be removed from a future JDK release
java.lang.RuntimeException
    at catdata.sql.SqlTable.validate(SqlTable.java:40)
    at catdata.sql.SqlSchema.validate(SqlSchema.java:38)
    at catdata.sql.SqlSchema.<init>(SqlSchema.java:155)
    at catdata.aql.exp.SchExpJdbcAll.eval0(SchExpJdbcAll.java:146)
    at catdata.aql.exp.SchExpJdbcAll.eval0(SchExpJdbcAll.java:1)
    at catdata.aql.exp.Exp.eval(Exp.java:229)
    at catdata.aql.exp.Exp.eval_static(Exp.java:145)
    at catdata.aql.exp.AqlStatic.lambda$0(AqlStatic.java:44)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:835)
Anomaly: please report.  (Null pointer)
java.lang.RuntimeException: Anomaly
    at catdata.aql.gui.AqlCodeEditor.lambda$2(AqlCodeEditor.java:375)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
java.util.concurrent.ExecutionException: java.lang.RuntimeException
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at catdata.Util.timeout(Util.java:85)
    at catdata.aql.exp.AqlMultiDriver.call(AqlMultiDriver.java:402)
    at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: java.lang.RuntimeException
    at catdata.sql.SqlTable.validate(SqlTable.java:40)
    at catdata.sql.SqlSchema.validate(SqlSchema.java:38)
    at catdata.sql.SqlSchema.<init>(SqlSchema.java:155)
    at catdata.aql.exp.SchExpJdbcAll.eval0(SchExpJdbcAll.java:146)
    at catdata.aql.exp.SchExpJdbcAll.eval0(SchExpJdbcAll.java:1)
    at catdata.aql.exp.Exp.eval(Exp.java:229)
    at catdata.aql.exp.AqlMultiDriver.lambda$3(AqlMultiDriver.java:402)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    ... 1 more
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.RuntimeException
    at catdata.Util.timeout(Util.java:93)
    at catdata.aql.exp.AqlMultiDriver.call(AqlMultiDriver.java:402)
    at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at catdata.Util.timeout(Util.java:85)
    ... 2 more
Caused by: java.lang.RuntimeException
    at catdata.sql.SqlTable.validate(SqlTable.java:40)
    at catdata.sql.SqlSchema.validate(SqlSchema.java:38)
    at catdata.sql.SqlSchema.<init>(SqlSchema.java:155)
    at catdata.aql.exp.SchExpJdbcAll.eval0(SchExpJdbcAll.java:146)
    at catdata.aql.exp.SchExpJdbcAll.eval0(SchExpJdbcAll.java:1)
    at catdata.aql.exp.Exp.eval(Exp.java:229)
    at catdata.aql.exp.AqlMultiDriver.lambda$3(AqlMultiDriver.java:402)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    ... 1 more
catdata.LineException: java.util.concurrent.ExecutionException: java.lang.RuntimeException
    at catdata.aql.exp.AqlMultiDriver.call(AqlMultiDriver.java:437)
    at java.base/java.lang.Thread.run(Thread.java:835)
wisnesky commented 4 years ago

5 seconds is the timeout used by the UI thread to process schemas at compile time (as opposed to runtime). If your schema takes longer than 5 seconds to import, then the UI thread will show an error in the UI, but it shouldn’t timeout at runtime. You should be able to test this by toggling the ‘prove’ option in the UI. On further reflection, 'jdbc schema import all' should probably not even be attempted at compile time, since jdbc fetches over the internet can easily exceed 5 seconds. I’ll make that change.

Alternatively, it wouldn’t surprise me if some internal error due to Postgres and CQL interaction is escaping and manifesting as a 5 second timeout, as the UI does ‘last resort’ error catching. Postgres testing is lacking compared to e.g., H2 or MySQL. Can you share your file and/or data?

Finally, the reason schema import can take longer than 5 seconds is that the schema ‘import all’ constructs a decision procedure for the SQL schema naively, rather than exploiting the particular nature of SQL primary and foreign keys, etc. The reason for that is mostly expediency: in practice, importing a slice of SQL data onto explicitly designed CQL schemas tends to work far better than importing everything into CQL and then projecting the slice you care about from within CQL. In particular, this landing process can be used to create fresh IDs, normalize values, perform type conversion, etc from within SQL code, and it bypasses the construction of a decision procedure for the entire sql database schema.

On Jul 9, 2020, at 2:24 AM, Tim Pierson notifications@github.com wrote:

I have a large schema in postgres I'm trying to import but seem to be unable to set the timeout option. The entirety of my CQL file is:

options timeout = 6000 gui_rows_to_display = 600 gui_max_table_size = 6000 gui_max_graph_size = 6000 gui_max_string_size = 6000 always_reload = true

schema sourcedata = import_jdbc_all "jdbc:postgresql://foo/bar" This seems to always throw:

Timeout after 5 seconds.

Possible solution: add options timeout=X where X > 5 is how many seconds to wait. If I connect to the baz db on the same server, I'm able to retrieve the schema, presumably because it is able to query the data in under 5 seconds.

Am I doing something wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CategoricalData/CQL/issues/45, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2QKN6PVPI6QXHEEZTTNILR2WEGHANCNFSM4OVM7EOA.

o1lo01ol1o commented 4 years ago

Can you share your file and/or data?

Unfortunately some is not public and, as you might guess from the name sourcedata it's all rather unpleasant and mostly singleton tables.

I edited the above description when I found the static_timeout option but that seems to lead to a Null Pointer error.

In general, is there a way to import a subset of a postgressql database? Say only one schema or if that's not possible, an explicit query from tables?

wisnesky commented 4 years ago

I think you are describing the usual jdbc import process: given a CQL schema S, and an SQL DB X, the 'import_jdbc' primitive lets you write one SQL query per CQL entity, that returns a column for each attribute and foreign key in S, and an 'id' column, and puts the data into a CQL S-instance. This method is preferred in part because, to faithfully preserve SQL semantics in CQL, imported SQL schemas have more columns than the actual imported DB and look kind of stylized.

I'll download a postgres database and try an import to see if I can track down the error. Usually there are some issues with JDBC compliance to deal with the first time a new vendor's jdbc driver is used; the commercial version of CQL uses JOOQ (vs JDBC) to bypass these issues entirely. My guess is either these issues or 'long running theorem proving' is leading to the exception.

On 7/9/20, Tim Pierson notifications@github.com wrote:

Can you share your file and/or data?

Unfortunately some is not public and, as you might guess from the name sourcedata it's all rather unpleasant and mostly singleton tables.

I edited the above description when I found the static_timeout option but that seems to lead to a Null Pointer error.

In general, is there a way to import a subset of a postgressql database? Say only one schema or if that's not possible, an explicit query from tables?

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/CategoricalData/CQL/issues/45#issuecomment-656044293

o1lo01ol1o commented 4 years ago

I've since restored the schema that interests me to a separate database and am able to import it. I suspect there may have been a permissions error on some object or another in the database that may have been complicating things.