Merge pull request #18951 from taosdata/enh/td-21144

enh: ignore head line in cvs file
This commit is contained in:
Shengliang Guan 2022-12-17 22:29:56 +08:00 committed by GitHub
commit 7cd76335fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -1411,6 +1411,7 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt,
(*pNumOfRows) = 0; (*pNumOfRows) = 0;
char* pLine = NULL; char* pLine = NULL;
int64_t readLen = 0; int64_t readLen = 0;
bool firstLine = (pStmt->fileProcessing == false);
pStmt->fileProcessing = false; pStmt->fileProcessing = false;
while (TSDB_CODE_SUCCESS == code && (readLen = taosGetLineFile(pStmt->fp, &pLine)) != -1) { while (TSDB_CODE_SUCCESS == code && (readLen = taosGetLineFile(pStmt->fp, &pLine)) != -1) {
if (('\r' == pLine[readLen - 1]) || ('\n' == pLine[readLen - 1])) { if (('\r' == pLine[readLen - 1]) || ('\n' == pLine[readLen - 1])) {
@ -1418,6 +1419,7 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt,
} }
if (readLen == 0) { if (readLen == 0) {
firstLine = false;
continue; continue;
} }
@ -1431,6 +1433,11 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt,
strtolower(pLine, pLine); strtolower(pLine, pLine);
const char* pRow = pLine; const char* pRow = pLine;
code = parseOneRow(pCxt, (const char**)&pRow, pDataBuf, &gotRow, &token); code = parseOneRow(pCxt, (const char**)&pRow, pDataBuf, &gotRow, &token);
if (code && firstLine) {
firstLine = false;
code = 0;
continue;
}
} }
if (TSDB_CODE_SUCCESS == code && gotRow) { if (TSDB_CODE_SUCCESS == code && gotRow) {
@ -1442,6 +1449,8 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt,
pStmt->fileProcessing = true; pStmt->fileProcessing = true;
break; break;
} }
firstLine = false;
} }
taosMemoryFree(pLine); taosMemoryFree(pLine);