创建外部表HIVE的RJDBC dbGetQuery()错误。

时间:2022-03-03 00:58:31

I encounter this problem: the DB call only creates a table, it has problem of retrieving JDBC result set.

我遇到了这个问题:DB调用只创建了一个表,它有检索JDBC结果集的问题。

Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for Calls: dbGetQuery ... dbSendQuery -> dbSendQuery -> .local -> .verify.JDBC.result Execution halted

在.verify.JDBC错误。结果(r)无法检索调用的JDBC结果集:dbGetQuery…dbSendQuery -> dbSendQuery -> .local -> . verify.jdbc。结果执行停止

    options( java.parameters = "-Xmx32g" )
    library(rJava)
    library(RJDBC)
    drv <- JDBC("org.apache.hive.jdbc.HiveDriver", "/tmp/r_jars/hive-jdbc.jar")
    for(jar in list.files('/tmp/r_jars/')){
        .jaddClassPath(paste("/tmp/r_jars/",jar,sep=""))
    }

    conn <- dbConnect(drv, "jdbc:hive2://10.40.51.75:10000/default", "myusername", "mypassword")

    createSCOREDDL_query <- "CREATE EXTERNAL TABLE hiveschema.mytable (
       myvariables
    )
    ROW FORMAT SERDE
    'com.bizo.hive.serde.csv.CSVSerde'
     STORED AS INPUTFORMAT
    'org.apache.hadoop.mapred.TextInputFormat'
     OUTPUTFORMAT
     'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
     LOCATION
    's3://mybucket/myschema/'"

    dbGetQuery(conn, createSCOREDDL_query)
    dbDisconnect(conn)

2 个解决方案

#1


1  

Instead of dbGetQuery can you try using dbSendUpdate? I was having similar issues and making this switch solved the problem.

您可以尝试使用dbSendUpdate而不是dbGetQuery吗?我也遇到过类似的问题,所以这个开关解决了问题。

#2


0  

I tried with the following code as suggested by @KaIC and it worked:

我用@KaIC的建议尝试了以下代码:

dbSendUpdate(conn, "CREATE EXTERNAL TABLE hiveschema.mytable ( col_A  string, col_B  string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE")

For multiple tables, you can create a list or loop within a function and use an apply() construct to apply it to the entire loop.

对于多个表,可以在函数中创建列表或循环,并使用apply()构造将其应用到整个循环。

#1


1  

Instead of dbGetQuery can you try using dbSendUpdate? I was having similar issues and making this switch solved the problem.

您可以尝试使用dbSendUpdate而不是dbGetQuery吗?我也遇到过类似的问题,所以这个开关解决了问题。

#2


0  

I tried with the following code as suggested by @KaIC and it worked:

我用@KaIC的建议尝试了以下代码:

dbSendUpdate(conn, "CREATE EXTERNAL TABLE hiveschema.mytable ( col_A  string, col_B  string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE")

For multiple tables, you can create a list or loop within a function and use an apply() construct to apply it to the entire loop.

对于多个表,可以在函数中创建列表或循环,并使用apply()构造将其应用到整个循环。