fix: not in null

This commit is contained in:
xsren 2024-07-30 14:33:47 +08:00
parent 915ec87f8d
commit d0131bb83a
2 changed files with 51 additions and 24 deletions

View File

@ -1176,27 +1176,6 @@ EDealRes sclRewriteNonConstOperator(SNode **pNode, SScalarCtx *ctx) {
} }
} }
if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) {
SNodeListNode *listNode = (SNodeListNode *)node->pRight;
SNode *tnode = NULL;
WHERE_EACH(tnode, listNode->pNodeList) {
if (SCL_IS_NULL_VALUE_NODE(tnode)) {
if (node->opType == OP_TYPE_IN) {
ERASE_NODE(listNode->pNodeList);
continue;
} else { // OP_TYPE_NOT_IN
return sclRewriteNullInOptr(pNode, ctx, node->opType);
}
}
WHERE_NEXT;
}
if (listNode->pNodeList->length <= 0) {
return sclRewriteNullInOptr(pNode, ctx, node->opType);
}
}
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -1334,6 +1313,27 @@ EDealRes sclRewriteOperator(SNode **pNode, SScalarCtx *ctx) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) {
SNodeListNode *listNode = (SNodeListNode *)node->pRight;
SNode *tnode = NULL;
WHERE_EACH(tnode, listNode->pNodeList) {
if (SCL_IS_NULL_VALUE_NODE(tnode)) {
if (node->opType == OP_TYPE_IN) {
ERASE_NODE(listNode->pNodeList);
continue;
} else { // OP_TYPE_NOT_IN
return sclRewriteNullInOptr(pNode, ctx, node->opType);
}
}
WHERE_NEXT;
}
if (listNode->pNodeList->length <= 0) {
return sclRewriteNullInOptr(pNode, ctx, node->opType);
}
}
if ((!SCL_IS_CONST_NODE(node->pLeft)) || (!SCL_IS_CONST_NODE(node->pRight))) { if ((!SCL_IS_CONST_NODE(node->pLeft)) || (!SCL_IS_CONST_NODE(node->pRight))) {
return sclRewriteNonConstOperator(pNode, ctx); return sclRewriteNonConstOperator(pNode, ctx);
} }

View File

@ -48,11 +48,11 @@ class TDTestCase:
tdSql.query(f"select 1 not in (2, null)") tdSql.query(f"select 1 not in (2, null)")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 0, True) # 1 not in (2, null) is NULL? tdSql.checkData(0, 0, False) # 1 not in (2, null) is NULL?
tdSql.query(f"select 1 not in (null)") tdSql.query(f"select 1 not in (null)")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 0, True) # 1 not in (null) is NULL? tdSql.checkData(0, 0, False) # 1 not in (null) is NULL?
tdSql.execute(f'''create table {dbname}.stb(ts timestamp, col1 int, col2 nchar(20)) tags(loc nchar(20))''') tdSql.execute(f'''create table {dbname}.stb(ts timestamp, col1 int, col2 nchar(20)) tags(loc nchar(20))''')
tdSql.execute(f"create table {dbname}.stb_1 using {dbname}.stb tags('beijing')") tdSql.execute(f"create table {dbname}.stb_1 using {dbname}.stb tags('beijing')")
@ -60,6 +60,8 @@ class TDTestCase:
for i in range(self.rowNum): for i in range(self.rowNum):
tdSql.execute(f"insert into {dbname}.stb_1 values({self.ts + i + 1}, {i+1}, 'taosdata_{i+1}')" ) tdSql.execute(f"insert into {dbname}.stb_1 values({self.ts + i + 1}, {i+1}, 'taosdata_{i+1}')" )
for i in range(self.rowNum):
tdSql.execute(f"insert into {dbname}.stb_2 values({self.ts + i + 1}, {i+1}, 'taosdata_{i+1}')" )
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 2) order by ts") tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 2) order by ts")
tdSql.checkRows(2) tdSql.checkRows(2)
@ -94,11 +96,36 @@ class TDTestCase:
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 1, 1) tdSql.checkData(0, 1, 1)
tdSql.query(f"select * from {dbname}.stb_1 where col2 not in (1, 'taosdata_1', 3, null) order by ts")
tdSql.checkRows(0)
tdSql.execute(f"insert into {dbname}.stb_1 values({self.ts + self.rowNum + 1}, {self.rowNum+1}, null)" ) tdSql.execute(f"insert into {dbname}.stb_1 values({self.ts + self.rowNum + 1}, {self.rowNum+1}, null)" )
tdSql.execute(f"insert into {dbname}.stb_2 values({self.ts + self.rowNum + 1}, {self.rowNum+1}, null)" )
tdSql.query(f"select * from {dbname}.stb_1 where col2 in (1, 'taosdata_1', 3, null) order by ts") tdSql.query(f"select * from {dbname}.stb_1 where col2 in (1, 'taosdata_1', 3, null) order by ts")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 1, 1) tdSql.checkData(0, 1, 1)
tdSql.query(f"select * from {dbname}.stb_1 where col2 not in (1, 'taosdata_1', 3, null) order by ts")
tdSql.checkRows(0)
tdSql.query(f"select * from {dbname}.stb where loc in ('beijing', null)")
tdSql.checkRows(11)
tdSql.query(f"select * from {dbname}.stb where loc in ('shanghai', null)")
tdSql.checkRows(11)
tdSql.query(f"select * from {dbname}.stb where loc in ('shanghai', 'shanghai', null)")
tdSql.checkRows(11)
tdSql.query(f"select * from {dbname}.stb where loc in ('beijing', 'shanghai', null)")
tdSql.checkRows(22)
tdSql.query(f"select * from {dbname}.stb where loc not in ('beijing', null)")
tdSql.checkRows(0)
tdSql.query(f"select * from {dbname}.stb where loc not in ('shanghai', 'shanghai', null)")
tdSql.checkRows(0)
def run(self): def run(self):