是否有任何选项来定义dbGetQuery的特定时间限制

时间:2019-04-08 12:41:37

标签: r dbi pool rmysql

对于R var result = from s in db.StakeHolders join pr in db.PaymentsAndReceipt on s.StakeHolderId equals pr.StakeHolderId where StakeHolderTypeId == "0b85a69e-55f2-4142-a49d-98e22aa7ca10" group s by new { s.StakeHolderId,s.CompanyName} into p select new { StakeHolderId= p.Key.StakeHolderId, CompanyName= p.Key.CompanyName, Receivables = string.Format("{0:C}", p.Sum(y => y.Amount)) }; 程序包来说。是否有任何选项或参数可以限制SQL查询时间。

从中找不到任何选项 DBI dbConnect(drv, ...)

dbGetQuery(conn, statement, ...)程序包提供了pool选项,但找不到限制查询时间的选项或参数

如果超过时间限制,则预期返回null,这样就不会影响外部数据库

1 个答案:

答案 0 :(得分:4)

You can use the function withTimeout(QUERY, timeout=TIMEINSECONDS) from package R.utils

By default it gives you an error if executing whatever you pass in the first parameter executes for more than the timout parameter seconds.

But if you tune parameter onTimeout you can define " A character specifying what action to take if a timeout event occurs" and TimeoutException to catch and treat the timeout. See ?withTimeout examples