Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
402748d9
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
402748d9
编写于
5月 14, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-3776]<fix>set time precision after parsing and JNI time precision minor change
上级
4066fb7c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
123 addition
and
28 deletion
+123
-28
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
+3
-3
src/client/src/TSDBJNIConnector.c
src/client/src/TSDBJNIConnector.c
+14
-4
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+4
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+10
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
...src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
+28
-14
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
...src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
+64
-7
未找到文件。
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
浏览文件 @
402748d9
...
...
@@ -51,10 +51,10 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getTsCharset
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: getResultTimePrecision
* Signature: (J
)J
* Method: getResultTimePrecision
Imp
* Signature: (J
J)I
*/
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TDDBJNIConnector_getResultTimePrecision
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TDDBJNIConnector_getResultTimePrecision
Imp
(
JNIEnv
*
,
jobject
,
jlong
,
jlong
);
/*
...
...
src/client/src/TSDBJNIConnector.c
浏览文件 @
402748d9
...
...
@@ -113,7 +113,7 @@ static void jniGetGlobalMethod(JNIEnv *env) {
g_rowdataSetFloatFp
=
(
*
env
)
->
GetMethodID
(
env
,
g_rowdataClass
,
"setFloat"
,
"(IF)V"
);
g_rowdataSetDoubleFp
=
(
*
env
)
->
GetMethodID
(
env
,
g_rowdataClass
,
"setDouble"
,
"(ID)V"
);
g_rowdataSetStringFp
=
(
*
env
)
->
GetMethodID
(
env
,
g_rowdataClass
,
"setString"
,
"(ILjava/lang/String;)V"
);
g_rowdataSetTimestampFp
=
(
*
env
)
->
GetMethodID
(
env
,
g_rowdataClass
,
"setTimestamp"
,
"(IJ)V"
);
g_rowdataSetTimestampFp
=
(
*
env
)
->
GetMethodID
(
env
,
g_rowdataClass
,
"setTimestamp"
,
"(IJ
I
)V"
);
g_rowdataSetByteArrayFp
=
(
*
env
)
->
GetMethodID
(
env
,
g_rowdataClass
,
"setByteArray"
,
"(I[B)V"
);
(
*
env
)
->
DeleteLocalRef
(
env
,
rowdataClass
);
...
...
@@ -519,9 +519,11 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
jniFromNCharToByteArray
(
env
,
(
char
*
)
row
[
i
],
length
[
i
]));
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetTimestampFp
,
i
,
(
jlong
)
*
((
int64_t
*
)
row
[
i
]));
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
int
precision
=
taos_result_precision
(
result
);
(
*
env
)
->
CallVoidMethod
(
env
,
rowobj
,
g_rowdataSetTimestampFp
,
i
,
(
jlong
)
*
((
int64_t
*
)
row
[
i
]),
precision
);
break
;
}
default:
break
;
}
...
...
@@ -672,7 +674,15 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getTsCharset(J
return
(
*
env
)
->
NewStringUTF
(
env
,
(
const
char
*
)
tsCharset
);
}
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TDDBJNIConnector_getResultTimePrecision
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
/**
* Get Result Time Precision
* @param env vm
* @param jobj the TSDBJNIConnector java object
* @param con the c connection pointer
* @param res the TAOS_RES object, i.e. the SSqlObject
* @return precision 0:ms 1:us 2:ns
*/
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getResultTimePrecisionImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jlong
res
)
{
TAOS
*
tscon
=
(
TAOS
*
)
con
;
if
(
tscon
==
NULL
)
{
...
...
src/client/src/tscSQLParser.c
浏览文件 @
402748d9
...
...
@@ -772,6 +772,10 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pCmd
->
active
=
pCmd
->
pQueryInfo
;
pCmd
->
command
=
pCmd
->
pQueryInfo
->
command
;
if
(
pTableMetaInfo
->
pTableMeta
!=
NULL
)
{
pSql
->
res
.
precision
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
).
precision
;
}
return
TSDB_CODE_SUCCESS
;
// do not build query message here
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
402748d9
...
...
@@ -216,6 +216,16 @@ public class TSDBJNIConnector {
private
native
int
fetchBlockImp
(
long
connection
,
long
resultSet
,
TSDBResultSetBlockData
blockData
);
/**
* Get Result Time Precision.
* @return 0: ms, 1: us, 2: ns
*/
public
int
getResultTimePrecision
(
long
sqlObj
)
{
return
this
.
getResultTimePrecisionImp
(
this
.
taos
,
sqlObj
);
}
private
native
int
getResultTimePrecisionImp
(
long
connection
,
long
result
);
/**
* Execute close operation from C to release connection pointer by JNI
*
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
浏览文件 @
402748d9
...
...
@@ -414,26 +414,40 @@ public class TSDBResultSetRowData {
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setTimestampValue
(
int
colIndex
,
long
value
)
{
setTimestamp
(
colIndex
-
1
,
value
);
setTimestamp
(
colIndex
-
1
,
value
,
0
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
* @param precision 0 : ms, 1 : us, 2 : ns
*/
public
void
setTimestamp
(
int
col
,
long
ts
)
{
//TODO: this implementation contains logical error
// when precision is us the (long ts) is 16 digital number
// when precision is ms, the (long ts) is 13 digital number
// we need a JNI function like this:
// public void setTimestamp(int col, long epochSecond, long nanoAdjustment)
if
(
ts
<
1_0000_0000_0000_0L
)
{
data
.
set
(
col
,
new
Timestamp
(
ts
));
}
else
{
long
epochSec
=
ts
/
1000_000
l
;
long
nanoAdjustment
=
ts
%
1000_000
l
*
1000
l
;
Timestamp
timestamp
=
Timestamp
.
from
(
Instant
.
ofEpochSecond
(
epochSec
,
nanoAdjustment
));
data
.
set
(
col
,
timestamp
);
public
void
setTimestamp
(
int
col
,
long
ts
,
int
precision
)
{
long
milliseconds
=
0
;
int
fracNanoseconds
=
0
;
switch
(
precision
)
{
case
0
:
{
milliseconds
=
ts
;
fracNanoseconds
=
(
int
)(
ts
*
1_000_000
%
1_000_000_000
);
break
;
}
case
1
:
{
milliseconds
=
ts
/
1_000
;
fracNanoseconds
=
(
int
)(
ts
*
1_000
%
1_000_000_000
);
break
;
}
case
2
:
{
milliseconds
=
ts
/
1_000_000
;
fracNanoseconds
=
(
int
)(
ts
%
1_000_000_000
);
break
;
}
default
:
{
throw
new
IllegalArgumentException
(
"precision is not valid. precision: "
+
precision
);
}
}
Timestamp
tsObj
=
new
Timestamp
(
milliseconds
);
tsObj
.
setNanos
(
fracNanoseconds
);
data
.
set
(
col
,
tsObj
);
}
public
Timestamp
getTimestamp
(
int
col
,
int
nativeType
)
{
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
浏览文件 @
402748d9
package
com.taosdata.jdbc
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
java.sql.SQLException
;
import
java.sql.SQLWarning
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.RuntimeMXBean
;
import
java.lang.management.ThreadMXBean
;
public
class
TSDBJNIConnectorTest
{
private
static
TSDBResultSetRowData
rowData
;
...
...
@@ -14,17 +19,68 @@ public class TSDBJNIConnectorTest {
@Test
public
void
test
()
{
try
{
try
{
//change sleepSeconds when debugging with attach to process to find PID
int
sleepSeconds
=
-
1
;
if
(
sleepSeconds
>
0
)
{
RuntimeMXBean
runtimeBean
=
ManagementFactory
.
getRuntimeMXBean
();
String
jvmName
=
runtimeBean
.
getName
();
long
pid
=
Long
.
valueOf
(
jvmName
.
split
(
"@"
)[
0
]);
System
.
out
.
println
(
"JVM PID = "
+
pid
);
Thread
.
sleep
(
sleepSeconds
*
1000
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// init
TSDBJNIConnector
.
init
(
"/etc/taos/taos.cfg"
,
null
,
null
,
null
);
TSDBJNIConnector
.
init
(
"/etc/taos"
,
null
,
null
,
null
);
// connect
TSDBJNIConnector
connector
=
new
TSDBJNIConnector
();
connector
.
connect
(
"127.0.0.1"
,
6030
,
"unsign_jni"
,
"root"
,
"taosdata"
);
connector
.
connect
(
"127.0.0.1"
,
6030
,
null
,
"root"
,
"taosdata"
);
// setup
String
setupSqlStrs
[]
=
{
"create database if not exists d precision \"us\""
,
"create table if not exists d.t(ts timestamp, f int)"
,
"create database if not exists d2"
,
"create table if not exists d2.t2(ts timestamp, f int)"
,
"insert into d.t values(now+100s, 100)"
,
"insert into d2.t2 values(now+200s, 200)"
};
for
(
String
setupSqlStr
:
setupSqlStrs
)
{
long
setupSql
=
connector
.
executeQuery
(
setupSqlStr
);
assertEquals
(
0
,
connector
.
getResultTimePrecision
(
setupSql
));
if
(
connector
.
isUpdateQuery
(
setupSql
))
{
connector
.
freeResultSet
(
setupSql
);
}
}
{
long
sqlObj1
=
connector
.
executeQuery
(
"select * from d2.t2"
);
assertEquals
(
0
,
connector
.
getResultTimePrecision
(
sqlObj1
));
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
int
code
=
connector
.
getSchemaMetaData
(
sqlObj1
,
columnMetaDataList
);
rowData
=
new
TSDBResultSetRowData
(
columnMetaDataList
.
size
());
assertTrue
(
next
(
connector
,
sqlObj1
));
assertEquals
(
0
,
connector
.
getResultTimePrecision
(
sqlObj1
));
connector
.
freeResultSet
(
sqlObj1
);
}
// executeQuery
long
pSql
=
connector
.
executeQuery
(
"select * from unsign_jni.us_table"
);
long
pSql
=
connector
.
executeQuery
(
"select * from d.t"
);
if
(
connector
.
isUpdateQuery
(
pSql
))
{
connector
.
freeResultSet
(
pSql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_WITH_EXECUTEQUERY
);
}
assertEquals
(
1
,
connector
.
getResultTimePrecision
(
pSql
));
// get schema
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>();
int
code
=
connector
.
getSchemaMetaData
(
pSql
,
columnMetaDataList
);
...
...
@@ -37,6 +93,8 @@ public class TSDBJNIConnectorTest {
if
(
code
==
TSDBConstants
.
JNI_NUM_OF_FIELDS_0
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_NUM_OF_FIELDS_0
);
}
assertEquals
(
1
,
connector
.
getResultTimePrecision
(
pSql
));
int
columnSize
=
columnMetaDataList
.
size
();
// print metadata
for
(
int
i
=
0
;
i
<
columnSize
;
i
++)
{
...
...
@@ -45,9 +103,8 @@ public class TSDBJNIConnectorTest {
rowData
=
new
TSDBResultSetRowData
(
columnSize
);
// iterate resultSet
for
(
int
i
=
0
;
next
(
connector
,
pSql
);
i
++)
{
// System.out.println("col[" + i + "] size: " + rowData.getColSize());
// rowData.getData().stream().forEach(col -> System.out.print(col + "\t"));
// System.out.println();
assertEquals
(
1
,
connector
.
getResultTimePrecision
(
pSql
));
System
.
out
.
println
();
}
// close resultSet
code
=
connector
.
freeResultSet
(
pSql
);
...
...
@@ -86,4 +143,4 @@ public class TSDBJNIConnectorTest {
}
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录