countAlwaysReturnValue.py 5.5 KB
Newer Older
G
Ganlin Zhao 已提交
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
import taos
import sys
import datetime
import inspect

from util.log import *
from util.sql import *
from util.cases import *
import random


class TDTestCase:
    updatecfgDict = {"countAlwaysReturnValue":0}

    def init(self, conn, logSql, replicaVar=1):
        tdLog.debug(f"start to excute {__file__}")
        tdSql.init(conn.cursor(), False)

    def prepare_data(self, dbname="db"):
        tdSql.execute(
            f"create database if not exists {dbname} keep 3650 duration 1000")
        tdSql.execute(f"use {dbname} ")
        tdSql.execute(
            f"create table {dbname}.tb (ts timestamp, c0 int)"
        )
        tdSql.execute(
            f"create table {dbname}.stb (ts timestamp, c0 int) tags (t0 int)"
        )
        tdSql.execute(
            f"create table {dbname}.ctb1 using {dbname}.stb tags (1)"
        )
        tdSql.execute(
            f"create table {dbname}.ctb2 using {dbname}.stb tags (2)"
        )

G
Ganlin Zhao 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48
        tdSql.execute(
            f"create table {dbname}.tb_empty (ts timestamp, c0 int)"
        )
        tdSql.execute(
            f"create table {dbname}.stb_empty (ts timestamp, c0 int) tags (t0 int)"
        )
        tdSql.execute(
            f"create table {dbname}.ctb1_empty using {dbname}.stb tags (1)"
        )
        tdSql.execute(
            f"create table {dbname}.ctb2_empty using {dbname}.stb tags (2)"
        )

G
Ganlin Zhao 已提交
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
        tdSql.execute(
            f"insert into {dbname}.tb values (now(), NULL)")

        tdSql.execute(
            f"insert into {dbname}.ctb1 values (now(), NULL)")

        tdSql.execute(
            f"insert into {dbname}.ctb2 values (now() + 1s, NULL)")

    def test_results(self, dbname="db"):

        # count
        tdSql.query(f"select count(c0) from {dbname}.tb")
        tdSql.checkRows(0)

        tdSql.query(f"select count(NULL) from {dbname}.tb")
        tdSql.checkRows(0)

        tdSql.query(f"select c0,count(c0) from {dbname}.tb group by c0")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, None)

        tdSql.query(f"select count(c0) from {dbname}.stb")
        tdSql.checkRows(0)

        tdSql.query(f"select count(NULL) from {dbname}.stb")
        tdSql.checkRows(0)

        tdSql.query(f"select c0,count(c0) from {dbname}.stb group by c0")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, None)

        tdSql.query(f"select count(NULL)")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, 0)

        # hyperloglog
        tdSql.query(f"select hyperloglog(c0) from {dbname}.tb")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(NULL) from {dbname}.tb")
        tdSql.checkRows(0)

        tdSql.query(f"select c0,hyperloglog(c0) from {dbname}.tb group by c0")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, None)

        tdSql.query(f"select hyperloglog(c0) from {dbname}.stb")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(NULL) from {dbname}.stb")
        tdSql.checkRows(0)

        tdSql.query(f"select c0,hyperloglog(c0) from {dbname}.stb group by c0")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, None)

        tdSql.query(f"select hyperloglog(NULL)")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, 0)

G
Ganlin Zhao 已提交
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
        # test empty table/input
        tdSql.query(f"select count(*) from {dbname}.tb where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select count(ts) from {dbname}.stb where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select count(c0) from {dbname}.ctb1 where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select count(1) from {dbname}.ctb2 where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select count(*) from {dbname}.tb_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select count(ts) from {dbname}.stb_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select count(c0) from {dbname}.ctb1_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select count(1) from {dbname}.ctb2_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(c0) from {dbname}.tb where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(ts) from {dbname}.stb where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(1) from {dbname}.ctb1 where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(1) from {dbname}.ctb2 where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(c0) from {dbname}.tb_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(ts) from {dbname}.stb_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(1) from {dbname}.ctb1_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select hyperloglog(1) from {dbname}.ctb2_empty")
        tdSql.checkRows(0)

        tdSql.query(f"select count(*), hyperloglog(c0), sum(1), max(c0) from {dbname}.tb where ts > now + 1h")
        tdSql.checkRows(0)

        tdSql.query(f"select count(*), hyperloglog(c0), sum(1), max(c0) from {dbname}.tb_empty")
        tdSql.checkRows(0)

G
Ganlin Zhao 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    def run(self):
        tdSql.prepare()

        tdLog.printNoPrefix("==========step1:prepare data ==============")

        self.prepare_data()

        tdLog.printNoPrefix("==========step2:test results ==============")

        self.test_results()


    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")


tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())