diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 4b8396dd0d7..dc228095f97 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -722,29 +722,36 @@ static int32_t checkColRefType(const SSchema* vtbSchema, const SSchema* refSchem static int32_t addSubScanNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SVirtualTableNode* pVirtualTable, int32_t index, SHashObj *refTablesMap) { - int32_t code = TSDB_CODE_SUCCESS; - col_id_t colId = 0; - SColRef* pColRef = &pVirtualTable->pMeta->colRef[index]; - SNode *pRefTable = NULL; + int32_t code = TSDB_CODE_SUCCESS; + col_id_t colId = 0; + SColRef *pColRef = &pVirtualTable->pMeta->colRef[index]; + SNode *pRefTable = NULL; + SLogicNode *pRefScan = NULL; + bool put = false; PLAN_ERR_JRET(findRefTableNode(pVirtualTable->refTables, pColRef->refTableName, &pRefTable)); PLAN_ERR_JRET(findRefColId(pRefTable, pColRef->refColName, &colId)); - SLogicNode *pRefScan = NULL; SLogicNode **ppRefScan = (SLogicNode **)taosHashGet(refTablesMap, &pColRef->refTableName, strlen(pColRef->refTableName)); if (NULL == ppRefScan) { PLAN_ERR_JRET(createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pRefTable, &pRefScan)); PLAN_ERR_JRET(checkColRefType(&pVirtualTable->pMeta->schema[index], &((SRealTableNode*)pRefTable)->pMeta->schema[colId - 1])); PLAN_ERR_JRET(scanAddCol(pRefScan, pColRef, &pVirtualTable->pMeta->schema[index], colId)); PLAN_ERR_JRET(taosHashPut(refTablesMap, &pColRef->refTableName, strlen(pColRef->refTableName), &pRefScan, POINTER_BYTES)); + put = true; } else { pRefScan = *ppRefScan; PLAN_ERR_JRET(checkColRefType(&pVirtualTable->pMeta->schema[index], &((SRealTableNode*)pRefTable)->pMeta->schema[colId - 1])); PLAN_ERR_JRET(scanAddCol(pRefScan, pColRef, &pVirtualTable->pMeta->schema[index], colId)); } + nodesDestroyNode((SNode*)pRefTable); + return code; _return: nodesDestroyNode((SNode*)pRefTable); + if (!put) { + nodesDestroyNode((SNode*)pRefScan); + } return code; } @@ -763,6 +770,14 @@ static int32_t makeVirtualScanLogicNode(SLogicPlanContext* pCxt, SVirtualTableNo return TSDB_CODE_SUCCESS; } +static void destroyScanLogicNode(void* data) { + if (data == NULL) { + return; + } + SScanLogicNode* pNode = *(SScanLogicNode **)data; + nodesDestroyNode((SNode*)pNode); +} + static int32_t createVirtualTableLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SVirtualTableNode* pVirtualTable, SLogicNode** pLogicNode) { int32_t code = TSDB_CODE_SUCCESS; @@ -851,10 +866,7 @@ static int32_t createVirtualTableLogicNode(SLogicPlanContext* pCxt, SSelectStmt* return code; _return: - while ((pIter = taosHashIterate(pRefTablesMap, pIter))) { - SScanLogicNode **pRefScanNode = (SScanLogicNode**)pIter; - nodesDestroyNode((SNode*)(*pRefScanNode)); - } + taosHashSetFreeFp(pRefTablesMap, destroyScanLogicNode); taosHashCleanup(pRefTablesMap); nodesDestroyNode((SNode*)pVtableScan); return code; diff --git a/tests/army/vtable/ans/test_vctable_select_test_function.ans b/tests/army/vtable/ans/test_vctable_select_test_function.ans index 240b60413a8..96fdad98ef7 100644 --- a/tests/army/vtable/ans/test_vctable_select_test_function.ans +++ b/tests/army/vtable/ans/test_vctable_select_test_function.ans @@ -201,7 +201,7 @@ taos> select atan(u_tinyint_col) from test_vtable_select.vtb_virtual_ctb_full li 1.564467297378695 | 1.563389054863731 | 1.565965446500920 | - 1.566410390006105 | + 1.566410390006104 | 1.557639191322141 | 1.566697989085048 | 1.373400766945016 | @@ -654,7 +654,7 @@ taos> select tan(u_tinyint_col) from test_vtable_select.vtb_virtual_ctb_full lim 1.314265006453343 | 1.557407724654902 | -3.172908552159191 | - -5.737022539279000 | + -5.737022539278999 | -225.950846454195130 | -32.268575775934416 | 0.169749752082688 | @@ -669,7 +669,7 @@ taos> select tan(u_tinyint_col) from test_vtable_select.vtb_virtual_ctb_full lim -0.825774009196815 | 0.070929992292224 | 0.919286404403608 | - -6.799711455220378 | + -6.799711455220379 | 3.493915645474840 | -0.234224329867607 | -0.635859928661581 | @@ -687,13 +687,13 @@ taos> select tan(u_tinyint_col) from test_vtable_select.vtb_virtual_ctb_full lim 1.314265006453343 | -0.088715756770060 | -0.359502553689686 | - -4.185333577911701 | + -4.185333577911702 | 0.686747689351523 | -1.720229311752444 | - -3.380515006246585 | + -3.380515006246586 | 0.310309660994801 | 1.244270058128709 | - 5.192801712384871 | + 5.192801712384870 | 1.004465813691152 | -1.314182797241192 | -0.410321299048242 | @@ -2970,7 +2970,7 @@ taos> select stateduration(u_tinyint_col, "GT", 20, 1a) from test_vtable_select. taos> select twa(int_col) from test_vtable_select.vtb_virtual_ctb_full limit 50; twa(int_col) | ============================ - -163781.012033155217068 | + -163685.413924687134568 | taos> select abs(int_tag) from test_vtable_select.vtb_virtual_ctb_full limit 5; abs(int_tag) | diff --git a/tests/army/vtable/test_vtable_auth.py b/tests/army/vtable/test_vtable_auth_alter_drop.py similarity index 50% rename from tests/army/vtable/test_vtable_auth.py rename to tests/army/vtable/test_vtable_auth_alter_drop.py index 76773db66a3..46901e40d20 100644 --- a/tests/army/vtable/test_vtable_auth.py +++ b/tests/army/vtable/test_vtable_auth_alter_drop.py @@ -25,15 +25,9 @@ class TDTestCase(TBase): def prepare_data(self): tdLog.info(f"prepare databases.") - tdSql.execute("drop database if exists test_vtable_auth_create;") tdSql.execute("drop database if exists test_vtable_auth_alter;") - tdSql.execute("drop database if exists test_vtable_auth_select;") - tdSql.execute("drop database if exists test_vctable_auth_create;") tdSql.execute("drop database if exists test_vctable_auth_alter;") - tdSql.execute("create database test_vtable_auth_create;") tdSql.execute("create database test_vtable_auth_alter;") - tdSql.execute("create database test_vtable_auth_select;") - tdSql.execute("create database test_vctable_auth_create;") tdSql.execute("create database test_vctable_auth_alter;") @@ -141,192 +135,6 @@ def test_alter_drop_virtual_normal_table(self): tdSql.execute("drop database test_vtable_auth_alter;") - def test_create_virtual_normal_table(self): - tdSql.execute("use test_vtable_auth_create;") - tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") - tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") - tdSql.execute("create user test_vtable_user_create PASS 'test12@#*';") - - priv_list = ["write", "read", "none", "all"] - - testconn = taos.connect(user='test_vtable_user_create', password='test12@#*') - cursor = testconn.cursor() - testSql = TDSql() - testSql.init(cursor) - - i = 0 - for priv_db in priv_list: - if (priv_db == "none"): - continue # meaningless to test db has no privilege - for priv_tb1 in priv_list: - for priv_tb2 in priv_list: - tdSql.execute("use test_vtable_auth_create;") - tdSql.execute(f"grant {priv_db} on test_vtable_auth_create to test_vtable_user_create;") - if (priv_tb1 != "none"): - tdSql.execute(f"grant {priv_tb1} on test_vtable_auth_create.test_vtable_auth_org_table_1 to test_vtable_user_create;") - if (priv_tb2 != "none"): - tdSql.execute(f"grant {priv_tb2} on test_vtable_auth_create.test_vtable_auth_org_table_2 to test_vtable_user_create;") - - sleep(2) - tdLog.info(f"priv_db: {priv_db}, priv_tb1: {priv_tb1}, priv_tb2: {priv_tb2}") - testSql.execute("use test_vtable_auth_create;") - if (priv_db == "read"): - testSql.error(f"create vtable test_vtable_auth_vtb_{i}(" - "ts timestamp, " - "int_col_1 int from test_vtable_auth_org_table_1.int_col, " - "int_col_2 int from test_vtable_auth_org_table_2.int_col);", expectErrInfo="Permission denied or target object not exist") - elif (priv_db == "all"): - testSql.execute(f"create vtable test_vtable_auth_vtb_{i}(" - "ts timestamp, " - "int_col_1 int from test_vtable_auth_org_table_1.int_col, " - "int_col_2 int from test_vtable_auth_org_table_2.int_col);") - elif (priv_tb1 == "write" or priv_tb2 == "write" or priv_tb1 == "none" or priv_tb2 == "none"): - testSql.error(f"create vtable test_vtable_auth_vtb_{i}(" - "ts timestamp, " - "int_col_1 int from test_vtable_auth_org_table_1.int_col, " - "int_col_2 int from test_vtable_auth_org_table_2.int_col);", expectErrInfo="Permission denied or target object not exist") - else: - testSql.execute(f"create vtable test_vtable_auth_vtb_{i}(" - "ts timestamp, " - "int_col_1 int from test_vtable_auth_org_table_1.int_col, " - "int_col_2 int from test_vtable_auth_org_table_2.int_col);") - - - - tdSql.execute(f"revoke {priv_db} on test_vtable_auth_create from test_vtable_user_create;") - if (priv_tb1 != "none"): - tdSql.execute(f"revoke {priv_tb1} on test_vtable_auth_create.test_vtable_auth_org_table_1 from test_vtable_user_create;") - if (priv_tb2 != "none"): - tdSql.execute(f"revoke {priv_tb2} on test_vtable_auth_create.test_vtable_auth_org_table_2 from test_vtable_user_create;") - i+=1 - - tdSql.execute("drop database test_vtable_auth_create;") - - def test_select_virtual_normal_table(self): - tdSql.execute("use test_vtable_auth_select;") - tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") - tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") - tdSql.execute("create user test_vtable_user_select PASS 'test12@#*';") - tdSql.execute("create vtable test_vtable_auth_vtb_0(" - "ts timestamp, " - "int_col_1 int from test_vtable_auth_org_table_1.int_col, " - "int_col_2 int from test_vtable_auth_org_table_2.int_col);") - - priv_list = ["write", "read", "none", "all"] - - testconn = taos.connect(user='test_vtable_user_select', password='test12@#*') - cursor = testconn.cursor() - testSql = TDSql() - testSql.init(cursor) - - i = 0 - for priv_db in priv_list: - if (priv_db == "none"): - continue # meaningless to test db has no privilege - for priv_vtb in priv_list: - tdSql.execute("use test_vtable_auth_select;") - - tdSql.execute(f"grant {priv_db} on test_vtable_auth_select to test_vtable_user_select;") - if (priv_vtb != "none"): - tdSql.execute(f"grant {priv_vtb} on test_vtable_auth_select.test_vtable_auth_vtb_0 to test_vtable_user_select;") - - sleep(2) - - tdLog.info(f"priv_db: {priv_db}, priv_vtb: {priv_vtb}") - testSql.execute("use test_vtable_auth_select;") - if (priv_db == "read" or priv_db == "all"): - testSql.query("select * from test_vtable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_1 from test_vtable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_2 from test_vtable_auth_vtb_0;") - testSql.checkRows(0) - else: - if (priv_vtb == "read" or priv_vtb == "all"): - testSql.query("select * from test_vtable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_1 from test_vtable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_2 from test_vtable_auth_vtb_0;") - testSql.checkRows(0) - else: - testSql.error("select * from test_vtable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") - testSql.error("select int_col_1 from test_vtable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") - testSql.error("select int_col_2 from test_vtable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") - - tdSql.execute(f"revoke {priv_db} on test_vtable_auth_select from test_vtable_user_select;") - if (priv_vtb != "none"): - tdSql.execute(f"revoke {priv_vtb} on test_vtable_auth_select.test_vtable_auth_vtb_0 from test_vtable_user_select;") - i+=1 - - tdSql.execute("drop database test_vtable_auth_select;") - - def test_create_virtual_child_table(self): - tdSql.execute("use test_vctable_auth_create;") - tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") - tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") - tdSql.execute("create user test_vct_user_create PASS 'test12@#*';") - tdSql.execute("create stable test_vtable_auth_stb_1(ts timestamp, int_col_1 int, int_col_2 int) TAGS (int_tag int) virtual 1;") - priv_list = ["write", "read", "none", "all"] - - testconn = taos.connect(user='test_vct_user_create', password='test12@#*') - cursor = testconn.cursor() - testSql = TDSql() - testSql.init(cursor) - - i = 0 - for priv_db in priv_list: - if (priv_db == "none"): - continue # meaningless to test db has no privilege - for priv_tb1 in priv_list: - for priv_tb2 in priv_list: - tdSql.execute("use test_vctable_auth_create;") - tdSql.execute(f"grant {priv_db} on test_vctable_auth_create to test_vct_user_create;") - if (priv_tb1 != "none"): - tdSql.execute(f"grant {priv_tb1} on test_vctable_auth_create.test_vtable_auth_org_table_1 to test_vct_user_create;") - if (priv_tb2 != "none"): - tdSql.execute(f"grant {priv_tb2} on test_vctable_auth_create.test_vtable_auth_org_table_2 to test_vct_user_create;") - - sleep(2) - tdLog.info(f"priv_db: {priv_db}, priv_tb1: {priv_tb1}, priv_tb2: {priv_tb2}") - testSql.execute("use test_vctable_auth_create;") - if (priv_db == "read"): - testSql.error(f"create vtable test_vctable_auth_vtb_{i}(" - "test_vtable_auth_org_table_1.int_col, " - "test_vtable_auth_org_table_2.int_col) " - "USING test_vtable_auth_stb_1 " - "TAGS (1);", expectErrInfo="Permission denied or target object not exist") - elif (priv_db == "all"): - testSql.execute(f"create vtable test_vctable_auth_vtb_{i}(" - "test_vtable_auth_org_table_1.int_col, " - "test_vtable_auth_org_table_2.int_col)" - "USING test_vtable_auth_stb_1 " - "TAGS (1);") - else: - if (priv_tb1 == "write" or priv_tb1 == "none" or priv_tb2 == "write" or priv_tb2 == "none"): - testSql.error(f"create vtable test_vctable_auth_vtb_{i}(" - "test_vtable_auth_org_table_1.int_col, " - "test_vtable_auth_org_table_2.int_col) " - "USING test_vtable_auth_stb_1 " - "TAGS (1);", expectErrInfo="Permission denied or target object not exist") - else: - testSql.execute(f"create vtable test_vctable_auth_vtb_{i}(" - "test_vtable_auth_org_table_1.int_col, " - "test_vtable_auth_org_table_2.int_col)" - "USING test_vtable_auth_stb_1 " - "TAGS (1);") - - - - tdSql.execute(f"revoke {priv_db} on test_vctable_auth_create from test_vct_user_create;") - if (priv_tb1 != "none"): - tdSql.execute(f"revoke {priv_tb1} on test_vctable_auth_create.test_vtable_auth_org_table_1 from test_vct_user_create;") - if (priv_tb2 != "none"): - tdSql.execute(f"revoke {priv_tb2} on test_vctable_auth_create.test_vtable_auth_org_table_2 from test_vct_user_create;") - i+=1 - - tdSql.execute("drop database test_vctable_auth_create;") - def test_alter_drop_virtual_child_table(self): tdSql.execute("use test_vctable_auth_alter;") tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") @@ -404,75 +212,12 @@ def test_alter_drop_virtual_child_table(self): tdSql.execute("drop database test_vctable_auth_alter;") - def test_select_virtual_child_table(self): - tdSql.execute("drop database if exists test_vctable_auth_select;") - tdSql.execute("create database test_vctable_auth_select;") - tdSql.execute("use test_vctable_auth_select;") - tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") - tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") - tdSql.execute("create user test_vct_user_select PASS 'test12@#*';") - tdSql.execute("create stable test_vtable_auth_stb_1(ts timestamp, int_col_1 int, int_col_2 int) TAGS (int_tag int) virtual 1;") - tdSql.execute(f"create vtable test_vctable_auth_vtb_0(test_vtable_auth_org_table_1.int_col, test_vtable_auth_org_table_2.int_col) USING test_vtable_auth_stb_1 TAGS (1);") - - priv_list = ["write", "read", "none", "all"] - - testconn = taos.connect(user='test_vct_user_select', password='test12@#*') - cursor = testconn.cursor() - testSql = TDSql() - testSql.init(cursor) - - i = 0 - for priv_db in priv_list: - if (priv_db == "none"): - continue # meaningless to test db has no privilege - for priv_vtb in priv_list: - tdSql.execute("use test_vctable_auth_select;") - - tdSql.execute(f"grant {priv_db} on test_vctable_auth_select to test_vct_user_select;") - if (priv_vtb != "none"): - tdSql.execute(f"grant {priv_vtb} on test_vctable_auth_select.test_vtable_auth_stb_1 with int_tag = 1 to test_vct_user_select;") - - sleep(2) - - tdLog.info(f"priv_db: {priv_db}, priv_vtb: {priv_vtb}") - testSql.execute("use test_vctable_auth_select;") - if (priv_db == "read" or priv_db == "all"): - testSql.query("select * from test_vctable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_1 from test_vctable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_2 from test_vctable_auth_vtb_0;") - testSql.checkRows(0) - else: - if (priv_vtb == "read" or priv_vtb == "all"): - testSql.query("select * from test_vctable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_1 from test_vctable_auth_vtb_0;") - testSql.checkRows(0) - testSql.query("select int_col_2 from test_vctable_auth_vtb_0;") - testSql.checkRows(0) - else: - testSql.error("select * from test_vctable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") - testSql.error("select int_col_1 from test_vctable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") - testSql.error("select int_col_2 from test_vctable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") - - tdSql.execute(f"revoke {priv_db} on test_vctable_auth_select from test_vct_user_select;") - if (priv_vtb != "none"): - tdSql.execute(f"revoke {priv_vtb} on test_vctable_auth_select.test_vtable_auth_stb_1 with int_tag = 1 from test_vct_user_select;") - i+=1 - - tdSql.execute("drop database if exists test_vctable_auth_select;") - def run(self): tdLog.debug(f"start to excute {__file__}") self.prepare_data() - #self.test_create_virtual_normal_table() - #self.test_alter_drop_virtual_normal_table() - #self.test_select_virtual_normal_table() - self.test_create_virtual_child_table() + self.test_alter_drop_virtual_normal_table() self.test_alter_drop_virtual_child_table() - self.test_select_virtual_child_table() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/army/vtable/test_vtable_auth_create.py b/tests/army/vtable/test_vtable_auth_create.py new file mode 100644 index 00000000000..68f28752993 --- /dev/null +++ b/tests/army/vtable/test_vtable_auth_create.py @@ -0,0 +1,171 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +from frame.etool import * +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame.common import * + +import taos +import time + +class TDTestCase(TBase): + + def prepare_data(self): + tdLog.info(f"prepare databases.") + tdSql.execute("drop database if exists test_vtable_auth_create;") + tdSql.execute("drop database if exists test_vctable_auth_create;") + tdSql.execute("create database test_vtable_auth_create;") + tdSql.execute("create database test_vctable_auth_create;") + + + def test_create_virtual_normal_table(self): + tdSql.execute("use test_vtable_auth_create;") + tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") + tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") + tdSql.execute("create user test_vtable_user_create PASS 'test12@#*';") + + priv_list = ["write", "read", "none", "all"] + + testconn = taos.connect(user='test_vtable_user_create', password='test12@#*') + cursor = testconn.cursor() + testSql = TDSql() + testSql.init(cursor) + + i = 0 + for priv_db in priv_list: + if (priv_db == "none"): + continue # meaningless to test db has no privilege + for priv_tb1 in priv_list: + for priv_tb2 in priv_list: + tdSql.execute("use test_vtable_auth_create;") + tdSql.execute(f"grant {priv_db} on test_vtable_auth_create to test_vtable_user_create;") + if (priv_tb1 != "none"): + tdSql.execute(f"grant {priv_tb1} on test_vtable_auth_create.test_vtable_auth_org_table_1 to test_vtable_user_create;") + if (priv_tb2 != "none"): + tdSql.execute(f"grant {priv_tb2} on test_vtable_auth_create.test_vtable_auth_org_table_2 to test_vtable_user_create;") + + sleep(2) + tdLog.info(f"priv_db: {priv_db}, priv_tb1: {priv_tb1}, priv_tb2: {priv_tb2}") + testSql.execute("use test_vtable_auth_create;") + if (priv_db == "read"): + testSql.error(f"create vtable test_vtable_auth_vtb_{i}(" + "ts timestamp, " + "int_col_1 int from test_vtable_auth_org_table_1.int_col, " + "int_col_2 int from test_vtable_auth_org_table_2.int_col);", expectErrInfo="Permission denied or target object not exist") + elif (priv_db == "all"): + testSql.execute(f"create vtable test_vtable_auth_vtb_{i}(" + "ts timestamp, " + "int_col_1 int from test_vtable_auth_org_table_1.int_col, " + "int_col_2 int from test_vtable_auth_org_table_2.int_col);") + elif (priv_tb1 == "write" or priv_tb2 == "write" or priv_tb1 == "none" or priv_tb2 == "none"): + testSql.error(f"create vtable test_vtable_auth_vtb_{i}(" + "ts timestamp, " + "int_col_1 int from test_vtable_auth_org_table_1.int_col, " + "int_col_2 int from test_vtable_auth_org_table_2.int_col);", expectErrInfo="Permission denied or target object not exist") + else: + testSql.execute(f"create vtable test_vtable_auth_vtb_{i}(" + "ts timestamp, " + "int_col_1 int from test_vtable_auth_org_table_1.int_col, " + "int_col_2 int from test_vtable_auth_org_table_2.int_col);") + + + + tdSql.execute(f"revoke {priv_db} on test_vtable_auth_create from test_vtable_user_create;") + if (priv_tb1 != "none"): + tdSql.execute(f"revoke {priv_tb1} on test_vtable_auth_create.test_vtable_auth_org_table_1 from test_vtable_user_create;") + if (priv_tb2 != "none"): + tdSql.execute(f"revoke {priv_tb2} on test_vtable_auth_create.test_vtable_auth_org_table_2 from test_vtable_user_create;") + i+=1 + + tdSql.execute("drop database test_vtable_auth_create;") + + def test_create_virtual_child_table(self): + tdSql.execute("use test_vctable_auth_create;") + tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") + tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") + tdSql.execute("create user test_vct_user_create PASS 'test12@#*';") + tdSql.execute("create stable test_vtable_auth_stb_1(ts timestamp, int_col_1 int, int_col_2 int) TAGS (int_tag int) virtual 1;") + priv_list = ["write", "read", "none", "all"] + + testconn = taos.connect(user='test_vct_user_create', password='test12@#*') + cursor = testconn.cursor() + testSql = TDSql() + testSql.init(cursor) + + i = 0 + for priv_db in priv_list: + if (priv_db == "none"): + continue # meaningless to test db has no privilege + for priv_tb1 in priv_list: + for priv_tb2 in priv_list: + tdSql.execute("use test_vctable_auth_create;") + tdSql.execute(f"grant {priv_db} on test_vctable_auth_create to test_vct_user_create;") + if (priv_tb1 != "none"): + tdSql.execute(f"grant {priv_tb1} on test_vctable_auth_create.test_vtable_auth_org_table_1 to test_vct_user_create;") + if (priv_tb2 != "none"): + tdSql.execute(f"grant {priv_tb2} on test_vctable_auth_create.test_vtable_auth_org_table_2 to test_vct_user_create;") + + sleep(2) + tdLog.info(f"priv_db: {priv_db}, priv_tb1: {priv_tb1}, priv_tb2: {priv_tb2}") + testSql.execute("use test_vctable_auth_create;") + if (priv_db == "read"): + testSql.error(f"create vtable test_vctable_auth_vtb_{i}(" + "test_vtable_auth_org_table_1.int_col, " + "test_vtable_auth_org_table_2.int_col) " + "USING test_vtable_auth_stb_1 " + "TAGS (1);", expectErrInfo="Permission denied or target object not exist") + elif (priv_db == "all"): + testSql.execute(f"create vtable test_vctable_auth_vtb_{i}(" + "test_vtable_auth_org_table_1.int_col, " + "test_vtable_auth_org_table_2.int_col)" + "USING test_vtable_auth_stb_1 " + "TAGS (1);") + else: + if (priv_tb1 == "write" or priv_tb1 == "none" or priv_tb2 == "write" or priv_tb2 == "none"): + testSql.error(f"create vtable test_vctable_auth_vtb_{i}(" + "test_vtable_auth_org_table_1.int_col, " + "test_vtable_auth_org_table_2.int_col) " + "USING test_vtable_auth_stb_1 " + "TAGS (1);", expectErrInfo="Permission denied or target object not exist") + else: + testSql.execute(f"create vtable test_vctable_auth_vtb_{i}(" + "test_vtable_auth_org_table_1.int_col, " + "test_vtable_auth_org_table_2.int_col)" + "USING test_vtable_auth_stb_1 " + "TAGS (1);") + + + + tdSql.execute(f"revoke {priv_db} on test_vctable_auth_create from test_vct_user_create;") + if (priv_tb1 != "none"): + tdSql.execute(f"revoke {priv_tb1} on test_vctable_auth_create.test_vtable_auth_org_table_1 from test_vct_user_create;") + if (priv_tb2 != "none"): + tdSql.execute(f"revoke {priv_tb2} on test_vctable_auth_create.test_vtable_auth_org_table_2 from test_vct_user_create;") + i+=1 + + tdSql.execute("drop database test_vctable_auth_create;") + + def run(self): + tdLog.debug(f"start to excute {__file__}") + + self.prepare_data() + self.test_create_virtual_normal_table() + self.test_create_virtual_child_table() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/army/vtable/test_vtable_auth_select.py b/tests/army/vtable/test_vtable_auth_select.py new file mode 100644 index 00000000000..e19eab79357 --- /dev/null +++ b/tests/army/vtable/test_vtable_auth_select.py @@ -0,0 +1,159 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +from frame.etool import * +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame.common import * + +import taos +import time + +class TDTestCase(TBase): + + def prepare_data(self): + tdLog.info(f"prepare databases.") + tdSql.execute("drop database if exists test_vtable_auth_select;") + tdSql.execute("create database test_vtable_auth_select;") + tdSql.execute("drop database if exists test_vctable_auth_select;") + tdSql.execute("create database test_vctable_auth_select;") + + def test_select_virtual_normal_table(self): + tdSql.execute("use test_vtable_auth_select;") + tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") + tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") + tdSql.execute("create user test_vtable_user_select PASS 'test12@#*';") + tdSql.execute("create vtable test_vtable_auth_vtb_0(" + "ts timestamp, " + "int_col_1 int from test_vtable_auth_org_table_1.int_col, " + "int_col_2 int from test_vtable_auth_org_table_2.int_col);") + + priv_list = ["write", "read", "none", "all"] + + testconn = taos.connect(user='test_vtable_user_select', password='test12@#*') + cursor = testconn.cursor() + testSql = TDSql() + testSql.init(cursor) + + i = 0 + for priv_db in priv_list: + if (priv_db == "none"): + continue # meaningless to test db has no privilege + for priv_vtb in priv_list: + tdSql.execute("use test_vtable_auth_select;") + + tdSql.execute(f"grant {priv_db} on test_vtable_auth_select to test_vtable_user_select;") + if (priv_vtb != "none"): + tdSql.execute(f"grant {priv_vtb} on test_vtable_auth_select.test_vtable_auth_vtb_0 to test_vtable_user_select;") + + sleep(2) + + tdLog.info(f"priv_db: {priv_db}, priv_vtb: {priv_vtb}") + testSql.execute("use test_vtable_auth_select;") + if (priv_db == "read" or priv_db == "all"): + testSql.query("select * from test_vtable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_1 from test_vtable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_2 from test_vtable_auth_vtb_0;") + testSql.checkRows(0) + else: + if (priv_vtb == "read" or priv_vtb == "all"): + testSql.query("select * from test_vtable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_1 from test_vtable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_2 from test_vtable_auth_vtb_0;") + testSql.checkRows(0) + else: + testSql.error("select * from test_vtable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") + testSql.error("select int_col_1 from test_vtable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") + testSql.error("select int_col_2 from test_vtable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") + + tdSql.execute(f"revoke {priv_db} on test_vtable_auth_select from test_vtable_user_select;") + if (priv_vtb != "none"): + tdSql.execute(f"revoke {priv_vtb} on test_vtable_auth_select.test_vtable_auth_vtb_0 from test_vtable_user_select;") + i+=1 + + tdSql.execute("drop database test_vtable_auth_select;") + + def test_select_virtual_child_table(self): + tdSql.execute("use test_vctable_auth_select;") + tdSql.execute("create table test_vtable_auth_org_table_1(ts timestamp, int_col int);") + tdSql.execute("create table test_vtable_auth_org_table_2(ts timestamp, int_col int);") + tdSql.execute("create user test_vct_user_select PASS 'test12@#*';") + tdSql.execute("create stable test_vtable_auth_stb_1(ts timestamp, int_col_1 int, int_col_2 int) TAGS (int_tag int) virtual 1;") + tdSql.execute(f"create vtable test_vctable_auth_vtb_0(test_vtable_auth_org_table_1.int_col, test_vtable_auth_org_table_2.int_col) USING test_vtable_auth_stb_1 TAGS (1);") + + priv_list = ["write", "read", "none", "all"] + + testconn = taos.connect(user='test_vct_user_select', password='test12@#*') + cursor = testconn.cursor() + testSql = TDSql() + testSql.init(cursor) + + i = 0 + for priv_db in priv_list: + if (priv_db == "none"): + continue # meaningless to test db has no privilege + for priv_vtb in priv_list: + tdSql.execute("use test_vctable_auth_select;") + + tdSql.execute(f"grant {priv_db} on test_vctable_auth_select to test_vct_user_select;") + if (priv_vtb != "none"): + tdSql.execute(f"grant {priv_vtb} on test_vctable_auth_select.test_vtable_auth_stb_1 with int_tag = 1 to test_vct_user_select;") + + sleep(2) + + tdLog.info(f"priv_db: {priv_db}, priv_vtb: {priv_vtb}") + testSql.execute("use test_vctable_auth_select;") + if (priv_db == "read" or priv_db == "all"): + testSql.query("select * from test_vctable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_1 from test_vctable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_2 from test_vctable_auth_vtb_0;") + testSql.checkRows(0) + else: + if (priv_vtb == "read" or priv_vtb == "all"): + testSql.query("select * from test_vctable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_1 from test_vctable_auth_vtb_0;") + testSql.checkRows(0) + testSql.query("select int_col_2 from test_vctable_auth_vtb_0;") + testSql.checkRows(0) + else: + testSql.error("select * from test_vctable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") + testSql.error("select int_col_1 from test_vctable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") + testSql.error("select int_col_2 from test_vctable_auth_vtb_0;", expectErrInfo="Permission denied or target object not exist") + + tdSql.execute(f"revoke {priv_db} on test_vctable_auth_select from test_vct_user_select;") + if (priv_vtb != "none"): + tdSql.execute(f"revoke {priv_vtb} on test_vctable_auth_select.test_vtable_auth_stb_1 with int_tag = 1 from test_vct_user_select;") + i+=1 + + tdSql.execute("drop database if exists test_vctable_auth_select;") + + def run(self): + tdLog.debug(f"start to excute {__file__}") + + self.prepare_data() + self.test_select_virtual_normal_table() + self.test_select_virtual_child_table() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 9f13ae53daa..ae820a24fdf 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -28,7 +28,9 @@ ,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_alter.py ,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_drop.py ,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_meta.py -,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_auth.py +,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_auth_create.py +,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_auth_select.py +,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_auth_alter_drop.py ,,y,army,./pytest.sh python3 ./test.py -f vtable/test_vtable_query.py ,,y,army,./pytest.sh python3 ./test.py -f query/function/test_func_elapsed.py ,,y,army,./pytest.sh python3 ./test.py -f query/function/test_function.py diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 390bf3d9dd6..1beb46c4f49 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -222,7 +222,7 @@ def ins_columns_check(self): tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'") tdLog.info(len(tdSql.queryResult)) - tdSql.checkEqual(True, len(tdSql.queryResult) in range(312, 313)) + tdSql.checkEqual(True, len(tdSql.queryResult) in range(312, 315)) tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'") tdSql.checkEqual(61, len(tdSql.queryResult)) diff --git a/tests/system-test/2-query/odbc.py b/tests/system-test/2-query/odbc.py index 7daf5fd7302..8e3d7f8427c 100644 --- a/tests/system-test/2-query/odbc.py +++ b/tests/system-test/2-query/odbc.py @@ -42,7 +42,7 @@ def check_ins_cols(self): tdSql.checkData(5, 4, 8) tdSql.query("desc information_schema.ins_columns") - tdSql.checkRows(9) + tdSql.checkRows(10) tdSql.checkData(0, 0, "table_name") tdSql.checkData(5, 0, "col_length") tdSql.checkData(1, 2, 64)