-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shaoting-huang <[email protected]>
- Loading branch information
1 parent
51b7244
commit 7d83835
Showing
15 changed files
with
330 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2023 Zilliz | ||
// | ||
// 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 | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <arrow/c/abi.h> | ||
|
||
typedef void* CPackedWriter; | ||
typedef void* CColumnOffsetMapping; | ||
|
||
int NewPackedWriter(const char* path, | ||
struct ArrowSchema* schema, | ||
const int64_t buffer_size, | ||
CPackedWriter* c_packed_writer); | ||
|
||
int WriteRecordBatch(CPackedWriter c_packed_writer, struct ArrowArray* array, struct ArrowSchema* schema); | ||
|
||
int Close(CPackedWriter c_packed_writer, CColumnOffsetMapping* c_column_offset_mapping); | ||
|
||
void DeletePackedWriter(CPackedWriter c_packed_writer); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 Zilliz | ||
// | ||
// 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. | ||
|
||
#include "packed/writer_c.h" | ||
#include "packed/writer.h" | ||
#include "common/log.h" | ||
#include "common/config.h" | ||
#include "filesystem/fs.h" | ||
|
||
#include <arrow/c/bridge.h> | ||
#include <arrow/filesystem/filesystem.h> | ||
#include <iostream> | ||
|
||
int NewPackedWriter(const char* path, | ||
struct ArrowSchema* schema, | ||
const int64_t buffer_size, | ||
CPackedWriter* c_packed_writer) { | ||
try { | ||
auto truePath = std::string(path); | ||
auto factory = std::make_shared<milvus_storage::FileSystemFactory>(); | ||
auto conf = milvus_storage::StorageConfig(); | ||
conf.uri = "file:///tmp/"; | ||
auto trueFs = factory->BuildFileSystem(conf, &truePath).value(); | ||
auto trueSchema = arrow::ImportSchema(schema).ValueOrDie(); | ||
auto writer = | ||
std::make_unique<milvus_storage::PackedRecordBatchWriter>(buffer_size, trueSchema, trueFs, truePath, conf); | ||
|
||
*c_packed_writer = writer.release(); | ||
return 0; | ||
} catch (std::exception& e) { | ||
return -1; | ||
} | ||
} | ||
|
||
int WriteRecordBatch(CPackedWriter c_packed_writer, struct ArrowArray* array, struct ArrowSchema* schema) { | ||
try { | ||
auto packed_writer = static_cast<milvus_storage::PackedRecordBatchWriter*>(c_packed_writer); | ||
auto record_batch = arrow::ImportRecordBatch(array, schema).ValueOrDie(); | ||
auto status = packed_writer->Write(record_batch); | ||
if (!status.ok()) { | ||
return -1; | ||
} | ||
return 0; | ||
} catch (std::exception& e) { | ||
return -1; | ||
} | ||
} | ||
|
||
int Close(CPackedWriter c_packed_writer, CColumnOffsetMapping* c_column_offset_mapping) { | ||
try { | ||
auto packed_writer = static_cast<milvus_storage::PackedRecordBatchWriter*>(c_packed_writer); | ||
*c_column_offset_mapping = packed_writer->Close().release(); | ||
delete packed_writer; | ||
return 0; | ||
} catch (std::exception& e) { | ||
return -1; | ||
} | ||
} |
Oops, something went wrong.