0

According to the document of TDengine,

The maximum length of a column name is 64.

I want to change it from 64 to 100 in source code, and build a new version.

Then I found taosdef.h,and changed it:

#define TSDB_COL_NAME_LEN   100

Then I built it successfully.

I tried to create a table with a column's name exceeding 64, but I failed.

 invalid column name 

How do I fix it?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
superman
  • 1
  • 4

1 Answers1

0

There are many ways to produce that error (or similar errors). Correcting one doesn't mean there aren't other issues too.

Please show the exact statement executed (and the exact / complete error) that caused the error.

Add breakpoints or otherwise trace execution to find the source of the issue.

The problem is likely somewhere in the following (maybe validateColumnName), but that might change if the above detail isn't precise:

validateStateWindowNode
validateSessionNode
validateTableColumnInfo  <===== which then calls validateColumnName
validateOneColumn
handleArithmeticExpr
addProjectionExprAndResultField
doGetColumnIndexByName
validateGroupbyNode
checkAndSetJoinCondInfo
doAddJoinTagsColumnsIntoTagList
validateOrderbyNode
setAlterTableInfo


./src/client/src/tscSQLParser.c

validateTableColumnInfo
    if (validateColumnName(pField->name) != TSDB_CODE_SUCCESS) {
      invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
      return false;
    }


int32_t validateColumnName(char* name) {
  bool ret = taosIsKeyWordToken(name, (int32_t)strlen(name));
  if (ret) {
    return TSDB_CODE_TSC_INVALID_OPERATION;
  }

  SStrToken token = {.z = name};
  token.n = tGetToken(name, &token.type);

  if (token.type != TK_STRING && token.type != TK_ID) {
    return TSDB_CODE_TSC_INVALID_OPERATION;
  }

  if (token.type == TK_STRING) {
    strdequote(token.z);
    strntolower(token.z, token.z, token.n);
    token.n = (uint32_t)strtrim(token.z);

    int32_t k = tGetToken(token.z, &token.type);
    if (k != token.n) {
      return TSDB_CODE_TSC_INVALID_OPERATION;
    }

    return validateColumnName(token.z);
  } else {
    if (isNumber(&token)) {
      return TSDB_CODE_TSC_INVALID_OPERATION;
    }
  }

  return TSDB_CODE_SUCCESS;
}


$ find . -name "*.[ch]" | xargs grep "taosIsKeyWordToken"
./src/client/src/tscSQLParser.c:  bool ret = taosIsKeyWordToken(name, (int32_t)strlen(name));
./src/util/inc/ttoken.h:bool taosIsKeyWordToken(const char *z, int32_t len);
./src/util/src/ttokenizer.c:bool taosIsKeyWordToken(const char* z, int32_t len) {

./src/util/src/ttokenizer.c:bool taosIsKeyWordToken(const char* z, int32_t len) {


./src/util/src/ttokenizer.c

bool taosIsKeyWordToken(const char* z, int32_t len) {
  return (tKeywordCode((char*)z, len) != TK_ID);
}

static int32_t tKeywordCode(const char* z, int n) {
  pthread_once(&keywordsHashTableInit, doInitKeywordsTable);
  
  char key[512] = {0};
  if (n > tListLen(key)) { // too long token, can not be any other token type
    return TK_ID;
  }
  
  for (int32_t j = 0; j < n; ++j) {
    if (z[j] >= 'a' && z[j] <= 'z') {
      key[j] = (char)(z[j] & 0xDF);  // to uppercase and set the null-terminated
    } else {
      key[j] = z[j];
    }
  }

  SKeyword** pKey = (SKeyword**)taosHashGet(keywordHashTable, key, n);
  return (pKey != NULL)? (*pKey)->type:TK_ID;
}
Jon Armstrong
  • 4,654
  • 2
  • 12
  • 14