@Override
    public TListTableStatusResult listTableStatus(TGetTablesParams params) throws TException {
        LOG.debug("get list table request: {}", params);
        TListTableStatusResult result = new TListTableStatusResult();
        List<TTableStatus> tablesResult = Lists.newArrayList();
        result.setTables(tablesResult);
        PatternMatcher matcher = null;
        boolean caseSensitive = CaseSensibility.TABLE.getCaseSensibility();
        if (params.isSetPattern()) {
            try {
                matcher = PatternMatcher.createMysqlPattern(params.getPattern(), caseSensitive);
            } catch (SemanticException e) {
                throw new TException("Pattern is in bad format " + params.getPattern());
            }
        }

        Database db = GlobalStateMgr.getCurrentState().getDb(params.db);
        long limit = params.isSetLimit() ? params.getLimit() : -1;
        UserIdentity currentUser;
        if (params.isSetCurrent_user_ident()) {
            currentUser = UserIdentity.fromThrift(params.current_user_ident);
        } else {
            currentUser = UserIdentity.createAnalyzedUserIdentWithIp(params.user, params.user_ip);
        }
        if (db != null) {
            Locker locker = new Locker();
            locker.lockDatabase(db, LockType.READ);
            try {
                boolean listingViews = params.isSetType() && TTableType.VIEW.equals(params.getType());
                List<Table> tables = listingViews ? db.getViews() : db.getTables();
                OUTER:
                for (Table table : tables) {
                    try {
                        Authorizer.checkAnyActionOnTableLikeObject(currentUser,
                                null, params.db, table);
                    } catch (AccessDeniedException e) {
                        continue;
                    }

                    if (!PatternMatcher.matchPattern(params.getPattern(), table.getName(), matcher, caseSensitive)) {
                        continue;
                    }

                    TTableStatus status = new TTableStatus();
                    status.setName(table.getName());
                    status.setType(table.getMysqlType());
                    status.setEngine(table.getEngine());
                    status.setComment(table.getComment());
                    status.setCreate_time(table.getCreateTime());
                    status.setLast_check_time(table.getLastCheckTime());
                    if (listingViews) {
                        View view = (View) table;
                        String ddlSql = view.getInlineViewDef();

                        ConnectContext connectContext = new ConnectContext();
                        connectContext.setQualifiedUser(AuthenticationMgr.ROOT_USER);
                        connectContext.setCurrentUserIdentity(UserIdentity.ROOT);
                        connectContext.setCurrentRoleIds(Sets.newHashSet(PrivilegeBuiltinConstants.ROOT_ROLE_ID));

                        try {
                            List<TableName> allTables = view.getTableRefs();
                            for (TableName tableName : allTables) {
                                Table tbl = db.getTable(tableName.getTbl());
                                if (tbl != null) {
                                    try {
                                        Authorizer.checkAnyActionOnTableLikeObject(currentUser,
                                                null, db.getFullName(), tbl);
                                    } catch (AccessDeniedException e) {
                                        continue OUTER;
                                    }
                                }
                            }
                        } catch (SemanticException e) {
                            // ignore semantic exception because view maybe invalid
                        }
                        status.setDdl_sql(ddlSql);
                    }

                    tablesResult.add(status);
                    // if user set limit, then only return limit size result
                    if (limit > 0 && tablesResult.size() >= limit) {
                        break;
                    }
                }
            } finally {
                locker.unLockDatabase(db, LockType.READ);
            }
        }
        return result;
    }
@Test
    public void testListTableStatus() throws TException {
        FrontendServiceImpl impl = new FrontendServiceImpl(exeEnv);
        TListTableStatusResult result = impl.listTableStatus(buildListTableStatusParam());
        Assert.assertEquals(7, result.tables.size());
    }