tname.h 3.8 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

H
hjxilinx 已提交
16 17 18
#ifndef TDENGINE_NAME_H
#define TDENGINE_NAME_H

19 20
#include "os.h"
#include "taosmsg.h"
H
Haojun Liao 已提交
21
#include "tstoken.h"
22
#include "tvariant.h"
23 24 25 26 27 28 29 30 31 32 33

typedef struct SDataStatis {
  int16_t colId;
  int64_t sum;
  int64_t max;
  int64_t min;
  int16_t maxIndex;
  int16_t minIndex;
  int16_t numOfNull;
} SDataStatis;

H
hjxilinx 已提交
34
typedef struct SColumnInfoData {
35
  SColumnInfo info;
H
Haojun Liao 已提交
36
  char* pData;    // the corresponding block data in memory
H
hjxilinx 已提交
37
} SColumnInfoData;
38

39 40 41 42 43
typedef struct SResPair {
  TSKEY  key;
  double avg;
} SResPair;

H
Haojun Liao 已提交
44
// the structure for sql function in select clause
H
Haojun Liao 已提交
45 46 47
typedef struct SSqlExpr {
  char      aliasName[TSDB_COL_NAME_LEN];  // as aliasName
  SColIndex colInfo;
H
Haojun Liao 已提交
48

H
Haojun Liao 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  uint64_t  uid;            // refactor use the pointer

  int16_t   functionId;     // function id in aAgg array

  int16_t   resType;        // return value type
  int16_t   resBytes;       // length of return value
  int32_t   interBytes;     // inter result buffer size

  int16_t   colType;        // table column type
  int16_t   colBytes;       // table column bytes

  int16_t   numOfParams;    // argument value of each function
  tVariant  param[3];       // parameters are not more than 3
  int32_t   offset;         // sub result column value of arithmetic expression.
  int16_t   resColId;       // result column id
H
Haojun Liao 已提交
64

65
  SColumnFilterList flist;
H
Haojun Liao 已提交
66 67 68
} SSqlExpr;

typedef struct SExprInfo {
H
Haojun Liao 已提交
69 70
  SSqlExpr           base;
  struct tExprNode  *pExpr;
H
Haojun Liao 已提交
71 72
} SExprInfo;

73 74 75 76 77 78 79 80 81 82 83 84 85 86
#define TSDB_DB_NAME_T     1
#define TSDB_TABLE_NAME_T  2

#define T_NAME_ACCT     0x1u
#define T_NAME_DB       0x2u
#define T_NAME_TABLE    0x4u

typedef struct SName {
  uint8_t type;  //db_name_t, table_name_t
  char acctId[TSDB_ACCT_ID_LEN];
  char dbname[TSDB_DB_NAME_LEN];
  char tname[TSDB_TABLE_NAME_LEN];
} SName;

87
void extractTableName(const char *tableId, char *name);
H
hjxilinx 已提交
88 89 90

char* extractDBName(const char *tableId, char *name);

91
size_t tableIdPrefix(const char* name, char* prefix, int32_t len);
92

H
Haojun Liao 已提交
93
void extractTableNameFromToken(SStrToken *pToken, SStrToken* pTable);
H
Haojun Liao 已提交
94

95
//SSchema tGetTbnameColumnSchema();
H
Haojun Liao 已提交
96

Y
yihaoDeng 已提交
97 98
SSchema tGetBlockDistColumnSchema();

H
Haojun Liao 已提交
99
SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const char* name);
H
Haojun Liao 已提交
100

H
Haojun Liao 已提交
101
bool tscValidateTableNameLength(size_t len);
102

103
SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFilters);
H
Haojun Liao 已提交
104

105
SSchema* tGetTbnameColumnSchema();
H
Haojun Liao 已提交
106

H
Haojun Liao 已提交
107 108 109 110 111 112 113 114 115 116 117 118
/**
 * check if the schema is valid or not, including following aspects:
 * 1. number of columns
 * 2. column types
 * 3. column length
 * 4. column names
 * 5. total length
 *
 * @param pSchema
 * @param numOfCols
 * @return
 */
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);

int32_t tNameExtractFullName(const SName* name, char* dst);
int32_t tNameLen(const SName* name);

SName* tNameDup(const SName* name);

bool tIsValidName(const SName* name);

const char* tNameGetTableName(const SName* name);

int32_t tNameGetDbName(const SName* name, char* dst);
int32_t tNameGetFullDbName(const SName* name, char* dst);

bool tNameIsEmpty(const SName* name);

void tNameAssign(SName* dst, const SName* src);

int32_t tNameFromString(SName* dst, const char* str, uint32_t type);

int32_t tNameSetAcctId(SName* dst, const char* acct);

int32_t tNameSetDbName(SName* dst, const char* acct, SStrToken* dbToken);
H
Haojun Liao 已提交
142

H
hjxilinx 已提交
143
#endif  // TDENGINE_NAME_H