Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init #51

Merged
merged 17 commits into from
Apr 18, 2024
Merged

init #51

merged 17 commits into from
Apr 18, 2024

Conversation

menshibin
Copy link
Contributor

No description provided.


export class WsClient {
private _wsConnector?: WebSocketConnector;
private _req_id = 1000000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsued

Comment on lines 18 to 19
private _timeout?:number | undefined | null;
private _url:URL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly?

"@types/jest": "^29.2.1",
"@types/json-bigint": "^1.0.1",
"@types/node": "^18.0.0",
"@types/websocket": "^1.0npm install async-mutex.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong version

@@ -0,0 +1,61 @@
import { createHash } from 'crypto';
import { v4 as uuidv4 } from 'uuid';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uuid not found

}

export function readNchar(dataBuffer: ArrayBuffer, colDataHead: number, length: number): string {
let decoder = new TextDecoder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Comment on lines 20 to 22
export class TaosResultError extends TDWebSocketClientError{};
export class TaosError extends TDWebSocketClientError{};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary semicolon

ERR_WEBSOCKET_CONNECTION = 104,
ERR_WEBSOCKET_QUERY_TIMEOUT = 105,
ERR_INVALID_AUTHENTICATION = 106,
ERR_UNSPPORTED_TDENGINE_TYPE = 107,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo? unsupported?

try {
let wsFetchResponse = await this._wsClient.fetch(this._wsQueryResponse);
console.log("[wsQuery.execute.wsFetchResponse]==>\n", wsFetchResponse)
if (wsFetchResponse.completed == true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to wsFetchResponse.completed

}

this._taosResult = await this.getBlockData();
if (this._taosResult.GetData() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'if' statement can be simplified

try{
while (true) {
let wsFetchResponse = await this._wsClient.fetch(wsQueryResponse)
if (wsFetchResponse.completed == true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to wsFetchResponse.completed

let err :any = e
throw new TaosResultError(err.code, err.message);
} finally {
this._wsClient.freeResult(wsQueryResponse)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing await for an async function call ?

user: string;
password: string;
group_id: string;
clien_id: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?


}

export class CommitedResp extends PartitionsResp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

var taosResults: Map<string, TaosResult> = new Map();
let resp = await this._wsClient.exec(JSON.stringify(queryMsg), false);
let pollResp = new WsPollResponse(resp)
if (pollResp.have_message == false || pollResp.message_type != TMQMessageType.ResDataType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to !pollResp.have_message

// count++
let fetchResp = await this.fetch(pollResp)
if (fetchResp.completed || fetchResp.rows == 0) {
let currTime = new Date().getTime();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

private static _instance?:WebSocketConnectionPool;
private pool: Map<string, WebSocketConnector[]> = new Map();
private _connectionCount: number;
private _maxConnections: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly?

return
}
this._isClose = true
this._wsClient.freeResult(this._wsQueryResponse)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need .then()?


export class WSRows {
private _wsClient: WsClient;
private _wsQueryResponse: WSQueryResponse;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly?

let result = await wsRows.GetData();
console.log('queryRes.Scan().then=>', result);
}
await wsRows.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrRows.Close is a synchronous function

Comment on lines 132 to 133
let tmp: TaosResult = await this._wsClient.fetchBlock(wsFetchResponse, taosResult);
taosResult = tmp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is redundant

Comment on lines 20 to 21
private precisionLength:number = PrecisionLength['ms']
private _params: ColumnInfo[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly?

Copy link
Contributor

@huskar-t huskar-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments

public GetTotalTime() {
return this._totalTime;
}
public AddtotalTime(totalTime:number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddtotalTime -> AddTotalTime

@huskar-t
Copy link
Contributor

need to format and add automatic tests

import { sqlConnect } from '../index';
let dsn = 'ws://root:[email protected]:6051/ws';
let db = 'power'
let influxdbData = "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尽量使用 meters 表做用例

import { WSConfig } from '../src/common/config';
import { sqlConnect } from '../index'

let dsn = 'ws://root:[email protected]:6051/ws';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后的 ws 是数据库吗,如果不是,是端点,不要体现出来,Adapter 的 路径对外不可见

[TMQConstants.CONNECT_PASS, "taosdata"],
[TMQConstants.AUTO_OFFSET_RESET, "earliest"],
[TMQConstants.CLIENT_ID, 'test_tmq_client'],
[TMQConstants.WS_URL, 'ws://192.168.1.95:6051/rest/tmq'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest/tmq 不要暴露

- **host/port**: Declare host and port. eg. `localhost:6041`
- **database**: Optional, use to specify database name.
- **params**: Other parameters. Like cloud Token.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dsn 定义是对的,严格按照这个来解析


``` typescript
import {connect} from '@tdengine/websocket'
let dsn = "ws://host:port/rest/ws/db"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里跟上面 dsn 对不上

})
}

async execute(sql: string, reqId?: number, action:string = 'query'): Promise<TaosResult> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schemaless 不支持sql

}


private encodeColumnNumbers(params:any[], dataType:string = 'number', typeLen:number, columnType:number):[number, ArrayBuffer] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方法名好像只处理 number 类型

// let count = 0
// let startTime = new Date().getTime();
while (true) {
// count++
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无用代码都应该删除,不要注释掉

for (let i = 0; i < actualData.length; i++) {
actualData[i].forEach((d, index) => {
if (expectMeta[index].name == 'geo' || expectMeta[index].name == 'vbinary') {
expect(d).toBeTruthy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为何这两种类型没有仔细检查?

wsSchemaless.Close();
});

test('normal wsSql insert', async() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里都没有check

@menshibin menshibin merged commit ed3b566 into main Apr 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants