update case about diff

This commit is contained in:
wenzhouwww@live.cn 2022-08-10 17:57:45 +08:00
parent 3807d00623
commit 01bac29880
1 changed files with 51 additions and 74 deletions

View File

@ -30,7 +30,7 @@ class TDTestCase:
tdLog.debug("start to execute %s" % __file__) tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor()) tdSql.init(conn.cursor())
def diff_query_form(self, col="c1", alias="", table_expr="t1", condition=""): def diff_query_form(self, col="c1", alias="", table_expr="db.t1", condition=""):
''' '''
diff function: diff function:
@ -44,7 +44,7 @@ class TDTestCase:
return f"select diff({col}) {alias} from {table_expr} {condition}" return f"select diff({col}) {alias} from {table_expr} {condition}"
def checkdiff(self,col="c1", alias="", table_expr="t1", condition="" ): def checkdiff(self,col="c1", alias="", table_expr="db.t1", condition="" ):
line = sys._getframe().f_back.f_lineno line = sys._getframe().f_back.f_lineno
pre_sql = self.diff_query_form( pre_sql = self.diff_query_form(
col=col, table_expr=table_expr, condition=condition col=col, table_expr=table_expr, condition=condition
@ -60,7 +60,7 @@ class TDTestCase:
return return
if "order by tbname" in condition: if "order by tbname" in condition:
tdSql.error(self.diff_query_form( tdSql.query(self.diff_query_form(
col=col, alias=alias, table_expr=table_expr, condition=condition col=col, alias=alias, table_expr=table_expr, condition=condition
)) ))
return return
@ -164,9 +164,9 @@ class TDTestCase:
self.checkdiff(**case6) self.checkdiff(**case6)
# case7~8: nested query # case7~8: nested query
# case7 = {"table_expr": "(select c1 from stb1)"} # case7 = {"table_expr": "(select c1 from db.stb1)"}
# self.checkdiff(**case7) # self.checkdiff(**case7)
# case8 = {"table_expr": "(select diff(c1) c1 from stb1 group by tbname)"} # case8 = {"table_expr": "(select diff(c1) c1 from db.stb1 group by tbname)"}
# self.checkdiff(**case8) # self.checkdiff(**case8)
# case9~10: mix with tbname/ts/tag/col # case9~10: mix with tbname/ts/tag/col
@ -200,15 +200,15 @@ class TDTestCase:
self.checkdiff(**case17) self.checkdiff(**case17)
# case18~19: with group by # case18~19: with group by
# case18 = { # case18 = {
# "table_expr": "t1", # "table_expr": "db.t1",
# "condition": "group by c6" # "condition": "group by c6"
# } # }
# self.checkdiff(**case18) # self.checkdiff(**case18)
# case19 = { case19 = {
# "table_expr": "stb1", "table_expr": "db.stb1",
# "condition": "partition by tbname" # partition by tbname "condition": "partition by tbname order by tbname" # partition by tbname
# } }
# self.checkdiff(**case19) self.checkdiff(**case19)
# # case20~21: with order by # # case20~21: with order by
# case20 = {"condition": "order by ts"} # case20 = {"condition": "order by ts"}
@ -226,7 +226,7 @@ class TDTestCase:
} }
self.checkdiff(**case23) self.checkdiff(**case23)
# case24 = { # case24 = {
# "table_expr": "stb1", # "table_expr": "db.stb1",
# "condition": "group by tbname slimit 1 soffset 1" # "condition": "group by tbname slimit 1 soffset 1"
# } # }
# self.checkdiff(**case24) # self.checkdiff(**case24)
@ -241,13 +241,13 @@ class TDTestCase:
# #
# form test # form test
tdSql.error(self.diff_query_form(col="")) # no col tdSql.error(self.diff_query_form(col="")) # no col
tdSql.error("diff(c1) from stb1") # no select tdSql.error("diff(c1) from db.stb1") # no select
tdSql.error("select diff from t1") # no diff condition tdSql.error("select diff from db.t1") # no diff condition
tdSql.error("select diff c1 from t1") # no brackets tdSql.error("select diff c1 from db.t1") # no brackets
tdSql.error("select diff(c1) t1") # no from tdSql.error("select diff(c1) db.t1") # no from
tdSql.error("select diff( c1 ) from ") # no table_expr tdSql.error("select diff( c1 ) from ") # no table_expr
# tdSql.error(self.diff_query_form(col="st1")) # tag col # tdSql.error(self.diff_query_form(col="st1")) # tag col
tdSql.query("select diff(st1) from t1 ") tdSql.query("select diff(st1) from db.t1")
# tdSql.error(self.diff_query_form(col=1)) # col is a value # tdSql.error(self.diff_query_form(col=1)) # col is a value
tdSql.error(self.diff_query_form(col="'c1'")) # col is a string tdSql.error(self.diff_query_form(col="'c1'")) # col is a string
tdSql.error(self.diff_query_form(col=None)) # col is NULL 1 tdSql.error(self.diff_query_form(col=None)) # col is NULL 1
@ -260,18 +260,18 @@ class TDTestCase:
tdSql.error(self.diff_query_form(col='ts')) # Primary key tdSql.error(self.diff_query_form(col='ts')) # Primary key
tdSql.error(self.diff_query_form(col='avg(c1)')) # expr col tdSql.error(self.diff_query_form(col='avg(c1)')) # expr col
# tdSql.error(self.diff_query_form(col='c6')) # bool col # tdSql.error(self.diff_query_form(col='c6')) # bool col
tdSql.query("select diff(c6) from t1") tdSql.query("select diff(c6) from db.t1")
tdSql.error(self.diff_query_form(col='c4')) # binary col tdSql.error(self.diff_query_form(col='c4')) # binary col
tdSql.error(self.diff_query_form(col='c10')) # nachr col tdSql.error(self.diff_query_form(col='c10')) # nachr col
tdSql.error(self.diff_query_form(col='c10')) # not table_expr col tdSql.error(self.diff_query_form(col='c10')) # not table_expr col
tdSql.error(self.diff_query_form(col='t1')) # tbname tdSql.error(self.diff_query_form(col='db.t1')) # tbname
tdSql.error(self.diff_query_form(col='stb1')) # stbname tdSql.error(self.diff_query_form(col='db.stb1')) # stbname
tdSql.error(self.diff_query_form(col='db')) # datbasename tdSql.error(self.diff_query_form(col='db')) # datbasename
# tdSql.error(self.diff_query_form(col=True)) # col is BOOL 1 # tdSql.error(self.diff_query_form(col=True)) # col is BOOL 1
# tdSql.error(self.diff_query_form(col='True')) # col is BOOL 2 # tdSql.error(self.diff_query_form(col='True')) # col is BOOL 2
tdSql.error(self.diff_query_form(col='*')) # col is all col tdSql.error(self.diff_query_form(col='*')) # col is all col
tdSql.error("select diff[c1] from t1") # sql form error 1 tdSql.error("select diff[c1] from db.t1") # sql form error 1
tdSql.error("select diff{c1} from t1") # sql form error 2 tdSql.error("select diff{c1} from db.t1") # sql form error 2
tdSql.error(self.diff_query_form(col="[c1]")) # sql form error 3 tdSql.error(self.diff_query_form(col="[c1]")) # sql form error 3
# tdSql.error(self.diff_query_form(col="c1, c2")) # sql form error 3 # tdSql.error(self.diff_query_form(col="c1, c2")) # sql form error 3
# tdSql.error(self.diff_query_form(col="c1, 2")) # sql form error 3 # tdSql.error(self.diff_query_form(col="c1, 2")) # sql form error 3
@ -284,7 +284,7 @@ class TDTestCase:
# tdSql.error(self.diff_query_form(alias=" + 2")) # mix with arithmetic 1 # tdSql.error(self.diff_query_form(alias=" + 2")) # mix with arithmetic 1
tdSql.error(self.diff_query_form(alias=" + avg(c1)")) # mix with arithmetic 2 tdSql.error(self.diff_query_form(alias=" + avg(c1)")) # mix with arithmetic 2
tdSql.query(self.diff_query_form(alias=", c2")) # mix with other 1 tdSql.query(self.diff_query_form(alias=", c2")) # mix with other 1
# tdSql.error(self.diff_query_form(table_expr="stb1")) # select stb directly # tdSql.error(self.diff_query_form(table_expr="db.stb1")) # select stb directly
stb_join = { stb_join = {
"col": "stb1.c1", "col": "stb1.c1",
"table_expr": "stb1, stb2", "table_expr": "stb1, stb2",
@ -296,17 +296,17 @@ class TDTestCase:
} }
tdSql.error(self.diff_query_form(**interval_sql)) # interval tdSql.error(self.diff_query_form(**interval_sql)) # interval
group_normal_col = { group_normal_col = {
"table_expr": "t1", "table_expr": "db.t1",
"condition": "group by c6" "condition": "group by c6"
} }
tdSql.error(self.diff_query_form(**group_normal_col)) # group by normal col tdSql.error(self.diff_query_form(**group_normal_col)) # group by normal col
slimit_soffset_sql = { slimit_soffset_sql = {
"table_expr": "stb1", "table_expr": "db.stb1",
"condition": "group by tbname slimit 1 soffset 1" "condition": "group by tbname slimit 1 soffset 1"
} }
# tdSql.error(self.diff_query_form(**slimit_soffset_sql)) # tdSql.error(self.diff_query_form(**slimit_soffset_sql))
order_by_tbname_sql = { order_by_tbname_sql = {
"table_expr": "stb1", "table_expr": "db.stb1",
"condition": "group by tbname order by tbname" "condition": "group by tbname order by tbname"
} }
tdSql.error(self.diff_query_form(**order_by_tbname_sql)) tdSql.error(self.diff_query_form(**order_by_tbname_sql))
@ -351,63 +351,40 @@ class TDTestCase:
"create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)" "create stable db.stb2 (ts timestamp, c1 int) tags(st2 int)"
) )
for i in range(tbnum): for i in range(tbnum):
tdSql.execute(f"create table t{i} using stb1 tags({i})") tdSql.execute(f"create table t{i} using db.stb1 tags({i})")
tdSql.execute(f"create table tt{i} using stb2 tags({i})") tdSql.execute(f"create table tt{i} using db.stb2 tags({i})")
pass pass
def diff_support_stable(self): def diff_support_stable(self):
tdSql.query(" select diff(1) from stb1 ") tdSql.query(" select diff(1) from db.stb1 ")
tdSql.checkRows(229) tdSql.checkRows(229)
tdSql.checkData(0,0,0) tdSql.checkData(0,0,0)
tdSql.query("select diff(c1) from stb1 partition by tbname ") tdSql.query("select diff(c1) from db.stb1 partition by tbname ")
tdSql.checkRows(190)
# tdSql.query("select diff(st1) from stb1 partition by tbname")
# tdSql.checkRows(229)
tdSql.query("select diff(st1+c1) from stb1 partition by tbname")
tdSql.checkRows(190)
tdSql.query("select diff(st1+c1) from stb1 partition by tbname")
tdSql.checkRows(190)
tdSql.query("select diff(st1+c1) from stb1 partition by tbname")
tdSql.checkRows(190) tdSql.checkRows(190)
# # bug need fix tdSql.query("select diff(st1+c1) from db.stb1 partition by tbname")
# tdSql.query("select diff(st1+c1) from stb1 partition by tbname slimit 1 ") tdSql.checkRows(190)
# tdSql.checkRows(19) tdSql.query("select diff(st1+c1) from db.stb1 partition by tbname")
# tdSql.error("select diff(st1+c1) from stb1 partition by tbname limit 1 ") tdSql.checkRows(190)
tdSql.query("select diff(st1+c1) from db.stb1 partition by tbname")
# bug need fix
tdSql.query("select diff(st1+c1) from stb1 partition by tbname")
tdSql.checkRows(190) tdSql.checkRows(190)
# bug need fix # bug need fix
# tdSql.query("select tbname , diff(c1) from stb1 partition by tbname") tdSql.query("select diff(st1+c1) from db.stb1 partition by tbname")
# tdSql.checkRows(199) tdSql.checkRows(190)
# tdSql.query("select tbname , diff(st1) from stb1 partition by tbname")
# tdSql.checkRows(199) # bug need fix
# tdSql.query("select tbname , diff(st1) from stb1 partition by tbname slimit 1") tdSql.query("select tbname , diff(c1) from db.stb1 partition by tbname")
# tdSql.checkRows(19) tdSql.checkRows(190)
tdSql.query("select tbname , diff(st1) from db.stb1 partition by tbname")
tdSql.checkRows(220)
# partition by tags # partition by tags
# tdSql.query("select st1 , diff(c1) from stb1 partition by st1") tdSql.query("select st1 , diff(c1) from db.stb1 partition by st1")
# tdSql.checkRows(199) tdSql.checkRows(190)
# tdSql.query("select diff(c1) from stb1 partition by st1") tdSql.query("select diff(c1) from db.stb1 partition by st1")
# tdSql.checkRows(199) tdSql.checkRows(190)
# tdSql.query("select st1 , diff(c1) from stb1 partition by st1 slimit 1")
# tdSql.checkRows(19)
# tdSql.query("select diff(c1) from stb1 partition by st1 slimit 1")
# tdSql.checkRows(19)
# partition by col
# tdSql.query("select c1 , diff(c1) from stb1 partition by c1")
# tdSql.checkRows(199)
# tdSql.query("select diff(c1) from stb1 partition by c1")
# tdSql.checkRows(41)
# tdSql.query("select c1 , diff(c1) from stb1 partition by st1 slimit 1")
# tdSql.checkRows(19)
# tdSql.query("select diff(c1) from stb1 partition by st1 slimit 1")
# tdSql.checkRows(19)
def diff_test_run(self) : def diff_test_run(self) :
@ -430,18 +407,18 @@ class TDTestCase:
tdLog.printNoPrefix("######## insert data in the range near the max(bigint/double):") tdLog.printNoPrefix("######## insert data in the range near the max(bigint/double):")
self.diff_test_table(tbnum) self.diff_test_table(tbnum)
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values " tdSql.execute(f"insert into db.t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 1) * 10}, {2**31-1}, {3.4*10**38}, {1.7*10**308}, {2**63-1})") f"({nowtime - (per_table_rows + 1) * 10}, {2**31-1}, {3.4*10**38}, {1.7*10**308}, {2**63-1})")
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values " tdSql.execute(f"insert into db.t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 2) * 10}, {2**31-1}, {3.4*10**38}, {1.7*10**308}, {2**63-1})") f"({nowtime - (per_table_rows + 2) * 10}, {2**31-1}, {3.4*10**38}, {1.7*10**308}, {2**63-1})")
self.diff_current_query() self.diff_current_query()
self.diff_error_query() self.diff_error_query()
tdLog.printNoPrefix("######## insert data in the range near the min(bigint/double):") tdLog.printNoPrefix("######## insert data in the range near the min(bigint/double):")
self.diff_test_table(tbnum) self.diff_test_table(tbnum)
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values " tdSql.execute(f"insert into db.t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 1) * 10}, {1-2**31}, {-3.4*10**38}, {-1.7*10**308}, {1-2**63})") f"({nowtime - (per_table_rows + 1) * 10}, {1-2**31}, {-3.4*10**38}, {-1.7*10**308}, {1-2**63})")
tdSql.execute(f"insert into t1(ts, c1,c2,c5,c7) values " tdSql.execute(f"insert into db.t1(ts, c1,c2,c5,c7) values "
f"({nowtime - (per_table_rows + 2) * 10}, {1-2**31}, {-3.4*10**38}, {-1.7*10**308}, {512-2**63})") f"({nowtime - (per_table_rows + 2) * 10}, {1-2**31}, {-3.4*10**38}, {-1.7*10**308}, {512-2**63})")
self.diff_current_query() self.diff_current_query()
self.diff_error_query() self.diff_error_query()