Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
8a39f899
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8a39f899
编写于
9月 15, 2020
作者:
Z
zyyang-taosdata
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add calcite test case
上级
99741286
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
47 deletion
+44
-47
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/cases/CalciteTest.java
...bc/src/main/java/com/taosdata/jdbc/cases/CalciteTest.java
+43
-46
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
8a39f899
...
...
@@ -242,7 +242,7 @@ public class TSDBStatement implements Statement {
public
void
addBatch
(
String
sql
)
throws
SQLException
{
if
(
batchedArgs
==
null
)
{
batchedArgs
=
new
ArrayList
<
String
>();
batchedArgs
=
new
ArrayList
<>();
}
batchedArgs
.
add
(
sql
);
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/cases/CalciteTest.java
浏览文件 @
8a39f899
...
...
@@ -7,17 +7,35 @@ import org.apache.calcite.sql.parser.SqlParseException;
import
org.apache.commons.dbcp2.BasicDataSource
;
import
java.sql.*
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
public
class
CalciteTest
{
public
static
void
main
(
String
[]
args
)
throws
SqlParseException
,
ClassNotFoundException
,
SQLException
{
// CalciteConnection calciteConnection = testMyqsl();
CalciteConnection
calciteConnection
=
testTSDB
();
Statement
statement
=
calciteConnection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from test.t"
);
while
(
resultSet
.
next
())
{
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
String
columnLabel
=
metaData
.
getColumnLabel
(
i
);
System
.
out
.
println
(
columnLabel
+
" : "
+
resultSet
.
getString
(
i
));
}
}
resultSet
.
close
();
statement
.
close
();
calciteConnection
.
close
();
}
private
static
CalciteConnection
testMyqsl
()
throws
ClassNotFoundException
,
SQLException
{
//创建Calcite Connection对象
Class
.
forName
(
"org.apache.calcite.jdbc.Driver"
);
Properties
info
=
new
Properties
();
info
.
setProperty
(
"lex"
,
"JAVA"
);
info
.
setProperty
(
"caseSensitive"
,
"false"
);
Connection
connection
=
DriverManager
.
getConnection
(
"jdbc:calcite:"
,
info
);
CalciteConnection
calciteConnection
=
connection
.
unwrap
(
CalciteConnection
.
class
);
...
...
@@ -26,55 +44,34 @@ public class CalciteTest {
// JDBC adapter
Class
.
forName
(
"com.mysql.jdbc.Driver"
);
BasicDataSource
dataSource
=
new
BasicDataSource
();
dataSource
.
setUrl
(
"jdbc:mysql://192.168.
56.101:3306
"
);
dataSource
.
setUrl
(
"jdbc:mysql://192.168.
236.135:3306/test
"
);
dataSource
.
setUsername
(
"root"
);
dataSource
.
setPassword
(
"123456"
);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
JdbcSchema
schema
=
JdbcSchema
.
create
(
rootSchema
,
"hr"
,
dataSource
,
null
,
null
);
rootSchema
.
add
(
"hr"
,
schema
);
Statement
statement
=
calciteConnection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
"select * from hr.depts"
);
while
(
resultSet
.
next
())
{
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
String
columnLabel
=
metaData
.
getColumnLabel
(
i
);
System
.
out
.
println
(
columnLabel
+
" : "
+
resultSet
.
getString
(
i
));
}
}
resultSet
.
close
();
statement
.
close
();
connection
.
close
();
JdbcSchema
schema
=
JdbcSchema
.
create
(
rootSchema
,
"test"
,
dataSource
,
null
,
"test"
);
rootSchema
.
add
(
"test"
,
schema
);
return
calciteConnection
;
}
//创建TDengine的数据源schema
// Class.forName("com.taosdata.jdbc.TSDBDriver");
// String url = "jdbc:TAOS://127.0.0.1:6030/hdb";
// dataSource.setUrl(url);
// dataSource.setUsername("root");
// dataSource.setPassword("taosdata");
private
static
CalciteConnection
testTSDB
()
throws
SQLException
,
ClassNotFoundException
{
//创建Calcite Connection对象
Class
.
forName
(
"org.apache.calcite.jdbc.Driver"
);
Properties
info
=
new
Properties
();
info
.
setProperty
(
"lex"
,
"JAVA"
);
info
.
setProperty
(
"caseSensitive"
,
"false"
);
Connection
connection
=
DriverManager
.
getConnection
(
"jdbc:calcite:"
,
info
);
CalciteConnection
calciteConnection
=
connection
.
unwrap
(
CalciteConnection
.
class
);
SchemaPlus
rootSchema
=
calciteConnection
.
getRootSchema
();
// Class.forName("com.mysql.jdbc.Driver");
// String url = "jdbc:mysql://localhost:3306/hdb";
// BasicDataSource dataSource = new BasicDataSource();
// dataSource.setUrl(url);
// dataSource.setUsername("root");
// dataSource.setPassword("123456");
//这里hdb是在tdengine中创建的数据库名
// JdbcSchema schema = JdbcSchema.create(rootSchema, "test", dataSource, null, "test");
// Schema schema = JdbcSchema.create(rootSchema, "test", dataSource, "hdb", null);
//创建新的schema自动映射到原来的hdb数据库
// rootSchema.add("test", schema);
// JDBC adapter
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
BasicDataSource
dataSource
=
new
BasicDataSource
();
dataSource
.
setUrl
(
"jdbc:TAOS://192.168.236.135:6030/test"
);
dataSource
.
setUsername
(
"root"
);
dataSource
.
setPassword
(
"taosdata"
);
JdbcSchema
schema
=
JdbcSchema
.
create
(
rootSchema
,
"test"
,
dataSource
,
null
,
"test"
);
rootSchema
.
add
(
"test"
,
schema
);
// Statement stmt = calciteConnection.createStatement();
//查询schema test中的表,表名是tdengine中的表
// ResultSet rs = stmt.executeQuery("select * from test.t");
// for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
// System.out.println(rs.getMetaData().getColumnName(i));
// }
// while (rs.next()) {
// System.out.println(rs.getObject(1));
// }
return
calciteConnection
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录