Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit cfd17e3

Browse files
committed
Updated optimize to continue support for old/weird/strange AF copy executor
1 parent 3876f95 commit cfd17e3

23 files changed

+316
-83
lines changed

src/common/internal_types.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,9 +1382,6 @@ std::string PlanNodeTypeToString(PlanNodeType type) {
13821382
case PlanNodeType::RESULT: {
13831383
return ("RESULT");
13841384
}
1385-
case PlanNodeType::COPY: {
1386-
return ("COPY");
1387-
}
13881385
case PlanNodeType::MOCK: {
13891386
return ("MOCK");
13901387
}
@@ -1394,6 +1391,9 @@ std::string PlanNodeTypeToString(PlanNodeType type) {
13941391
case PlanNodeType::ANALYZE: {
13951392
return ("ANALYZE");
13961393
}
1394+
case PlanNodeType::EXPORT_EXTERNAL_FILE: {
1395+
return ("EXPORT_EXTERNAL_FILE");
1396+
}
13971397
default: {
13981398
throw ConversionException(
13991399
StringUtil::Format("No string conversion for PlanNodeType value '%d'",
@@ -1461,12 +1461,12 @@ PlanNodeType StringToPlanNodeType(const std::string &str) {
14611461
return PlanNodeType::HASH;
14621462
} else if (upper_str == "RESULT") {
14631463
return PlanNodeType::RESULT;
1464-
} else if (upper_str == "COPY") {
1465-
return PlanNodeType::COPY;
14661464
} else if (upper_str == "MOCK") {
14671465
return PlanNodeType::MOCK;
14681466
} else if (upper_str == "ANALYZE") {
14691467
return PlanNodeType::ANALYZE;
1468+
} else if (upper_str == "EXPORT_EXTERNAL_FILE") {
1469+
return PlanNodeType::EXPORT_EXTERNAL_FILE;
14701470
} else {
14711471
throw ConversionException(StringUtil::Format(
14721472
"No PlanNodeType conversion from string '%s'", upper_str.c_str()));

src/executor/copy_executor.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66
//
77
// Identification: src/executor/copy_executor.cpp
88
//
9-
// Copyright (c) 2015-17, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "executor/copy_executor.h"
14+
15+
#include <sys/stat.h>
16+
#include <sys/mman.h>
17+
1318
#include "common/logger.h"
1419
#include "catalog/catalog.h"
1520
#include "concurrency/transaction_manager_factory.h"
16-
#include "executor/copy_executor.h"
1721
#include "executor/executor_context.h"
1822
#include "executor/logical_tile_factory.h"
19-
#include "planner/copy_plan.h"
23+
#include "planner/export_external_file_plan.h"
2024
#include "storage/table_factory.h"
2125
#include "network/postgres_protocol_handler.h"
2226
#include "common/exception.h"
2327
#include "common/macros.h"
24-
#include <sys/stat.h>
25-
#include <sys/mman.h>
2628

2729
namespace peloton {
2830
namespace executor {
@@ -35,7 +37,7 @@ CopyExecutor::CopyExecutor(const planner::AbstractPlan *node,
3537
ExecutorContext *executor_context)
3638
: AbstractExecutor(node, executor_context) {}
3739

38-
CopyExecutor::~CopyExecutor() {}
40+
CopyExecutor::~CopyExecutor() = default;
3941

4042
/**
4143
* @brief Basic initialization.
@@ -45,21 +47,19 @@ bool CopyExecutor::DInit() {
4547
PELOTON_ASSERT(children_.size() == 1);
4648

4749
// Grab info from plan node and check it
48-
const planner::CopyPlan &node = GetPlanNode<planner::CopyPlan>();
50+
const auto &node = GetPlanNode<planner::ExportExternalFilePlan>();
4951

50-
bool success = InitFileHandle(node.file_path.c_str(), "w");
52+
bool success = InitFileHandle(node.GetFileName().c_str(), "w");
5153

5254
if (success == false) {
53-
throw ExecutorException("Failed to create file " + node.file_path +
55+
throw ExecutorException("Failed to create file " + node.GetFileName() +
5456
". Try absolute path and make sure you have the "
5557
"permission to access this file.");
56-
return false;
5758
}
58-
LOG_DEBUG("Created target copy output file: %s", node.file_path.c_str());
59+
LOG_DEBUG("Created target copy output file: %s", node.GetFileName().c_str());
5960
return true;
6061
}
6162

62-
6363
bool CopyExecutor::InitFileHandle(const char *name, const char *mode) {
6464
auto file = fopen(name, mode);
6565
if (file == NULL) {

src/executor/plan_executor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ executor::AbstractExecutor *BuildExecutorTree(
328328
new executor::CreateFunctionExecutor(plan, executor_context);
329329
break;
330330

331-
case PlanNodeType::COPY:
331+
case PlanNodeType::EXPORT_EXTERNAL_FILE:
332332
child_executor = new executor::CopyExecutor(plan, executor_context);
333333
break;
334334

src/include/common/internal_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ enum class PlanNodeType {
596596

597597
// Utility
598598
RESULT = 70,
599-
COPY = 71,
599+
EXPORT_EXTERNAL_FILE = 71,
600600
CREATE_FUNC = 72,
601601

602602
// Test
@@ -1355,6 +1355,7 @@ enum class RuleType : uint32_t {
13551355
INNER_JOIN_TO_HASH_JOIN,
13561356
IMPLEMENT_DISTINCT,
13571357
IMPLEMENT_LIMIT,
1358+
EXPORT_EXTERNAL_FILE_TO_PHYSICAL,
13581359

13591360
// Don't move this one
13601361
RewriteDelimiter,

src/include/optimizer/child_property_deriver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ChildPropertyDeriver : public OperatorVisitor {
5959
void Visit(const PhysicalSortGroupBy *) override;
6060
void Visit(const PhysicalDistinct *) override;
6161
void Visit(const PhysicalAggregate *) override;
62+
void Visit(const PhysicalExportExternalFile *) override;
6263

6364
private:
6465
void DeriveForJoin();

src/include/optimizer/input_column_deriver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class InputColumnDeriver : public OperatorVisitor {
9393

9494
void Visit(const PhysicalAggregate *) override;
9595

96+
void Visit(const PhysicalExportExternalFile *) override;
97+
9698
private:
9799
/**
98100
* @brief Provide all tuple value expressions needed in the expression

src/include/optimizer/operator_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ enum class OpType {
7272
Update,
7373
Aggregate,
7474
HashGroupBy,
75-
SortGroupBy
75+
SortGroupBy,
76+
ExportExternalFile,
7677
};
7778

7879
//===--------------------------------------------------------------------===//

src/include/optimizer/operator_visitor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/include/optimizer/operator_visitor.h
88
//
9-
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -23,7 +23,7 @@ namespace optimizer {
2323

2424
class OperatorVisitor {
2525
public:
26-
virtual ~OperatorVisitor(){};
26+
virtual ~OperatorVisitor() = default;
2727

2828
// Physical operator
2929
virtual void Visit(const DummyScan *) {}
@@ -49,6 +49,7 @@ class OperatorVisitor {
4949
virtual void Visit(const PhysicalSortGroupBy *) {}
5050
virtual void Visit(const PhysicalDistinct *) {}
5151
virtual void Visit(const PhysicalAggregate *) {}
52+
virtual void Visit(const PhysicalExportExternalFile *) {}
5253

5354
// Logical operator
5455
virtual void Visit(const LeafOperator *) {}

src/include/optimizer/operators.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,19 @@ class LogicalUpdate : public OperatorNode<LogicalUpdate> {
325325
};
326326

327327
//===--------------------------------------------------------------------===//
328-
// External file get
328+
// Export to external file
329329
//===--------------------------------------------------------------------===//
330330
class LogicalExportExternalFile
331331
: public OperatorNode<LogicalExportExternalFile> {
332332
public:
333-
static Operator make();
333+
static Operator make(ExternalFileFormat format, std::string file_name);
334+
335+
bool operator==(const BaseOperatorNode &r) override;
336+
337+
hash_t Hash() const override;
338+
339+
ExternalFileFormat format;
340+
std::string file_name;
334341
};
335342

336343
//===--------------------------------------------------------------------===//
@@ -604,6 +611,22 @@ class PhysicalUpdate : public OperatorNode<PhysicalUpdate> {
604611
const std::vector<std::unique_ptr<parser::UpdateClause>> *updates;
605612
};
606613

614+
//===--------------------------------------------------------------------===//
615+
// Physical ExportExternalFile
616+
//===--------------------------------------------------------------------===//
617+
class PhysicalExportExternalFile
618+
: public OperatorNode<PhysicalExportExternalFile> {
619+
public:
620+
static Operator make(ExternalFileFormat format, std::string file_name);
621+
622+
bool operator==(const BaseOperatorNode &r) override;
623+
624+
hash_t Hash() const override;
625+
626+
ExternalFileFormat format;
627+
std::string file_name;
628+
};
629+
607630
//===--------------------------------------------------------------------===//
608631
// PhysicalHashGroupBy
609632
//===--------------------------------------------------------------------===//

src/include/optimizer/plan_generator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class PlanGenerator : public OperatorVisitor {
9494

9595
void Visit(const PhysicalAggregate *) override;
9696

97+
void Visit(const PhysicalExportExternalFile *) override;
98+
9799
private:
98100
/**
99101
* @brief Generate all tuple value expressions of a base table

0 commit comments

Comments
 (0)