test.cases.js 30.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
// const { testMatch } = require('../../jest.config');
const taos = require('../../tdengine');
const { getFeildsFromDll, buildInsertSql, getFieldArr, getResData } = require('../utils/utilTools')

const author = 'xiaolei';
const result = 'passed';
const fileName = __filename.slice(__dirname.length + 1);

// This is a taos connection
let conn;
// This is a Cursor
let c1;

function executeUpdate(sql) {
  console.log(sql);
  c1.execute(sql);
}

function executeQuery(sql) {
  c1.execute(sql, { quiet: true })
  var data = c1.fetchall();
  let fields = c1.fields;
  let resArr = [];

  data.forEach(row => {
    row.forEach(data => {
      if (data instanceof Date) {
        // console.log("date obejct:"+data.valueOf());
        resArr.push(data.taosTimestamp());
      } else {
        // console.log("not date:"+data);
        resArr.push(data);
      }
      // console.log(data instanceof Date)
    })
  })
  return { resData: resArr, resFeilds: fields };
}

beforeAll(() => {
  conn = taos.connect({ host: "127.0.0.1", user: "root", password: "taosdata", config: "/etc/taos", port: 10 });
  c1 = conn.cursor();
  executeUpdate("create database if not exists node_test_db keep 3650;");
  executeUpdate("use node_test_db;");
});

// Clears the database and adds some testing data.
// Jest will wait for this promise to resolve before running tests.
afterAll(() => {
  executeUpdate("drop database if exists node_test_db;");
  conn.close();
});

describe("test unsigned type", () => {

  test(`name:test unsinged tinnyint ntable;` +
    `author:${author};` +
    `desc:create,insert,query with unsigned tinnyint;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists utinnytest(ts timestamp,ut tinyint unsigned,i4 int,rownum nchar(20));";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = [1641827743305, 254, 124, 'row1'
        , 1641827743306, 0, -123, 'row2'
        , 1641827743307, 54, 0, 'row3'];
      let insertSql = buildInsertSql('utinnytest', '', expectResData, [], 4);

      executeUpdate(insertSql);
      let result = executeQuery("select * from utinnytest;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

  test(`name:test unsinged smallint ntable;` +
    `author:${author};` +
    `desc:create,insert,query with unsigned smallint;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists usmalltest(ts timestamp,ut smallint unsigned,i4 int,rownum nchar(20));";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = [1641827743305, 65534, 124, 'row1', 1641827743306, 0, -123, 'row2', 1641827743307, 79, 0, 'row3'];
      let insertSql = buildInsertSql('usmalltest', '', expectResData, [], 4);

      executeUpdate(insertSql);
      let result = executeQuery("select * from usmalltest;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

  test(`name:test unsinged int ntable;` +
    `author:${author};` +
    `desc:create,insert,query with unsigned int;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists uinttest(ts timestamp,ui int unsigned,i4 int,rownum nchar(20));";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = [1641827743305, 4294967294, 2147483647, 'row1', 1641827743306, 0, -2147483647, 'row2', 1641827743307, 105, 0, 'row3'];
      let insertSql = buildInsertSql('uinttest', '', expectResData, [], 4);

      executeUpdate(insertSql);
      let result = executeQuery("select * from uinttest;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

  test(`name:test unsinged bigint ntable;` +
    `author:${author};` +
    `desc:create,insert,query with unsigned bigint;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists ubigtest(ts timestamp,ui bigint unsigned,i8 bigint,rownum nchar(20));";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = [1641827743305, 18446744073709551614n, 9223372036854775807n, 'row1',
        1641827743306, 0n, -9223372036854775807n, 'row2',
        1641827743307, 130n, 0n, 'row3'];
      let insertSql = buildInsertSql('ubigtest', '', expectResData, [], 4);

      executeUpdate(insertSql);
      let result = executeQuery("select * from ubigtest;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

  test(`name:test unsinged type ntable;` +
    `author:${author};` +
    `desc:create,insert,query with mutiple unsinged type;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists unsigntest(ts timestamp,ut tinyint unsigned,us smallint unsigned,ui int unsigned,ub bigint unsigned,bi bigint);";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = [1641827743305, 254, 65534, 4294967294, 18446744073709551614n, 9223372036854775807n,
        1641827743306, 0, 0, 0, 0n, -9223372036854775807n];
      let insertSql = buildInsertSql('unsigntest', '', expectResData, [], 6);

      executeUpdate(insertSql);
      let result = executeQuery("select * from unsigntest;");
      // console.log(`result.data:${result.resData}`);
      // console.log(`result.feilds:${result.resFeilds}`);
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

  test(`name:test unsinged type stable max value;` +
    `author:${author};` +
    `desc:this is a description;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists max_unsigned_tag_test" +
        "(ts timestamp" +
        ",ut tinyint unsigned" +
        ",us smallint unsigned" +
        ",ui int unsigned" +
        ",ub bigint unsigned" +
        ",bi bigint)" +
        "tags(" +
        "ut1 tinyint unsigned" +
        ",us2 smallint unsigned" +
        ",ui4 int unsigned" +
        ",ubi8 bigint unsigned" +
225
        ",desc_nchr nchar(200)" +
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
        ");";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData = [1641827743305, 254, 65534, 4294967294, 18446744073709551614n, 9223372036854775807n,
        1641827743306, 0, 0, 0, 0n, -9223372036854775807n,
        1641827743307, 201, 44, 2, 8n, 1531n];
      let tagData = [254, 65534, 4294967294, 18446744073709551614n, 'max value of unsinged type tag']
      let insertSql = buildInsertSql('max_unsigned_tag_test_sub1', 'max_unsigned_tag_test', colData, tagData, 6);
      let expectResData = getResData(colData, tagData, 6);

      executeUpdate(insertSql);
      let result = executeQuery("select * from max_unsigned_tag_test;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

  test(`name:test unsinged type stable minimal value;` +
    `author:${author};` +
    `desc:this is a description;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists min_unsigned_tag_test" +
        "(ts timestamp" +
        ",ut tinyint unsigned" +
        ",us smallint unsigned" +
        ",ui int unsigned" +
        ",ub bigint unsigned" +
        ",bi bigint)" +
        "tags(" +
        "ut1 tinyint unsigned" +
        ",us2 smallint unsigned" +
        ",ui4 int unsigned" +
        ",ubi8 bigint unsigned" +
271
        ",desc_nchr nchar(200)" +
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
        ");";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData = [1641827743305, 254, 65534, 4294967294, 18446744073709551614n, 9223372036854775807n,
        1641827743306, 0, 0, 0, 0n, -9223372036854775807n,
        1641827743307, 201, 44, 2, 8n, 1531n];
      let tagData = [0, 0, 0, 0n, 'minimal value of unsinged type tag']
      let insertSql = buildInsertSql('min_unsigned_tag_test_sub1', 'min_unsigned_tag_test', colData, tagData, 6);
      let expectResData = getResData(colData, tagData, 6);

      executeUpdate(insertSql);
      let result = executeQuery("select * from min_unsigned_tag_test;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      console.log("expectResData.length:" + expectResData.length + " actualResData.length:" + actualResData.length);
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

  test(`name:test unsinged type stable mixed value;` +
    `author:${author};` +
    `desc:this is a description;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let createSql = "create table if not exists mix_unsigned_tag_test" +
        "(ts timestamp" +
        ",ut tinyint unsigned" +
        ",us smallint unsigned" +
        ",ui int unsigned" +
        ",ub bigint unsigned" +
        ",bi bigint)" +
        "tags(" +
        "ut1 tinyint unsigned" +
        ",us2 smallint unsigned" +
        ",ui4 int unsigned" +
        ",ubi8 bigint unsigned" +
318
        ",desc_nchr nchar(200)" +
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
        ");";
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData = [1641827743305, 254, 65534, 4294967294, 18446744073709551614n, 9223372036854775807n,
        1641827743306, 0, 0, 0, 0n, -9223372036854775807n,
        1641827743307, 201, 44, 2, 8n, 1531n];
      let tagData = [1, 20, 300, 4000n, 'mixed value of unsinged type tag']
      let insertSql = buildInsertSql('mix_unsigned_tag_test_sub1', 'mix_unsigned_tag_test', colData, tagData, 6);
      let expectResData = getResData(colData, tagData, 6);

      executeUpdate(insertSql);
      let result = executeQuery("select * from mix_unsigned_tag_test;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    });

})

describe("test cn character", () => {
  test(`name:test cn ntable;` +
    `author:${author};` +
    `desc:create,insert,query with cn characters;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      createSql = "create table if not exists nchartest(ts timestamp,value int,text binary(200),detail nchar(200));"
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = [1641827743305, 1, 'taosdata', 'tdengine'
        , 1641827743306, 2, 'tasdata', '涛思数据'
        , 1641827743307, 3, '涛思数据', 'tdengine'
        , 1641827743308, 4, '涛思数据taosdata', 'tdengine'
        , 1641827743309, 5, '涛思数据taosdata', 'tdengine涛思数据'];
      let insertSql = buildInsertSql('nchartest', '', expectResData, [], 4);

      executeUpdate(insertSql);
      let result = executeQuery("select * from nchartest;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });
      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    })

  test(`name:test cn stable;` +
    `author:${author};` +
    `desc:create,insert,query with cn characters;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
387
      createSql = "create table if not exists nchartest_s(ts timestamp,value int,text binary(200),detail nchar(200))tags(tag_bi binary(50),tag_nchr nchar(50));"
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData = [1641827743305, 1, 'taosdata', 'tdengine'
        , 1641827743306, 2, 'tasdata', '涛思数据'
        , 1641827743307, 3, '涛思数据', 'tdengine'
        , 1641827743308, 4, '涛思数据taosdata', 'tdengine'
        , 1641827743309, 5, '涛思数据taosdata', 'tdengine涛思数据'];
      let tagData = ['tags涛思', '数据tags'];
      let insertSql = buildInsertSql('sb_1', 'nchartest_s', colData, tagData, 4);
      let expectResData = getResData(colData, tagData, 4);

      executeUpdate(insertSql);
      let result = executeQuery("select * from nchartest_s;");
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    })
})

describe("test schemaless", () => {
  test(`name:sml line protocal using string;` +
    `author:${author};` +
    `desc:using line protocal to schemaless insert with a string;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let stablename = 'line_protocal_string';
      createSql = `create table if not exists ${stablename}(ts timestamp,c1 bigint,c3 nchar(6),c2 bool,c4 double)`
        + `tags(t1 nchar(4),t2 nchar(4),t3 nchar(4));`

      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData = [1626006833639, 3n, 'passit', false, 4.000000000];
      let tagData = ['3i64', '4f64', '\"t3\"'];
      let expectResData = getResData(colData, tagData, 5);
      let lineStr = stablename + ",t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639";


      c1.schemalessInsert(lineStr, taos.SCHEMALESS_PROTOCOL.TSDB_SML_LINE_PROTOCOL, taos.SCHEMALESS_PRECISION.TSDB_SML_TIMESTAMP_MILLI_SECONDS);
      let result = executeQuery(`select * from ${stablename};`);
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    })

  test(`name:sml line protocal using Array;` +
    `author:${author};` +
    `desc:using line protocal to schemaless insert with an Array;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let stablename = 'line_protocol_arr';

      createSql = `create table if not exists ${stablename}(ts timestamp,c1 bigint,c3 nchar(10),c2 bool,c4 double,c5 double)`
        + `tags(t1 nchar(4),t2 nchar(4),t3 nchar(4),t4 nchar(4));`

      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData1 = [1626006833641, 3n, 'passitagin', true, 5, 5]
      let colData2 = [1626006833639, 3n, 'passit', false, 4, null];
      let tagData1 = ['4i64', '5f64', '\"t4\"', '5f64'];
      let tagData2 = ['3i64', '4f64', '\"t3\"', null];
      let expectResDataTable1 = getResData(colData1, tagData1, 6);
      let expectResDataTable2 = getResData(colData2, tagData2, 6);
      let expectResData = expectResDataTable1.concat(expectResDataTable2);

      let lineStr = [stablename + ",t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
      stablename + ",t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833641000000"
      ];

      c1.schemalessInsert(lineStr, taos.SCHEMALESS_PROTOCOL.TSDB_SML_LINE_PROTOCOL, taos.SCHEMALESS_PRECISION.TSDB_SML_TIMESTAMP_NANO_SECONDS);
      let result = executeQuery(`select * from ${stablename};`);
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    })

  test(`name:sml json protocal using string;` +
    `author:${author};` +
    `desc:using json protocal to schemaless insert with a json string;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let stablename = 'json_protocol_str';

      createSql = `create table if not exists ${stablename}(ts timestamp,value double)`
        + `tags(t1 bool,t2 bool,t3 double,t4 nchar(35));`

      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData1 = [1626006833000, 10]
      let tagData1 = [true, false, 10, '123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>'];
      let expectResData = getResData(colData1, tagData1, 2);

      let jsonStr = "{"
        + "\"metric\": \"" + stablename + "\","
        + "\"timestamp\": 1626006833000,"
        + "\"value\": 10,"
        + "\"tags\": {"
        + " \"t1\": true,"
        + "\"t2\": false,"
        + "\"t3\": 10,"
        + "\"t4\": \"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>\""
        + "}"
        + "}";

      c1.schemalessInsert(jsonStr, taos.SCHEMALESS_PROTOCOL.TSDB_SML_JSON_PROTOCOL, taos.SCHEMALESS_PRECISION.TSDB_SML_TIMESTAMP_MILLI_SECONDS);

      let result = executeQuery(`select * from ${stablename};`);
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    })

  test(`name:sml json protocal using Array;` +
    `author:${author};` +
    `desc:using json protocal to schemaless insert with a json array;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let stablename = 'json_protocol_arr';

      createSql = `create table if not exists ${stablename}(ts timestamp,value double)`
        + `tags(t1 bool,t2 bool,t3 double,t4 nchar(35));`

      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData1 = [1626006833000, 10]
      let tagData1 = [true, false, 10, '123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>'];
      let expectResData = getResData(colData1, tagData1, 2);

      let jsonArr = ["{"
        + "\"metric\": \"" + stablename + "\","
        + "\"timestamp\": 1626006833,"
        + "\"value\": 10,"
        + "\"tags\": {"
        + " \"t1\": true,"
        + "\"t2\": false,"
        + "\"t3\": 10,"
        + "\"t4\": \"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>\""
        + "}"
        + "}"
      ];

      c1.schemalessInsert(jsonArr, taos.SCHEMALESS_PROTOCOL.TSDB_SML_JSON_PROTOCOL, taos.SCHEMALESS_PRECISION.TSDB_SML_TIMESTAMP_SECONDS);

      let result = executeQuery(`select * from ${stablename};`);
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    })
})

describe("test support microsecond", () => {
  test(`name:ms support ntable;` +
    `author:${author};` +
    `desc:test normal table supports microseconds;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let db = 'nodejs_support_ms_ntable';
      let table = 'us_test_ntable';
      let expectResData = [1625801548423914, 1, 1625801548423914,
        1625801548423915, 2, 1625801548423914,
        1625801548423916, 3, 1625801548423914,
        1625801548423917, 4, 1625801548423914];

      let createDB = `create database if not exists ${db} keep 3650 precision \'us\';`;
      let createSql = `create table if not exists ${db}.${table} (ts timestamp, seq int,record_date timestamp);`;
      let dropDB = `drop database if exists ${db};`;
      let insertSql = buildInsertSql(db + '.' + table, '',expectResData, [], 3);
      let querySql = `select * from ${db}.${table};`;
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      
      executeUpdate(dropDB);
      executeUpdate(createDB);
      executeUpdate(createSql);
      executeUpdate(insertSql);
      let result = executeQuery(querySql);

      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
      executeUpdate(dropDB);

    });

  test(`name:ms support stable;` +
    `author:${author};` +
    `desc:test stable supports microseconds;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let db = 'nodejs_support_ms_stable';
      let stable = 'us_test_stable';
      let table = "sub_1";
      let colData = [1625801548423914, 1, 1625801548423914,
        1625801548423915, 2, 1625801548423914,
        1625801548423916, 3, 1625801548423914,
        1625801548423917, 4, 1625801548423914];
      let tagData = [1,1625801548423914];
      let createDB = `create database if not exists ${db} keep 3650 precision \'us\';`;
      let createSql = `create table if not exists ${db}.${stable} (ts timestamp,seq int,`+
      `record_date timestamp)tags(id int,htime timestamp);`;
      let dropDB = `drop database if exists ${db};`;
      let insertSql = buildInsertSql(db + '.' + table, db + '.' + stable, colData,tagData, 3);
      let querySql = `select * from ${db}.${stable};`;
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = getResData(colData, tagData, 3);
      
      executeUpdate(dropDB);
      executeUpdate(createDB);
      executeUpdate(createSql);
      executeUpdate(insertSql);
      let result = executeQuery(querySql);

      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
      executeUpdate(dropDB);
    })
})

describe("test support nanosecond", () => {
  test(`name:ns support ntable;` +
    `author:${author};` +
    `desc:test normal table supports nanoseconds;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let db = 'nodejs_support_ns_ntable';
      let table = 'ns_test_ntable';
      let expectResData = [1625801548423914100, 1, 1625801548423914
        ,1625801548423914200, 2, 1625801548423914
      ];

      let createDB = `create database if not exists ${db} keep 3650 precision \'ns\';`;
      let createSql = `create table if not exists ${db}.${table} (ts timestamp, seq int,record_date timestamp);`;
      let dropDB = `drop database if exists ${db};`;
      let insertSql = buildInsertSql(db + '.' + table, '',expectResData, [], 3);
      let querySql = `select * from ${db}.${table};`;
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      
      executeUpdate(dropDB);
      executeUpdate(createDB);
      executeUpdate(createSql);
      executeUpdate(insertSql);
      console.log(querySql);
      let result = executeQuery(querySql);

      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        console.log((index));
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
      executeUpdate(dropDB);
    });

  test(`name:ns support stable;` +
    `author:${author};` +
    `desc:test stable supports nanoseconds;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let db = 'nodejs_support_ns_stable';
      let stable = 'ns_test_stable';
      let table = "sub_1";
      let colData = [1625801548423914100, 1, 1625801548423914,
        1625801548423914200, 2, 1625801548423914];
      let tagData = [1,1625801548423914100];
      let createDB = `create database if not exists ${db} keep 3650 precision \'ns\';`;
      let createSql = `create table if not exists ${db}.${stable} (ts timestamp,seq int,`+
      `record_date timestamp)tags(id int,htime timestamp);`;
      let dropDB = `drop database if exists ${db};`;
      let insertSql = buildInsertSql(db + '.' + table, db + '.' + stable, colData,tagData, 3);
      let querySql = `select * from ${db}.${stable};`;
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let expectResData = getResData(colData, tagData, 3);
      
      executeUpdate(dropDB);
      executeUpdate(createDB);
      executeUpdate(createSql);
      executeUpdate(insertSql);
      let result = executeQuery(querySql);

      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
      executeUpdate(dropDB);
    })
})

describe("test json tag", () => {
  test(`name:json tag;` +
    `author:${author};` +
    `desc:create,insert,query with json tag;` +
    `filename:${fileName};` +
    `result:${result}`, () => {
      let tableName = 'jsons1';
      let createSql = `create table if not exists ${tableName}(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json);`;

      executeUpdate(createSql);
      let expectResField = getFieldArr(getFeildsFromDll(createSql));
      let colData = [1591060618000, 1, false, 'json1', '涛思数据'
        , 1591060628000, 23, true, '涛思数据', 'json'
        , 1591060638000, 54, false, 'tdengine', 'taosdata'];
      let tagData = ['{\"tag1\":\"fff\",\"tag2\":5,\"tag3\":true}']
      let insertSql = buildInsertSql('json_sub_1', tableName, colData, tagData, 5);
      let expectResData = getResData(colData, tagData, 5);

      executeUpdate(insertSql);
      let result = executeQuery(`select * from ${tableName};`);
      let actualResData = result.resData;
      let actualResFields = result.resFeilds;

      //assert result data length 
      expect(expectResData.length).toEqual(actualResData.length);
      //assert result data
      expectResData.forEach((item, index) => {
        expect(item).toEqual(actualResData[index]);
      });

      //assert result meta data
      expectResField.forEach((item, index) => {
        expect(item).toEqual(actualResFields[index])
      })
    })
})