AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题

问题[r](dba)

Martin Hope
mkobayashi
Asked: 2019-10-11 20:24:56 +0800 CST

使用 MySQL 数据库在 R 上创建报告会更新我在 MySQL 上的数据库吗?

  • 0

我使用 MySQL 来存储我的数据。为了分析数据,我希望能够在 R 上生成月度报告。到目前为止,我能够使用连接到 MySQL,dbConnect但我想确保我所做的任何调整都不会影响我在 MySQL 中拥有的数据库。下面是我用来将数据库/表导入 R 的代码。

install.packages("RODBC")
library(RODBC)
Data<-dbConnect(drv, username="<insert username here>", password="<insert password here>", dbname ="<insert database name here>")
Table1 <- fetch(dbSendQuery(Data, "select * from Table"),-1)

使用该fetch函数,我可以将表加载到 R 中,但我想确保我不会同时在 MySQL 上更改它。应用任何操作、添加列等会影响 MySQL 中的原始数据库吗?

mysql r
  • 1 个回答
  • 75 Views
Martin Hope
Kingindanord
Asked: 2017-12-11 16:09:32 +0800 CST

如何在使用 R 时防止 SQLite 阻塞?

  • 2

我正在做一个无限循环以不断从数据库db收集数据,对其进行返工并将其发送到另一个数据库db1

library(DBI)
library(RSQLite)


while(1==1){

  db = dbConnect(SQLite(), dbname="Data.sqlite",synchronous = NULL)
  db1 = dbConnect(SQLite(), dbname="Data2.sqlite",synchronous = NULL)
  db1
  db

Column1=dbGetQuery(db,'select * from Table1')

  #Here is some calculations#

    Result = Column1/10

  #Here calculations are finished and ready to be sent to new database#

dbWriteTable(db1, name="Result", value=Result, row.names=TRUE, append=TRUE)
   dbDisconnect(db1)
   dbDisconnect(db)
}

当我运行代码时,它执行了大约 10 个循环,然后出现以下错误:rsqlite_send_query(conn@ptr, statement) 中的错误:数据库已锁定

有人可以帮我解决这个问题吗

sqlite r
  • 1 个回答
  • 770 Views
Martin Hope
Jaakko Seppälä
Asked: 2017-06-16 06:59:00 +0800 CST

SQL Server 中的 R 代码找不到包 psych

  • 2

我尝试在 SQL Server 中运行 R 代码,但它不会运行,尽管它运行或 R。如何让 R 在 SQL Server 上正常运行,以便它找到包 psych?我在https://learn.microsoft.com/en-us/sql/advanced-analytics/tutorials/rtsql-working-with-inputs-and-outputs中测试了示例,以确保至少一些 R 代码在 SQL 中正常工作服务器。

我试过了

EXECUTE sp_execute_external_script    
    @language = N'R'    
   , @script = N'a1=c(4,3,4,5,1,5,5,5,5,5,5,4,4,4,5,4,5,5,5,4,5,5,4,4,5,5,3,4,4,4,4,5,5,4,3,5,1,5,5,5,5,4,4,4,5,5,4,5,5,4,5,5,5,4,4,1,5,5,3,5,5,4,5,5,4,4,4,4,5,5,4,4,4,4,5,1,5,5,5,4,4,3,5,4,5,5,4,4,4,5,5,5,5,5,3,5,4,5,5,5,5,5,5,5,4,5,4,4,5,4,5,5,5,4,5,4,4,5,4,5,5,2,4,4,5,3,4,4,4,5,4,5,3,5,5,5,4,5,5,2,1,5,5,5,4,4,4,4,5,5,4,4,5)
a1=c(4,3,4,5,1,5,5,5,5,5,5,4,4,4,5,4,5,5,5,4,5,5,4,4,5,5,3,4,4,4,4,5,5,4,3,5,1,5,5,5,5,4,4,4,5,5,4,5,5,4,5,5,5,4,4,1,5,5,3,5,5,4,5,5,4,4,4,4,5,5,4,4,4,4,5,1,5,5,5,4,4,3,5,4,5,5,4,4,4,5,5,5,5,5,3,5,4,5,5,5,5,5,5,5,4,5,4,4,5,4,5,5,5,4,5,4,4,5,4,5,5,2,4,4,5,3,4,4,4,5,4,5,3,5,5,5,4,5,5,2,1,5,5,5,4,4,4,4,5,5,4,4,5)
a2=c(4,4,4,5,5,5,5,5,4,4,4,4,4,5,5,5,5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4,3,4,4,4,4,3,4,4,4,4,4,2,3,3,3,4,3,3,4,4,2,3,3,5,3,3,4,2,2,3,2,4,3,4,5,2,4,4,2,4,2,5,4,2,2,4,3,3,3,4,3,3,3,3,4,4,4,3,3,3,1,5,4,3,4,4,4,3,2,3,3,2,5,4,3,3)
a19=c(4,4,4,5,5,4,5,3,4,3,4,3,4,5,2,5,5,5,4,4,4,4,4,4,5,5,2,4,5,4,5,5,5,5,4,5,1,5,4,3,5,3,4,4,4,4,4,1,5,4,4,4,4,5,5,5,4,5,4,4,4,4,5,4,5,4,3,5,5,5,3,4,4,4,4,5,4,4,5,5,3,4,4,4,4,4,5,5,2,5,5,4,5,4,2,5,5,4,4,4,4,5,4,5,3,5,4,3,4,4,4,5,5,3,4,3,5,2,5,4,4,2,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,5,5,4,4,4,5,4,3,4,3,2,4,4,5,4)
a20=c(5,5,5,5,5,5,4,5,3,4,5,4,5,5,5,5,5,5,5,4,5,5,4,5,5,4,5,4,5,5,5,5,4,5,4,5,5,5,5,5,5,5,5,4,5,5,5,5,1,4,5,5,5,4,5,5,5,5,4,5,5,5,5,5,5,5,5,4,5,5,5,5,4,4,5,5,5,5,5,5,5,3,5,5,5,5,5,5,4,5,5,5,5,4,4,4,5,5,5,5,1,5,4,5,5,4,4,5,5,5,4,5,1,4,5,5,5,5,4,5,2,4,1,5,5,4,5,5,4,5,1,4,4,5,5,5,4,5,5,5,5,5,4,5,4,4,4,4,5,4.56579,5,4,4)
options(warn=-1);a=cbind(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
library(psych);
result = tryCatch(alpha(a), warning = function(w) {tryCatch(alpha(a,check.keys=TRUE),warning = function(w) { print("Error, lets try some likelihood!" ) })})
cor(a, method = c("spearman"))'    
   , @input_data_1 = N' SELECT 1 as Temp1'    
   WITH RESULT SETS (([Col1] char(20) NOT NULL));    

错误是

消息 39004,级别 16,状态 20,第 1 行
执行“sp_execute_external_script”期间出现“R”脚本错误,HRESULT 为 0x80004004。

消息 39019,级别 16,状态 1,第 1 行
发生外部脚本错误:
库 (psych) 错误:没有名为“psych”的包
调用:source -> withVisible -> eval -> eval -> library

sql-server r
  • 1 个回答
  • 145 Views
Martin Hope
Minu
Asked: 2016-06-21 05:26:51 +0800 CST

SQL Server R 服务 - 找不到存储过程“master..xp_ScaleR_init_job”

  • 3

我正在尝试按照本教程中的说明运行数据科学实验。本教程有 5 节课,每节课都有几个小节。

对于本教程,我正在使用

  • Azure 上的 SQL Server 2016 RC3 虚拟机,启用了 R 服务。
  • RRE for Windows 8.0.0 作为数据科学客户端/R 客户端(用于远程连接到 SQL Server)
  • 创建了一个新的 SQL 登录名,具有对数据库的读、写和 ddl 访问权限 - 用于通过 R 客户端连接到 SQL Server。

我已成功完成第 1 课,即从我的 R 客户端创建 SQL Server 数据对象,查询和修改 SQL Server 数据,以及定义/设置计算上下文。

我在本教程第 2 课的开头遇到了一个错误。
一旦我将计算上下文从本地更改为 sql server,一个简单的汇总函数 (rxsummary) 就会抛出错误。

错误如下所示:

C:\Users\...\Project0\DeepDive Experiment.R(109): Error in try({ : 
  ODBC statement error: [Microsoft][ODBC SQL Server Driver][SQL Server]Could not find stored procedure 'master..xp_ScaleR_init_job'.
Error in rxInDbJobIdParam(schedulerJobInstance, FALSE) : 
  hpcServerJob object has an invalid id. Ensure it was returned from a prior rxStartClusterJob() call
Error in rxStartClusterJob(hpcServerJob, timesIsValidated = TRUE, continueOnFailure = FALSE) : 
  Error in try({ : 
  ODBC statement error: [Microsoft][ODBC SQL Server Driver][SQL Server]Could not find stored procedure 'master..xp_ScaleR_init_job'.

Error in rxInDbJobIdParam(schedulerJobInstance, FALSE) : 
  hpcServerJob object has an invalid id. Ensure it was returned from a prior rxStartClusterJob() call


任何帮助

  • 为什么会发生此错误?
  • 如何查找/检查主数据库中的存储过程 - 如何检查 xp_scaleR_init_job 是否存在?
  • 如果不存在,如何添加/创建存储过程?

将不胜感激。


为了方便访问,这里是完整的注释脚本,直到我遇到错误:

###########################################DATA SCIENCE DEEP DIVE TUTORIAL###############################################

##Create the SQL Server Data Objects##

#Provide your database connection string in an R variable. 
    #DDUser01 is a login created on the sql server instance for remote login. 
    #It has read, write and ddl access to the DeepDive database.
sqlConnString <- "Driver=SQL Server;Server=*ip address*; Database=DeepDive;Uid=DDUser01;Pwd=*******"   
#Specify the name of the table you want to create, and save it in an R variable.
sqlFraudTable <- "ccFraudSmall"
#Chunking
sqlRowsPerRead = 5000
#Define a variable to store the new data source
sqlFraudDS <- RxSqlServerData(connectionString = sqlConnString,table = sqlFraudTable, rowsPerRead = sqlRowsPerRead) 
#Create a new R variable, sqlScoreTable, to store the name of the table used for scoring.
sqlScoreTable <- "ccFraudScoreSmall"
#Define a second data source object 
sqlScoreDS <- RxSqlServerData(connectionString = sqlConnString,table = sqlScoreTable, rowsPerRead = sqlRowsPerRead)  

##Load Data into SQL Tables Using R##

#Create an R variable, and assign to the variable the file path for the CSV file.
ccFraudCsv <- file.path(rxGetOption("sampleDataDir"), "ccFraudSmall.csv")
#RxTextData function to specify the text data source.
inTextData <- RxTextData(file = ccFraudCsv,      colClasses = c(   
    "custID" = "integer", "gender" = "integer", "state" = "integer",   
    "cardholder" = "integer", "balance" = "integer",    
    "numTrans" = "integer",   
    "numIntlTrans" = "integer", "creditLine" = "integer",    
    "fraudRisk" = "integer"))  
#Call rxDataStep to insert the data into the SQL Server table
rxDataStep(inData = inTextData, outFile = sqlFraudDS, overwrite = TRUE)   

#Variable for creating a path to the source file - score
ccScoreCsv <- file.path(rxGetOption("sampleDataDir"), "ccFraudScoreSmall.csv") 
#RxTextData function to get the data and save it in the variable
inTextData <- RxTextData(file = ccScoreCsv,      colClasses = c(   
    "custID" = "integer", "gender" = "integer", "state" = "integer",   
    "cardholder" = "integer", "balance" = "integer",    
    "numTrans" = "integer",   
    "numIntlTrans" = "integer", "creditLine" = "integer"))  
#Call rxDataStep to overwrite the current table with the new schema and data.
rxDataStep(inData = inTextData, sqlScoreDS, overwrite = TRUE)

##Query the Data ##

#Use the function rxGetVarInfo and specify the data source you want to analyze
rxGetVarInfo(data = sqlFraudDS)   

##Modify Metadata##

#Mapping of USA State abbreviations (categorical) to their integer identifiers
#Create an R variable that holds the vector of strings to add to it - different states of the USA.
stateAbb <- c("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC",     
    "DE", "FL", "GA", "HI","IA", "ID", "IL", "IN", "KS", "KY", "LA",   
    "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NB", "NC", "ND",   
    "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI","SC",   
    "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY")  
#Create a column information object that specifies the mapping of the existing integer values to the categorical levels
    #This statement also creates factor variables for gender and cardholder.
ccColInfo <- list(         
    gender = list(   
        type = "factor",    
        levels = c("1", "2"),  
        newLevels = c("Male", "Female")),      
    cardholder = list(type = "factor",    
        levels = c( "1", "2"),     
        newLevels = c("Principal", "Secondary")),     
        state = list(type = "factor", levels = as.character(1:51), newLevels = stateAbb)   
        )  
#Update the SQL Server data source that uses the updated data
sqlFraudDS <- RxSqlServerData(connectionString = sqlConnString,  
table = sqlFraudTable, colInfo = ccColInfo,  
rowsPerRead = sqlRowsPerRead) 
#Query new information
rxGetVarInfo(data = sqlFraudDS)     

##Create and Set a Compute Context##

#Specify the connection string for the instance where computations will take place.
sqlConnString <- "Driver=SQL Server;Server=*ip address*; Database=DeepDive;Uid=DDUser01;Pwd=*******"   
#Specify the location of the shared directory (temp folder for workspace objects) and save it in a variable.
sqlShareDir <- paste("c:AllShare", Sys.getenv("USERNAME"), sep="")   
#Create shared directory if it does not exist
if (!file.exists(sqlShareDir)) dir.create(sqlShareDir, recursive = TRUE)
#Specify how you want the output handled. 
    #Here, you are indicating that the R session on the workstation should always wait for R job results, 
    #but not return console output from remote computations.
sqlWait <- TRUE   
sqlConsoleOutput <- FALSE 
#Define the compute context object
sqlCompute <- RxInSqlServer(  
     connectionString = sqlConnString,        
     shareDir = sqlShareDir,       
     wait = sqlWait,   
     consoleOutput = sqlConsoleOutput)  
#ALTERNATIVE:Enable Tracing on the Compute Context
sqlComputeTrace <- RxInSqlServer(   
    connectionString = sqlConnString,        
    shareDir = sqlShareDir,  
    wait = sqlWait,   
    consoleOutput = sqlConsoleOutput,       
    traceEnabled = TRUE,    traceLevel = 7)  
#Change Compute Context to the Server
rxSetComputeContext(sqlCompute)   

##Compute Summary Statistics##

#Compute summary statistics for several of the variables
##THIS IS WHERE I FACE THE ERROR##
sumOut <- rxSummary(formula = ~gender + balance + numTrans + numIntlTrans + creditLine, data = sqlFraudDS)  
sql-server-2016 r
  • 2 个回答
  • 1252 Views
Martin Hope
Minu
Asked: 2016-06-09 05:30:44 +0800 CST

通过 Microsoft R Server 的独立安装使用 SQL Server 2016 R Services

  • 3

我一直在试验 SQL Server 2016 及其 R 服务。我的机器上还安装了独立的 Microsoft R Server。

在独立的 Microsoft R Server 上使用 SQL Server R Services 是一个很好的用例,因为两者都具有企业级 R 平台的特性。

sql-server-2016 r
  • 1 个回答
  • 603 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve