Skip to content

Commit

Permalink
fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuzu CI committed Mar 15, 2024
1 parent 9951547 commit aedf08c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
35 changes: 8 additions & 27 deletions src/binder/bind/bind_import_database.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <fcntl.h>

#include "binder/binder.h"
#include "binder/copy/bound_file_scan_info.h"
#include "binder/copy/bound_import_database.h"
#include "common/exception/binder.h"
#include "common/file_system/virtual_file_system.h"
Expand All @@ -15,25 +14,6 @@ using namespace kuzu::parser;
namespace kuzu {
namespace binder {

// std::string replaceCopyFromPath(common::VirtualFileSystem* vfs, const std::string boundFilePath,
// std::string query){
// auto parsedStatements = Parser::parseQuery(query);
// auto result = std::string();
// for(auto &parsedStatement : parsedStatements){
// KU_ASSERT(parsedStatement->getStatementType()==StatementType::COPY_FROM);
// auto copyFromStatement = ku_dynamic_cast<const Statement*, const
// CopyFrom*>(parsedStatement.get()); KU_ASSERT(copyFromStatement->getFilePath().size()==1);
// auto csvFilePath = copyFromStatement->getFilePath()[0];
// auto extractedFileName = vfs->extractName(csvFilePath);
// csvFilePath=vfs->joinPath(boundFilePath, extractedFileName);
// auto csvConfig =
// CSVReaderConfig::construct(bindParsingOptions(copyFromStatement->getParsingOptionsRef()));
// result+="COPY "+ copyFromStatement->getTableName()+ " FROM '"+csvFilePath+"
// "+csvConfig.option.toCypher()+"';";
// }
// return result;
//}

std::string getQueryFromFile(
common::VirtualFileSystem* vfs, const std::string boundFilePath, const std::string fileName) {
auto filePath = vfs->joinPath(boundFilePath, fileName);
Expand All @@ -48,10 +28,7 @@ std::string getQueryFromFile(
auto fsize = fileInfo->getFileSize();
auto buffer = std::make_unique<char[]>(fsize);
fileInfo->readFile(buffer.get(), fsize);
auto query = std::string(buffer.get(), fsize);
return query;
// fileName==ImportDBConstants::COPY_NAME?
// replaceCopyFromPath(vfs,boundFilePath,query):std::string(buffer.get(), fsize);
return std::string(buffer.get(), fsize);
}

std::unique_ptr<BoundStatement> Binder::bindImportDatabaseClause(const Statement& statement) {
Expand All @@ -69,10 +46,14 @@ std::unique_ptr<BoundStatement> Binder::bindImportDatabaseClause(const Statement
KU_ASSERT(parsedStatement->getStatementType() == StatementType::COPY_FROM);
auto copyFromStatement =
ku_dynamic_cast<const Statement*, const CopyFrom*>(parsedStatement.get());
KU_ASSERT(copyFromStatement->getFilePath().size() == 1);
auto csvFilePath = copyFromStatement->getFilePath()[0];
KU_ASSERT(copyFromStatement->getSource()->type == common::ScanSourceType::FILE);
auto filePaths = ku_dynamic_cast<parser::BaseScanSource*, parser::FileScanSource*>(
copyFromStatement->getSource())
->filePaths;
KU_ASSERT(filePaths.size() == 1);
auto csvFilePath = filePaths[0];
auto extractedFileName = fs->extractName(csvFilePath);
csvFilePath = fs->joinPath(boundFilePath, extractedFileName);
csvFilePath = boundFilePath + "/" + extractedFileName;
auto csvConfig = CSVReaderConfig::construct(
bindParsingOptions(copyFromStatement->getParsingOptionsRef()));
auto csvQuery = "COPY " + copyFromStatement->getTableName() + " FROM '" + csvFilePath +
Expand Down
5 changes: 0 additions & 5 deletions src/include/parser/copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class CopyFrom : public Copy {
inline bool byColumn() const { return byColumn_; }

inline BaseScanSource* getSource() const { return source.get(); }
inline std::vector<std::string> getFilePath() const {
KU_ASSERT(source->type == common::ScanSourceType::FILE);
auto fileSource = dynamic_cast<FileScanSource*>(source.get());
return fileSource->filePaths;
}

inline std::string getTableName() const { return tableName; }

Expand Down

0 comments on commit aedf08c

Please sign in to comment.