Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support reading form csv file #550

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ add_custom_target(submit-p2
)

set(P3_FILES
"src/include/execution/executors/copy_file_executor.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not include in submission files, because it will not be modified by students

"src/include/execution/executors/aggregation_executor.h"
"src/include/execution/executors/delete_executor.h"
"src/include/execution/executors/filter_executor.h"
Expand Down
1 change: 1 addition & 0 deletions src/binder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(
bind_create.cpp
bind_insert.cpp
bind_select.cpp
bind_copy.cpp
bind_variable.cpp
bound_statement.cpp
fmt_impl.cpp
Expand Down
Empty file added src/binder/bind_copy.cpp
Empty file.
Empty file added src/execution/csv_reader.cpp
Empty file.
40 changes: 40 additions & 0 deletions src/include/execution/executors/copy_file_executor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2022 RisingLight Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <memory>
#include <unordered_map>
#include <utility>
#include <vector>

#include "common/util/hash_util.h"
#include "container/hash/hash_function.h"
#include "execution/executor_context.h"
#include "execution/executors/abstract_executor.h"
#include "execution/executors/copy_file_executor.h"
#include "execution/expressions/abstract_expression.h"
#include "execution/plans/aggregation_plan.h"
#include "storage/table/tuple.h"
#include "type/value_factory.h"

namespace bustub {
class CopyFileExecutor : public AbstractExecutor {
public:
void Init() override;

private:
const PhysicalCopyFileNode *plan_;
}
} // namespace bustub
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need to add a new line to avoid lint warnings

43 changes: 43 additions & 0 deletions src/include/execution/persist/csv_reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
// Copyright 2018-2023 Stichting DuckDB Foundation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice (including the next paragraph)
// shall be included in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//===----------------------------------------------------------------------===//

#pragma once

#include <vector>

#include "buffer/buffer_pool_manager.h"
#include "catalog/catalog.h"
#include "concurrency/transaction.h"
#include "concurrency/transaction_manager.h"
#include "execution/executor_context.h"
#include "execution/executor_factory.h"
#include "execution/executors/init_check_executor.h"
#include "execution/plans/abstract_plan.h"
#include "storage/table/tuple.h"

namespace bustub {
class BaseCsvReader {
public:
BaseCsvReader();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no implementation yet? 🤪

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I still read the duckdb code and I'm a little slow to catch on that.

~BaseCsvReader();
};
} // namespace bustub
3 changes: 2 additions & 1 deletion src/include/execution/plans/abstract_plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ enum class PlanType {
Sort,
TopN,
MockScan,
InitCheck
InitCheck,
PhysicalCopyFile,
};

class AbstractPlanNode;
Expand Down
39 changes: 39 additions & 0 deletions src/include/execution/plans/phsical_copy_file_plan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <string>
#include <utility>

#include "catalog/catalog.h"
#include "execution/expressions/abstract_expression.h"
#include "execution/plans/abstract_plan.h"
#include "fmt/core.h"

namespace bustub {

class PhysicalCopyFileNode : public AbstractPlanNode {
public:
/**
* Creates a new physical copy file plan node.
* @param output the output format of this scan plan node
*/
explicit PhysicalCopyFileNode(SchemaRef output) : AbstractPlanNode(std::move(output), {}) {}

auto GetType() const -> PlanType override { return PlanType::PhysicalCopyFile; }

BUSTUB_PLAN_NODE_CLONE_WITH_CHILDREN(PhysicalCopyFileNode);

protected:
auto PlanNodeToString() const -> std::string override {
return fmt::format("PhysicalCopy {{ file_path={} }}", path_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In BusTub we don't add Physical to the plan node name

}

private:
/** the relative file path */
std::string path_;

// column_type

// file_format(specify csv format)
};

} // namespace bustub
5 changes: 5 additions & 0 deletions test/csv/simple_test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name, id, favorite food
quincy, 1, hot dogs
beau, 2, cereal
abbey, 3, pizza
mrugesh, 4, ice cream