Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dcda284f
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
dcda284f
编写于
10月 09, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
10月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3767 from taosdata/feature/TD-1476
[TD-1476]<feature>: a demo for calcite
上级
15b6b2c4
a6107d1d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
126 addition
and
0 deletion
+126
-0
tests/examples/JDBC/calciteDemo/pom.xml
tests/examples/JDBC/calciteDemo/pom.xml
+53
-0
tests/examples/JDBC/calciteDemo/src/main/java/com/taosdata/example/calcite/CalciteDemo.java
...c/main/java/com/taosdata/example/calcite/CalciteDemo.java
+67
-0
tests/examples/JDBC/calciteDemo/src/main/resources/log4j.properties
...ples/JDBC/calciteDemo/src/main/resources/log4j.properties
+6
-0
未找到文件。
tests/examples/JDBC/calciteDemo/pom.xml
0 → 100644
浏览文件 @
dcda284f
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.taosdata.example.calcite
</groupId>
<artifactId>
calciteDemo
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<dependencies>
<!-- slf4j -->
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-simple
</artifactId>
<version>
1.7.25
</version>
<scope>
compile
</scope>
</dependency>
<!-- calcite -->
<dependency>
<groupId>
org.apache.calcite
</groupId>
<artifactId>
calcite-core
</artifactId>
<version>
1.23.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-dbcp2
</artifactId>
<version>
2.7.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.calcite.avatica
</groupId>
<artifactId>
avatica-core
</artifactId>
<version>
1.17.0
</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.47
</version>
</dependency>
<!-- tdengine -->
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.7
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
tests/examples/JDBC/calciteDemo/src/main/java/com/taosdata/example/calcite/CalciteDemo.java
0 → 100644
浏览文件 @
dcda284f
package
com.taosdata.example.calcite
;
import
org.apache.calcite.adapter.jdbc.JdbcSchema
;
import
org.apache.calcite.jdbc.CalciteConnection
;
import
org.apache.calcite.schema.Schema
;
import
org.apache.calcite.schema.SchemaPlus
;
import
org.apache.calcite.sql.parser.SqlParseException
;
import
org.apache.commons.dbcp2.BasicDataSource
;
import
java.sql.*
;
import
java.util.Properties
;
public
class
CalciteDemo
{
private
static
String
url_taos
=
"jdbc:TAOS://192.168.236.135:6030/test"
;
private
static
String
url_mysql
=
"jdbc:mysql://master:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8"
;
public
static
void
main
(
String
[]
args
)
throws
SqlParseException
,
ClassNotFoundException
,
SQLException
{
Class
.
forName
(
"org.apache.calcite.jdbc.Driver"
);
Properties
info
=
new
Properties
();
info
.
setProperty
(
"caseSensitive"
,
"false"
);
Connection
connection
=
DriverManager
.
getConnection
(
"jdbc:calcite:"
,
info
);
CalciteConnection
calciteConnection
=
connection
.
unwrap
(
CalciteConnection
.
class
);
SchemaPlus
rootSchema
=
calciteConnection
.
getRootSchema
();
//这里hdb是在tdengine中创建的数据库名
Schema
schema
=
mysqlTest
(
rootSchema
);
// Schema schema = tdengineTest(rootSchema);
//创建新的schema自动映射到原来的hdb数据库
rootSchema
.
add
(
"test"
,
schema
);
Statement
stmt
=
calciteConnection
.
createStatement
();
//查询schema test中的表,表名是tdengine中的表
ResultSet
rs
=
stmt
.
executeQuery
(
"select * from test.t"
);
ResultSetMetaData
metaData
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
System
.
out
.
println
(
metaData
.
getColumnLabel
(
i
)
+
" : "
+
rs
.
getString
(
i
));
}
}
}
private
static
Schema
tdengineTest
(
SchemaPlus
rootSchema
)
throws
ClassNotFoundException
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
BasicDataSource
dataSource
=
new
BasicDataSource
();
dataSource
.
setUrl
(
url_taos
);
dataSource
.
setUsername
(
"root"
);
dataSource
.
setPassword
(
"taosdata"
);
return
JdbcSchema
.
create
(
rootSchema
,
"test"
,
dataSource
,
"hdb"
,
null
);
}
private
static
Schema
mysqlTest
(
SchemaPlus
rootSchema
)
throws
ClassNotFoundException
{
Class
.
forName
(
"com.mysql.jdbc.Driver"
);
BasicDataSource
dataSource
=
new
BasicDataSource
();
dataSource
.
setUrl
(
url_mysql
);
dataSource
.
setUsername
(
"root"
);
dataSource
.
setPassword
(
"123456"
);
//Schema schema = JdbcSchema.create(rootSchema, "test", dataSource, "hdb", null);
return
JdbcSchema
.
create
(
rootSchema
,
"test"
,
dataSource
,
"test"
,
null
);
}
}
tests/examples/JDBC/calciteDemo/src/main/resources/log4j.properties
0 → 100644
浏览文件 @
dcda284f
log4j.rootLogger
=
info,stdout
#console
log4j.appender.stdout
=
org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout
=
org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern
=
[%d{yyyy-MM-dd HH:mm:ss a}]:%p %l%m%n
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录