INT32 RecordParser::createInstance(INPUT_FORMAT format, const Options& options, RecordParser*& parser) { INT32 rc = SDB_OK; if (FORMAT_CSV == format) { CSVRecordParser* csvParser = SDB_OSS_NEW CSVRecordParser(options.fieldDelimiter(), options.stringDelimiter(), options.dateFormat(), options.timestampFormat(), options.trimString(), options.autoAddField(), options.autoCompletion(), options.hasHeaderLine(), options.cast(), options.ignoreNull(), options.force(), options.strictFieldNum()); if (NULL == csvParser) { rc = SDB_OOM; PD_LOG(PDERROR, "failed to create CSVRecordParser object, rc=%d", rc); goto error; } if (!options.fields().empty()) { PD_LOG(PDINFO, "fields: %s", options.fields().c_str()); if (options.verbose()) { std::cout << "fields: " << options.fields() << std::endl; } const CHAR* str = options.fields().c_str(); INT32 len = options.fields().length(); rc = csvParser->parseFields(str, len, FALSE); if (SDB_OK != rc) { std::cout << "failed to parse fields" << std::endl; PD_LOG(PDERROR, "failed to parse fields, rc=%d", rc); goto error; } if (options.verbose()) { csvParser->printFieldsDef(); } } parser = csvParser; } else { SDB_ASSERT(FORMAT_JSON == format, "format must be JSON"); JSONRecordParser* jsonParser = SDB_OSS_NEW JSONRecordParser(); if (NULL == jsonParser) { rc = SDB_OOM; PD_LOG(PDERROR, "failed to create JSONRecordParser object, rc=%d", rc); goto error; } rc = jsonParser->init() ; if( rc ) { PD_LOG( PDERROR, "failed to call JSONRecordParser init, rc=%d", rc ) ; goto error ; } parser = jsonParser; } done: return rc; error: goto done; }