MCPcopy Create free account
hub / github.com/apache/arrow / ARROW_ASSIGN_OR_RAISE

Function ARROW_ASSIGN_OR_RAISE

cpp/examples/arrow/dataset_documentation_example.cc:78–183  ·  view source on GitHub ↗

Write it into two Parquet files

Source from the content-addressed store, hash-verified

76 ARROW_ASSIGN_OR_RAISE(auto table, CreateTable());
77 // Write it into two Parquet files
78 ARROW_ASSIGN_OR_RAISE(auto output,
79 filesystem->OpenOutputStream(base_path + "/data1.parquet"));
80 ARROW_RETURN_NOT_OK(parquet::arrow::WriteTable(
81 *table->Slice(0, 5), arrow::default_memory_pool(), output, /*chunk_size=*/2048));
82 ARROW_ASSIGN_OR_RAISE(output,
83 filesystem->OpenOutputStream(base_path + "/data2.parquet"));
84 ARROW_RETURN_NOT_OK(parquet::arrow::WriteTable(
85 *table->Slice(5), arrow::default_memory_pool(), output, /*chunk_size=*/2048));
86 return base_path;
87}
88// (Doc section: Reading Datasets)
89
90// (Doc section: Reading different file formats)
91// Set up a dataset by writing two Feather files.
92arrow::Result<std::string> CreateExampleFeatherDataset(
93 const std::shared_ptr<fs::FileSystem>& filesystem, const std::string& root_path) {
94 auto base_path = root_path + "/feather_dataset";
95 ARROW_RETURN_NOT_OK(filesystem->CreateDir(base_path));
96 // Create an Arrow Table
97 ARROW_ASSIGN_OR_RAISE(auto table, CreateTable());
98 // Write it into two Feather files
99 ARROW_ASSIGN_OR_RAISE(auto output,
100 filesystem->OpenOutputStream(base_path + "/data1.feather"));
101 ARROW_ASSIGN_OR_RAISE(auto writer,
102 arrow::ipc::MakeFileWriter(output.get(), table->schema()));
103 ARROW_RETURN_NOT_OK(writer->WriteTable(*table->Slice(0, 5)));
104 ARROW_RETURN_NOT_OK(writer->Close());
105 ARROW_ASSIGN_OR_RAISE(output,
106 filesystem->OpenOutputStream(base_path + "/data2.feather"));
107 ARROW_ASSIGN_OR_RAISE(writer,
108 arrow::ipc::MakeFileWriter(output.get(), table->schema()));
109 ARROW_RETURN_NOT_OK(writer->WriteTable(*table->Slice(5)));
110 ARROW_RETURN_NOT_OK(writer->Close());
111 return base_path;
112}
113// (Doc section: Reading different file formats)
114
115// (Doc section: Reading and writing partitioned data)
116// Set up a dataset by writing files with partitioning
117arrow::Result<std::string> CreateExampleParquetHivePartitionedDataset(
118 const std::shared_ptr<fs::FileSystem>& filesystem, const std::string& root_path) {
119 auto base_path = root_path + "/parquet_dataset";
120 ARROW_RETURN_NOT_OK(filesystem->CreateDir(base_path));
121 // Create an Arrow Table
122 auto schema = arrow::schema(
123 {arrow::field("a", arrow::int64()), arrow::field("b", arrow::int64()),
124 arrow::field("c", arrow::int64()), arrow::field("part", arrow::utf8())});
125 std::vector<std::shared_ptr<arrow::Array>> arrays(4);
126 arrow::NumericBuilder<arrow::Int64Type> builder;
127 ARROW_RETURN_NOT_OK(builder.AppendValues({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
128 ARROW_RETURN_NOT_OK(builder.Finish(&arrays[0]));
129 builder.Reset();
130 ARROW_RETURN_NOT_OK(builder.AppendValues({9, 8, 7, 6, 5, 4, 3, 2, 1, 0}));
131 ARROW_RETURN_NOT_OK(builder.Finish(&arrays[1]));
132 builder.Reset();
133 ARROW_RETURN_NOT_OK(builder.AppendValues({1, 2, 1, 2, 1, 2, 1, 2, 1, 2}));
134 ARROW_RETURN_NOT_OK(builder.Finish(&arrays[2]));
135 arrow::StringBuilder string_builder;

Callers 15

MainFunction · 0.70
RunDatasetDocumentationFunction · 0.70
ReadFullFileFunction · 0.70
ReadInBatchesFunction · 0.70
GetRBRFunction · 0.70
WriteFullFileFunction · 0.70
WriteInBatchesFunction · 0.70
MakeGroupableBatchesFunction · 0.70
ScanFilterSinkExampleFunction · 0.70
ScanProjectSinkExampleFunction · 0.70

Calls 15

MakeFileWriterFunction · 0.85
arraysFunction · 0.85
WriteFunction · 0.85
NewScanMethod · 0.80
CreateTableFunction · 0.70
schemaFunction · 0.50
fieldFunction · 0.50
MakeFunction · 0.50
CreateDirMethod · 0.45
OpenOutputStreamMethod · 0.45
getMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected