bkmgit commented on a change in pull request #11231:
URL: https://github.com/apache/arrow/pull/11231#discussion_r719112678



##########
File path: cpp/examples/arrow/compute_and_write_csv_example.cc
##########
@@ -0,0 +1,140 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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 <arrow/api.h>
+#include <arrow/compute/api_aggregate.h>
+#include <arrow/compute/cast.h>
+#include <arrow/compute/exec/expression.h>
+#include <arrow/csv/api.h>
+#include <arrow/csv/writer.h>
+#include <arrow/filesystem/filesystem.h>
+#include <arrow/io/file.h>
+#include <arrow/io/interfaces.h>
+#include <arrow/result.h>
+#include <arrow/status.h>
+
+#include <iostream>
+#include <vector>
+
+// Many operations in Apache arrow operate on
+// columns of data, and the columns of data are
+// assembled into a table. In this example, we
+// examine how to compare two arrays which are
+// combined to form a table that is then written
+// out to a CSV file.
+//
+// To run this example you can use
+// ./comparison_example uri
+//
+// where uri is the universal resource identifier
+// to the directory you want created on your
+// filesystem that output will be put into, for
+// example on a local linux system
+// ./comparison_example file:///$PWD
+
+int main(int argc, char** argv) {
+  if (argc < 2) {
+    std::cout << "Please enter the path to which you want data saved" << 
std::endl;
+    // Fake success for CI purposes.
+    return EXIT_SUCCESS;
+  }
+
+  // Make Arrays
+  arrow::NumericBuilder<arrow::Int64Type> int64_builder;
+  arrow::BooleanBuilder boolean_builder;
+
+  // Make place for 8 values in total
+  ARROW_RETURN_NOT_OK(int64_builder.Resize(8));
+  ARROW_RETURN_NOT_OK(boolean_builder.Resize(8));
+
+  // Bulk append the given values
+  std::vector<int64_t> int64_values = {1, 2, 3, 4, 5, 6, 7, 8};
+  ARROW_RETURN_NOT_OK(int64_builder.AppendValues(int64_values));
+  std::shared_ptr<arrow::Array> array_a;
+  ARROW_RETURN_NOT_OK(int64_builder.Finish(&array_a));
+  int64_builder.Reset();
+  int64_values = {2, 5, 1, 3, 6, 2, 7, 4};
+  std::shared_ptr<arrow::Array> array_b;
+  ARROW_RETURN_NOT_OK(int64_builder.AppendValues(int64_values));
+  ARROW_RETURN_NOT_OK(int64_builder.Finish(&array_b));
+
+  // Cast the arrays to their actual types
+  auto int64_array_a = std::static_pointer_cast<arrow::Int64Array>(array_a);
+  auto int64_array_b = std::static_pointer_cast<arrow::Int64Array>(array_b);
+  // Explicit comparison using a loop
+  for (int64_t i = 0; i < 8; i++) {
+    if ((!int64_array_a->IsNull(i)) & (!int64_array_b->IsNull(i))) {
+      bool comparison_result = int64_array_a->Value(i) > 
int64_array_b->Value(i);
+      boolean_builder.UnsafeAppend(comparison_result);
+    }
+  }
+  std::shared_ptr<arrow::Array> array_c;
+  ARROW_RETURN_NOT_OK(boolean_builder.Finish(&array_c));
+  std::cout << "Array explicitly compared" << std::endl;
+
+  // Try a compute function for comparison
+  arrow::Datum compared_datum;
+  std::shared_ptr<arrow::Array> array_d;
+  arrow::Result<arrow::Datum> st_compared_datum =
+      arrow::compute::CallFunction("greater", {array_a, array_b});
+  if (st_compared_datum.ok()) {
+    compared_datum = std::move(st_compared_datum).ValueOrDie();
+    array_d = compared_datum.make_array();
+  } else {
+    std::cerr << st_compared_datum.status() << std::endl;
+  }
+  std::cout << "Arrays compared using a compute function" << std::endl;
+  // Create a table
+  auto schema =
+      arrow::schema({arrow::field("a", arrow::int64()), 
+                     arrow::field("b", arrow::int64()),
+                     arrow::field("a>b? (self written)", arrow::boolean()),
+                     arrow::field("a>b? (arrow)", arrow::boolean())});
+  std::shared_ptr<arrow::Table> my_table =
+      arrow::Table::Make(schema, {array_a, array_b, array_c, array_d});
+
+  std::cout << "Table created" << std::endl;
+
+  // Create a folder to output the data
+  std::string uri = argv[1];
+  std::string root_path;
+  auto fs = arrow::fs::FileSystemFromUri(uri, &root_path).ValueOrDie();
+  std::string base_path = root_path + "/csv_dataset";
+  std::cout << "Base path " << base_path << std::endl;
+  ARROW_RETURN_NOT_OK(fs->CreateDir(base_path));

Review comment:
       @cyb70289 Appveyor build passes. Tests in C++ / AMD64 MacOS 10.15 C++  
pass, but then it seems to time out.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to