#pragma once #include #include "common/case_insensitive_map.h" #include "common/types/value/value.h" #include "function/function.h" namespace lbug { namespace function { struct ExportFuncLocalState { virtual ~ExportFuncLocalState() = default; template TARGET& cast() { return common::dynamic_cast_checked(*this); } }; struct ExportFuncBindData; struct ExportFuncSharedState { virtual ~ExportFuncSharedState() = default; template TARGET& cast() { return common::dynamic_cast_checked(*this); } virtual void init(main::ClientContext& context, const ExportFuncBindData& bindData) = 0; std::atomic parallelFlag = true; }; struct ExportFuncBindData { std::vector columnNames; std::vector types; std::string fileName; ExportFuncBindData(std::vector columnNames, std::string fileName) : columnNames{std::move(columnNames)}, fileName{std::move(fileName)} {} virtual ~ExportFuncBindData() = default; void setDataType(std::vector types_) { types = std::move(types_); } template const TARGET& constCast() const { return common::dynamic_cast_checked(*this); } virtual std::unique_ptr copy() const = 0; }; struct ExportFuncBindInput { std::vector columnNames; std::string filePath; common::case_insensitive_map_t parsingOptions; }; using export_bind_t = std::function(function::ExportFuncBindInput& bindInput)>; using export_init_local_t = std::function( main::ClientContext&, const ExportFuncBindData&, std::vector)>; using export_create_shared_t = std::function()>; using export_init_shared_t = std::function; using export_sink_t = std::function>)>; using export_combine_t = std::function; using export_finalize_t = std::function; struct LBUG_API ExportFunction : public Function { ExportFunction() = default; explicit ExportFunction(std::string name) : Function{std::move(name), {}} {} ExportFunction(std::string name, export_init_local_t initLocal, export_create_shared_t createShared, export_init_shared_t initShared, export_sink_t copyToSink, export_combine_t copyToCombine, export_finalize_t copyToFinalize) : Function{std::move(name), {}}, initLocalState{std::move(initLocal)}, createSharedState{std::move(createShared)}, initSharedState{std::move(initShared)}, sink{std::move(copyToSink)}, combine{std::move(copyToCombine)}, finalize{std::move(copyToFinalize)} {} export_bind_t bind; export_init_local_t initLocalState; export_create_shared_t createSharedState; export_init_shared_t initSharedState; export_sink_t sink; export_combine_t combine; export_finalize_t finalize; }; struct ExportCSVFunction : public ExportFunction { static constexpr const char* name = "COPY_CSV"; static function_set getFunctionSet(); }; struct ExportParquetFunction : public ExportFunction { static constexpr const char* name = "COPY_PARQUET"; static function_set getFunctionSet(); }; // Consumes (src OFFSET, degree INT64) rows and writes a CSR indptr table: a single // "ptr" INT64 column with N+1 prefix-summed offsets, sorted by source offset. struct IndptrExportFunction : public ExportFunction { static constexpr const char* name = "COPY_INDPTR"; static function_set getFunctionSet(); }; } // namespace function } // namespace lbug