diff --git a/examples/R/command.txt b/examples/R/command.txt index 9a549ff200968d96336666c23999e13aa07dbb3f..84ac1d50a413013b2a07172a9d31314a7e12b436 100644 --- a/examples/R/command.txt +++ b/examples/R/command.txt @@ -1,5 +1,5 @@ # Linux Platform -install.packages('rJDBC', repos='http://cran.us.r-project.org') +install.packages('RJDBC', repos='http://cran.us.r-project.org') # Loading RJDBC packages library('RJDBC') diff --git a/examples/R/rjdbc.sample.R b/examples/R/rjdbc.sample.R new file mode 100644 index 0000000000000000000000000000000000000000..806cc3b78ec8453e53109ccf78ba5d4d673fc11d --- /dev/null +++ b/examples/R/rjdbc.sample.R @@ -0,0 +1,86 @@ + +#install.packages('RJDBC', repos='http://cran.us.r-project.org') + +library('DBI') +library('rJava') +library('RJDBC') +# get jdbc from input parameters +args<- commandArgs(trailingOnly = TRUE) +# arg[1] for jdbc path,arg[2] fro jdbc name +# like "/src/connector/jdbc/target/taos-jdbcdriver-2.0.37-dist.jar" +jdbc<- paste(args[1],args[2],sep="/") + + +print("***************************taos-jdbcDriver support RJDBC sample *************************************") +#JNI +# Get JBDC-JNI connection +drv<-JDBC("com.taosdata.jdbc.TSDBDriver",jdbc, identifier.quote="\"") +conn<-dbConnect(drv,"jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata","root","taosdata") + +#Restful +#drv<-JDBC("com.taosdata.jdbc.TSDBDriver",jdbc, identifier.quote="\"") +#conn<-dbConnect(drv,"jdbc:TAOS-RS://127.0.0.1:6041/test?user=root&password=taosdata","root","taosdata") + +# Get connection information +dbGetInfo(conn) + +# create database +dbSendUpdate(conn,"create database if not exists r_example_db keep 3650") + +# use db +dbSendUpdate(conn,"use r_example_db") +dbSendUpdate(conn,"create table if not exists test(ts timestamp,i8 tinyint,i16 smallint,i32 int,i64 bigint,bnry binary(50),nchr nchar(50)) tags(k int,v binary(20))") + +# insert data +dbSendUpdate(conn,"insert into test_s01 using test tags(1,'sub_01') values(now,1,2,3,4,'binary1','nchar1')(now+1s,5,6,7,8,'binary2','nchar2')(now+2s,9,0,1,2,'binary3','nchar3')") + +# View all tables +print("==============dbGetQuery==================") +table1<-dbGetQuery(conn,"select * from test") +print(table1) + +# Functional support for RJDBC + +# List all tables +print("=============dbListTables===================") +dbListTables(conn,"test%") + +print("=============dbExistsTable===================") +# Is there table "test" +dbExistsTable(conn,"test") + +# Connect summary information +print("=============summary===================") +summary(conn) +print("=============dbGetInfo===================") +dbGetInfo(conn) + + +# Read all the data from the test table +print("=============dbReadTable===================") +dbReadTable(conn,"test") + + +# Execute any non-query SQL statements +dbSendUpdate(conn, "create table if not exists t1(ts timestamp,id int,u nchar(40))") +dbGetTables(conn, "t") +sampleData=data.frame(ts=c('2022-03-22 00:00:00.000','2022-03-22 10:00:00.000'),id=c(1,2),u=c('涛思数据','TDengine')) +print("=============dbWriteTable===================") +dbWriteTable(conn, "t1", sampleData, overwrite=FALSE, append=TRUE) +dbReadTable(conn,"t1") + +# Delete table t1 +dbRemoveTable(conn,"t1") + +# Extracting data on demand using SQL statements +print("=============dbGetQuery===================") +dbGetQuery(conn, "select * from test_s01") + +# Drop database +dbSendUpdate(conn,"drop database if exists r_example_db") + +# Close the connection +print("=============dbDisconnect===================") +dbDisconnect(conn) + +print("***************************taos-jdbcDriver support RJDBC sample done*************************************") diff --git a/tests/develop-test/3-connectors/R/test.sh b/tests/develop-test/3-connectors/R/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..90b94893659f04328d7eaef810018bb6a13c8c09 --- /dev/null +++ b/tests/develop-test/3-connectors/R/test.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +function stopTaosd { + echo "Stop taosd" + sudo systemctl stop taosd || echo 'no sudo or systemctl or stop fail' + PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` + while [ -n "$PID" ] + do + pkill -TERM -x taosd + sleep 1 + PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` + done +} +stopTaosd +rm -rf /var/lib/taos/* +rm -rf /var/log/taos/* +nohup taosd -c /etc/taos/ > /dev/null 2>&1 & +sleep 10 +ls -al + +cd ../../ +WKC=`pwd` +#echo "WKC:${WKC}" + +JDBC_PATH=${WKC}'/src/connector/jdbc/' +CASE_PATH=${WKC}'/tests/examples/R/' +cd ${JDBC_PATH} +#echo "JDBC_PATH:${JDBC_PATH}" +#echo "CASE_PATH:${CASE_PATH}" + +mvn clean package -Dmaven.test.skip=true + +JDBC=`ls target|grep dist.jar` +JDBC_PATH=${JDBC_PATH}target + +#echo ${jdbc} +#echo ${jdbc_path} +cd ${WKC} + +# remove +Rscript ${CASE_PATH}rjdbc.sample.R ${JDBC_PATH} ${JDBC} diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index fc9a094b2d1f33254e39f0c6e1c1048a64f3ea39..0085d0fc601adcfcceffb12c31f9225918bc12f9 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -36,7 +36,7 @@ 83,,script,./test.sh -f general/parser/limit1_tblocks100.sim 82,,script,./test.sh -f general/parser/limit1.sim 82,,pytest,python3 test.py -f query/last_row_cache.py -81,,develop-test,timeout 180 bash 3-connectors/c#/test.sh +81,,develop-test,timeout 180 bash 3-connectors/c#/test.sh 80,,develop-test,timeout 180 bash 3-connectors/nodejs/test.sh 79,,script,./test.sh -f general/db/alter_tables_v4.sim 79,,pytest,python3 test.py -f insert/verifyMemToDiskCrash.py @@ -803,3 +803,4 @@ 1,,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/demo.py 8,,pytest,python3 test.py -f update/update2.py 4,,pytest,python3 test.py -f insert/line_insert.py +80,,develop-test,bash 3-connectors/R/test.sh