Skip to content
Snippets Groups Projects
Commit a2d018b3 authored by Thomas Blum's avatar Thomas Blum
Browse files

Add copy analyser

parent 7ebe2e25
No related branches found
No related tags found
1 merge request!8Feature add copy statement
Pipeline #39206 canceled
......@@ -55,13 +55,18 @@ namespace semanticalAnalysis {
Relation relation;
std::vector<std::pair<Column,std::string>> selections;
};
struct CopyStatement {
Relation relation;
std::string filePath;
std::string format;
};
using BindingAttribute = std::pair<std::string, std::string>; // bindingName and attribute
struct SQLParserResult {
enum OpType : unsigned int {
Unknown, Select, Insert, Update, Delete, CreateTable, CreateBranch, Branch
Unknown, Select, Insert, Update, Delete, CreateTable, CreateBranch, Branch, Copy
} opType = Unknown;
CreateTableStatement *createTableStmt;
......@@ -70,6 +75,7 @@ namespace semanticalAnalysis {
SelectStatement *selectStmt;
UpdateStatement *updateStmt;
DeleteStatement *deleteStmt;
CopyStatement *copyStmt;
SQLParserResult() {}
~SQLParserResult() {
......@@ -94,6 +100,9 @@ namespace semanticalAnalysis {
break;
case Branch:
break;
case Copy:
delete copyStmt;
break;
case Unknown:
break;
}
......
......@@ -97,6 +97,13 @@ namespace semanticalAnalysis {
void verify() override;
void constructTree() override;
};
class CopyTableAnalyser : public SemanticAnalyser {
public:
CopyTableAnalyser(AnalyzingContext &context) : SemanticAnalyser(context) {}
void verify() override;
void constructTree() override;
};
}
......
......@@ -238,6 +238,9 @@ void QueryContext::convertToParserResult(semanticalAnalysis::SQLParserResult &de
case tardisParser::ParsingContext::Delete:
dest.opType = semanticalAnalysis::SQLParserResult::OpType::Delete;
break;
case tardisParser::ParsingContext::Copy:
dest.opType = semanticalAnalysis::SQLParserResult::OpType::Copy;
break;
}
source = tardisParser::ParsingContext();
}
......
//
// Created by Blum Thomas on 2020-06-29.
//
#include "semanticAnalyser/SemanticAnalyser.hpp"
#include "foundations/loader.hpp"
#include <fstream>
namespace semanticalAnalysis {
void CopyTableAnalyser::verify() {
Database &db = _context.db;
CopyStatement* stmt = _context.parserResult.copyStmt;
if (stmt == nullptr) throw semantic_sql_error("unknown statement type");
if (!db.hasTable(stmt->relation.name))
throw semantic_sql_error("table '" + stmt->relation.name + "' does not exist");
std::set<std::string> formats = { "CSV" };
if (std::find(formats.begin(),formats.end(),stmt->format) == formats.end())
throw semantic_sql_error("format type '" + stmt->format + "' does not exist");
}
void CopyTableAnalyser::constructTree() {
CopyStatement* stmt = _context.parserResult.copyStmt;
std::ifstream fs(stmt->filePath);
if (!fs) { throw std::runtime_error("file not found"); }
Table *table = _context.db.getTable(stmt->relation.name);
loadTable(fs, *table);
_context.joinedTree = nullptr;
}
}
\ No newline at end of file
......@@ -93,6 +93,8 @@ namespace semanticalAnalysis {
return std::make_unique<CreateBranchAnalyser>(context);
case SQLParserResult::OpType::Branch:
return std::make_unique<BranchAnalyser>(context);
case SQLParserResult::OpType::Copy:
return std::make_unique<CopyTableAnalyser>(context);
case SQLParserResult::OpType::Unknown:
return nullptr;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment