You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/03/07 23:39:29 UTC
[arrow] branch master updated: ARROW-4710: [C++][R] New linting
script skip files with "cpp" extension
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 0249f19 ARROW-4710: [C++][R] New linting script skip files with "cpp" extension
0249f19 is described below
commit 0249f19eeea9fca2f7dfe1f4e56071732074691b
Author: Romain Francois <ro...@purrple.cat>
AuthorDate: Thu Mar 7 17:39:21 2019 -0600
ARROW-4710: [C++][R] New linting script skip files with "cpp" extension
This replaces/finishes @wesm #3776, I did not know how to not open my own branch/pr.
Author: Romain Francois <ro...@purrple.cat>
Author: Wes McKinney <we...@apache.org>
Closes #3835 from romainfrancois/check-cpp-files and squashes the following commits:
fc1af047 <Romain Francois> linting
47239137 <Romain Francois> Do not use namespace using-directives
71f11f07 <Romain Francois> linting on feather.cpp
e7dfd8ed <Romain Francois> #include "./arrow_types.h"
db151044 <Wes McKinney> Also run cpplint and clang-format on .cpp files
---
cpp/build-support/lintutils.py | 4 +-
cpp/build-support/run_cpplint.py | 2 -
r/clang_format.sh | 28 ++
r/src/RcppExports.cpp | 16 +-
r/src/array.cpp | 6 +-
r/src/array__to_vector.cpp | 154 ++++++-----
r/src/array_from_vector.cpp | 580 +++++++++++++++++++--------------------
r/src/arraydata.cpp | 5 +-
r/src/buffer.cpp | 2 +-
r/src/chunkedarray.cpp | 6 +-
r/src/column.cpp | 2 +-
r/src/compression.cpp | 2 +-
r/src/compute.cpp | 5 +-
r/src/csv.cpp | 5 +-
r/src/datatype.cpp | 7 +-
r/src/feather.cpp | 6 +-
r/src/field.cpp | 4 +-
r/src/io.cpp | 4 +-
r/src/memorypool.cpp | 4 +-
r/src/message.cpp | 4 +-
r/src/recordbatch.cpp | 22 +-
r/src/recordbatchreader.cpp | 2 +-
r/src/recordbatchwriter.cpp | 2 +-
r/src/symbols.cpp | 2 +-
r/src/table.cpp | 5 +-
r/src/threadpool.cpp | 2 +-
26 files changed, 456 insertions(+), 425 deletions(-)
diff --git a/cpp/build-support/lintutils.py b/cpp/build-support/lintutils.py
index 012d42b..2386eb2 100644
--- a/cpp/build-support/lintutils.py
+++ b/cpp/build-support/lintutils.py
@@ -66,13 +66,15 @@ def run_parallel(cmds, **kwargs):
_source_extensions = '''
.h
.cc
+.cpp
'''.split()
def get_sources(source_dir, exclude_globs=[]):
sources = []
for directory, subdirs, basenames in os.walk(source_dir):
- for path in [os.path.join(directory, basename) for basename in basenames]:
+ for path in [os.path.join(directory, basename)
+ for basename in basenames]:
# filter out non-source files
if os.path.splitext(path)[1] not in _source_extensions:
continue
diff --git a/cpp/build-support/run_cpplint.py b/cpp/build-support/run_cpplint.py
index 171f173..d291b61 100755
--- a/cpp/build-support/run_cpplint.py
+++ b/cpp/build-support/run_cpplint.py
@@ -110,8 +110,6 @@ if __name__ == "__main__":
# distill a list of problematic files
for problem_files, stdout in pool.imap(checker, chunks):
if problem_files:
- msg = "{} had cpplint issues"
- print("\n".join(map(msg.format, problem_files)))
if isinstance(stdout, bytes):
stdout = stdout.decode('utf8')
print(stdout, file=sys.stderr)
diff --git a/r/clang_format.sh b/r/clang_format.sh
new file mode 100755
index 0000000..0bb5e07
--- /dev/null
+++ b/r/clang_format.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# 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.
+
+SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+CPP_BUILD_SUPPORT=$SOURCE_DIR/../cpp/build-support
+
+# Run clang-format
+CLANG_FORMAT=clang-format-7
+$CPP_BUILD_SUPPORT/run_clang_format.py \
+ --clang_format_binary=$CLANG_FORMAT \
+ --exclude_glob=$CPP_BUILD_SUPPORT/lint_exclusions.txt \
+ --source_dir=$SOURCE_DIR/src --quiet --fix $1
diff --git a/r/src/RcppExports.cpp b/r/src/RcppExports.cpp
index 6f78fcf..b39e635 100644
--- a/r/src/RcppExports.cpp
+++ b/r/src/RcppExports.cpp
@@ -227,7 +227,7 @@ BEGIN_RCPP
END_RCPP
}
// RecordBatch__to_dataframe
-List RecordBatch__to_dataframe(const std::shared_ptr<arrow::RecordBatch>& batch, bool use_threads);
+Rcpp::List RecordBatch__to_dataframe(const std::shared_ptr<arrow::RecordBatch>& batch, bool use_threads);
RcppExport SEXP _arrow_RecordBatch__to_dataframe(SEXP batchSEXP, SEXP use_threadsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
@@ -239,7 +239,7 @@ BEGIN_RCPP
END_RCPP
}
// Table__to_dataframe
-List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table, bool use_threads);
+Rcpp::List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table, bool use_threads);
RcppExport SEXP _arrow_Table__to_dataframe(SEXP tableSEXP, SEXP use_threadsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
@@ -274,12 +274,12 @@ BEGIN_RCPP
END_RCPP
}
// ChunkedArray__from_list
-std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(List chunks, SEXP s_type);
+std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(Rcpp::List chunks, SEXP s_type);
RcppExport SEXP _arrow_ChunkedArray__from_list(SEXP chunksSEXP, SEXP s_typeSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
- Rcpp::traits::input_parameter< List >::type chunks(chunksSEXP);
+ Rcpp::traits::input_parameter< Rcpp::List >::type chunks(chunksSEXP);
Rcpp::traits::input_parameter< SEXP >::type s_type(s_typeSEXP);
rcpp_result_gen = Rcpp::wrap(ChunkedArray__from_list(chunks, s_type));
return rcpp_result_gen;
@@ -1941,12 +1941,12 @@ BEGIN_RCPP
END_RCPP
}
// RecordBatch__from_dataframe
-std::shared_ptr<arrow::RecordBatch> RecordBatch__from_dataframe(DataFrame tbl);
+std::shared_ptr<arrow::RecordBatch> RecordBatch__from_dataframe(Rcpp::DataFrame tbl);
RcppExport SEXP _arrow_RecordBatch__from_dataframe(SEXP tblSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
- Rcpp::traits::input_parameter< DataFrame >::type tbl(tblSEXP);
+ Rcpp::traits::input_parameter< Rcpp::DataFrame >::type tbl(tblSEXP);
rcpp_result_gen = Rcpp::wrap(RecordBatch__from_dataframe(tbl));
return rcpp_result_gen;
END_RCPP
@@ -1988,7 +1988,7 @@ BEGIN_RCPP
END_RCPP
}
// RecordBatch__names
-CharacterVector RecordBatch__names(const std::shared_ptr<arrow::RecordBatch>& batch);
+Rcpp::CharacterVector RecordBatch__names(const std::shared_ptr<arrow::RecordBatch>& batch);
RcppExport SEXP _arrow_RecordBatch__names(SEXP batchSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
@@ -2024,7 +2024,7 @@ BEGIN_RCPP
END_RCPP
}
// ipc___SerializeRecordBatch__Raw
-RawVector ipc___SerializeRecordBatch__Raw(const std::shared_ptr<arrow::RecordBatch>& batch);
+Rcpp::RawVector ipc___SerializeRecordBatch__Raw(const std::shared_ptr<arrow::RecordBatch>& batch);
RcppExport SEXP _arrow_ipc___SerializeRecordBatch__Raw(SEXP batchSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
diff --git a/r/src/array.cpp b/r/src/array.cpp
index 0749f2f..9ef8f5f 100644
--- a/r/src/array.cpp
+++ b/r/src/array.cpp
@@ -15,10 +15,10 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
-using namespace Rcpp;
-using namespace arrow;
+using Rcpp::LogicalVector;
+using Rcpp::no_init;
// [[Rcpp::export]]
std::shared_ptr<arrow::Array> Array__Slice1(const std::shared_ptr<arrow::Array>& array,
diff --git a/r/src/array__to_vector.cpp b/r/src/array__to_vector.cpp
index af9cdb4..d4eec29 100644
--- a/r/src/array__to_vector.cpp
+++ b/r/src/array__to_vector.cpp
@@ -17,17 +17,21 @@
#include <arrow/util/parallel.h>
#include <arrow/util/task-group.h>
-#include "arrow_types.h"
-
-using namespace Rcpp;
-using namespace arrow;
+#include "./arrow_types.h"
namespace arrow {
namespace r {
+using Rcpp::default_value;
+using Rcpp::IntegerVector;
+using Rcpp::LogicalVector_;
+using Rcpp::no_init;
+using Rcpp::Shield;
+using Rcpp::StringVector_;
+
class Converter {
public:
- Converter(const ArrayVector& arrays) : arrays_(arrays) {}
+ explicit Converter(const ArrayVector& arrays) : arrays_(arrays) {}
virtual ~Converter() {}
@@ -90,7 +94,7 @@ class Converter {
template <int RTYPE>
Status AllNull_Ingest(SEXP data, R_xlen_t start, R_xlen_t n) {
auto p_data = Rcpp::internal::r_vector_start<RTYPE>(data) + start;
- std::fill_n(p_data, n, default_value<RTYPE>());
+ std::fill_n(p_data, n, Rcpp::default_value<RTYPE>());
return Status::OK();
}
@@ -133,7 +137,7 @@ class Converter_SimpleArray : public Converter {
using value_type = typename Vector::stored_type;
public:
- Converter_SimpleArray(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_SimpleArray(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const { return Vector(no_init(n)); }
@@ -151,7 +155,8 @@ class Converter_SimpleArray : public Converter {
class Converter_Date32 : public Converter_SimpleArray<INTSXP> {
public:
- Converter_Date32(const ArrayVector& arrays) : Converter_SimpleArray<INTSXP>(arrays) {}
+ explicit Converter_Date32(const ArrayVector& arrays)
+ : Converter_SimpleArray<INTSXP>(arrays) {}
SEXP Allocate(R_xlen_t n) const {
IntegerVector data(no_init(n));
@@ -162,7 +167,7 @@ class Converter_Date32 : public Converter_SimpleArray<INTSXP> {
struct Converter_String : public Converter {
public:
- Converter_String(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_String(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const { return StringVector_(no_init(n)); }
@@ -225,7 +230,7 @@ struct Converter_String : public Converter {
class Converter_Boolean : public Converter {
public:
- Converter_Boolean(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_Boolean(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const { return LogicalVector_(no_init(n)); }
@@ -261,7 +266,7 @@ class Converter_Boolean : public Converter {
class Converter_Dictionary : public Converter {
public:
- Converter_Dictionary(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_Dictionary(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const {
IntegerVector data(no_init(n));
@@ -276,19 +281,19 @@ class Converter_Dictionary : public Converter {
case Type::INT32:
break;
default:
- stop("Cannot convert Dictionary Array of type `%s` to R",
- dict_array->type()->ToString());
+ Rcpp::stop("Cannot convert Dictionary Array of type `%s` to R",
+ dict_array->type()->ToString());
}
if (dict->type_id() != Type::STRING) {
- stop("Cannot convert Dictionary Array of type `%s` to R",
- dict_array->type()->ToString());
+ Rcpp::stop("Cannot convert Dictionary Array of type `%s` to R",
+ dict_array->type()->ToString());
}
bool ordered = dict_array->dict_type()->ordered();
data.attr("levels") = ArrayVector__as_vector(dict->length(), {dict});
if (ordered) {
- data.attr("class") = CharacterVector::create("ordered", "factor");
+ data.attr("class") = Rcpp::CharacterVector::create("ordered", "factor");
} else {
data.attr("class") = "factor";
}
@@ -342,11 +347,11 @@ double ms_to_seconds(int64_t ms) { return static_cast<double>(ms / 1000); }
class Converter_Date64 : public Converter {
public:
- Converter_Date64(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_Date64(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const {
- NumericVector data(no_init(n));
- data.attr("class") = CharacterVector::create("POSIXct", "POSIXt");
+ Rcpp::NumericVector data(no_init(n));
+ data.attr("class") = Rcpp::CharacterVector::create("POSIXct", "POSIXt");
return data;
}
@@ -368,10 +373,10 @@ class Converter_Promotion : public Converter {
using value_type = typename TypeTraits<Type>::ArrayType::value_type;
public:
- Converter_Promotion(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_Promotion(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const {
- return Rcpp::Vector<RTYPE, NoProtectStorage>(no_init(n));
+ return Rcpp::Vector<RTYPE, Rcpp::NoProtectStorage>(no_init(n));
}
Status Ingest_all_nulls(SEXP data, R_xlen_t start, R_xlen_t n) const {
@@ -394,12 +399,12 @@ class Converter_Promotion : public Converter {
template <typename value_type>
class Converter_Time : public Converter {
public:
- Converter_Time(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_Time(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const {
- NumericVector data(no_init(n));
- data.attr("class") = CharacterVector::create("hms", "difftime");
- data.attr("units") = CharacterVector::create("secs");
+ Rcpp::NumericVector data(no_init(n));
+ data.attr("class") = Rcpp::CharacterVector::create("hms", "difftime");
+ data.attr("units") = Rcpp::CharacterVector::create("secs");
return data;
}
@@ -435,20 +440,21 @@ class Converter_Time : public Converter {
template <typename value_type>
class Converter_Timestamp : public Converter_Time<value_type> {
public:
- Converter_Timestamp(const ArrayVector& arrays) : Converter_Time<value_type>(arrays) {}
+ explicit Converter_Timestamp(const ArrayVector& arrays)
+ : Converter_Time<value_type>(arrays) {}
SEXP Allocate(R_xlen_t n) const {
- NumericVector data(no_init(n));
- data.attr("class") = CharacterVector::create("POSIXct", "POSIXt");
+ Rcpp::NumericVector data(no_init(n));
+ data.attr("class") = Rcpp::CharacterVector::create("POSIXct", "POSIXt");
return data;
}
};
class Converter_Decimal : public Converter {
public:
- Converter_Decimal(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_Decimal(const ArrayVector& arrays) : Converter(arrays) {}
- SEXP Allocate(R_xlen_t n) const { return NumericVector_(no_init(n)); }
+ SEXP Allocate(R_xlen_t n) const { return Rcpp::NumericVector_(no_init(n)); }
Status Ingest_all_nulls(SEXP data, R_xlen_t start, R_xlen_t n) const {
return AllNull_Ingest<REALSXP>(data, start, n);
@@ -468,8 +474,7 @@ class Converter_Decimal : public Converter {
*p_data = bitmap_reader.IsSet() ? std::stod(decimals_arr.FormatValue(i).c_str())
: NA_REAL;
}
- }
- else {
+ } else {
for (size_t i = 0; i < n; i++, ++p_data) {
*p_data = std::stod(decimals_arr.FormatValue(i).c_str());
}
@@ -481,10 +486,10 @@ class Converter_Decimal : public Converter {
class Converter_Int64 : public Converter {
public:
- Converter_Int64(const ArrayVector& arrays) : Converter(arrays) {}
+ explicit Converter_Int64(const ArrayVector& arrays) : Converter(arrays) {}
SEXP Allocate(R_xlen_t n) const {
- NumericVector data(no_init(n));
+ Rcpp::NumericVector data(no_init(n));
data.attr("class") = "integer64";
return data;
}
@@ -519,97 +524,103 @@ class Converter_Int64 : public Converter {
};
std::shared_ptr<Converter> Converter::Make(const ArrayVector& arrays) {
- using namespace arrow::r;
-
switch (arrays[0]->type_id()) {
// direct support
case Type::INT8:
- return std::make_shared<Converter_SimpleArray<RAWSXP>>(arrays);
+ return std::make_shared<arrow::r::Converter_SimpleArray<RAWSXP>>(arrays);
case Type::INT32:
- return std::make_shared<Converter_SimpleArray<INTSXP>>(arrays);
+ return std::make_shared<arrow::r::Converter_SimpleArray<INTSXP>>(arrays);
case Type::DOUBLE:
- return std::make_shared<Converter_SimpleArray<REALSXP>>(arrays);
+ return std::make_shared<arrow::r::Converter_SimpleArray<REALSXP>>(arrays);
// need to handle 1-bit case
case Type::BOOL:
- return std::make_shared<Converter_Boolean>(arrays);
+ return std::make_shared<arrow::r::Converter_Boolean>(arrays);
// handle memory dense strings
case Type::STRING:
- return std::make_shared<Converter_String>(arrays);
+ return std::make_shared<arrow::r::Converter_String>(arrays);
case Type::DICTIONARY:
- return std::make_shared<Converter_Dictionary>(arrays);
+ return std::make_shared<arrow::r::Converter_Dictionary>(arrays);
case Type::DATE32:
- return std::make_shared<Converter_Date32>(arrays);
+ return std::make_shared<arrow::r::Converter_Date32>(arrays);
case Type::DATE64:
- return std::make_shared<Converter_Date64>(arrays);
+ return std::make_shared<arrow::r::Converter_Date64>(arrays);
// promotions to integer vector
case Type::UINT8:
- return std::make_shared<Converter_Promotion<INTSXP, arrow::UInt8Type>>(arrays);
+ return std::make_shared<arrow::r::Converter_Promotion<INTSXP, arrow::UInt8Type>>(
+ arrays);
case Type::INT16:
- return std::make_shared<Converter_Promotion<INTSXP, arrow::Int16Type>>(arrays);
+ return std::make_shared<arrow::r::Converter_Promotion<INTSXP, arrow::Int16Type>>(
+ arrays);
case Type::UINT16:
- return std::make_shared<Converter_Promotion<INTSXP, arrow::UInt16Type>>(arrays);
+ return std::make_shared<arrow::r::Converter_Promotion<INTSXP, arrow::UInt16Type>>(
+ arrays);
// promotions to numeric vector
case Type::UINT32:
- return std::make_shared<Converter_Promotion<REALSXP, arrow::UInt32Type>>(arrays);
+ return std::make_shared<arrow::r::Converter_Promotion<REALSXP, arrow::UInt32Type>>(
+ arrays);
case Type::HALF_FLOAT:
- return std::make_shared<Converter_Promotion<REALSXP, arrow::HalfFloatType>>(arrays);
+ return std::make_shared<
+ arrow::r::Converter_Promotion<REALSXP, arrow::HalfFloatType>>(arrays);
case Type::FLOAT:
- return std::make_shared<Converter_Promotion<REALSXP, arrow::FloatType>>(arrays);
+ return std::make_shared<arrow::r::Converter_Promotion<REALSXP, arrow::FloatType>>(
+ arrays);
// time32 ane time64
case Type::TIME32:
- return std::make_shared<Converter_Time<int32_t>>(arrays);
+ return std::make_shared<arrow::r::Converter_Time<int32_t>>(arrays);
case Type::TIME64:
- return std::make_shared<Converter_Time<int64_t>>(arrays);
+ return std::make_shared<arrow::r::Converter_Time<int64_t>>(arrays);
case Type::TIMESTAMP:
- return std::make_shared<Converter_Timestamp<int64_t>>(arrays);
+ return std::make_shared<arrow::r::Converter_Timestamp<int64_t>>(arrays);
case Type::INT64:
- return std::make_shared<Converter_Int64>(arrays);
+ return std::make_shared<arrow::r::Converter_Int64>(arrays);
case Type::DECIMAL:
- return std::make_shared<Converter_Decimal>(arrays);
+ return std::make_shared<arrow::r::Converter_Decimal>(arrays);
default:
break;
}
- stop(tfm::format("cannot handle Array of type %s", arrays[0]->type()->name()));
+ Rcpp::stop(tfm::format("cannot handle Array of type %s", arrays[0]->type()->name()));
return nullptr;
}
-List to_dataframe_serial(int64_t nr, int64_t nc, const CharacterVector& names,
- const std::vector<std::shared_ptr<Converter>>& converters) {
- List tbl(nc);
+Rcpp::List to_dataframe_serial(
+ int64_t nr, int64_t nc, const Rcpp::CharacterVector& names,
+ const std::vector<std::shared_ptr<Converter>>& converters) {
+ Rcpp::List tbl(nc);
for (int i = 0; i < nc; i++) {
SEXP column = tbl[i] = converters[i]->Allocate(nr);
STOP_IF_NOT_OK(converters[i]->IngestSerial(column));
}
tbl.attr("names") = names;
- tbl.attr("class") = CharacterVector::create("tbl_df", "tbl", "data.frame");
- tbl.attr("row.names") = IntegerVector::create(NA_INTEGER, -nr);
+ tbl.attr("class") = Rcpp::CharacterVector::create("tbl_df", "tbl", "data.frame");
+ tbl.attr("row.names") = Rcpp::IntegerVector::create(NA_INTEGER, -nr);
return tbl;
}
-List to_dataframe_parallel(int64_t nr, int64_t nc, const CharacterVector& names,
- const std::vector<std::shared_ptr<Converter>>& converters) {
- List tbl(nc);
+Rcpp::List to_dataframe_parallel(
+ int64_t nr, int64_t nc, const Rcpp::CharacterVector& names,
+ const std::vector<std::shared_ptr<Converter>>& converters) {
+ Rcpp::List tbl(nc);
// task group to ingest data in parallel
auto tg = arrow::internal::TaskGroup::MakeThreaded(arrow::internal::GetCpuThreadPool());
@@ -642,7 +653,7 @@ List to_dataframe_parallel(int64_t nr, int64_t nc, const CharacterVector& names,
STOP_IF_NOT_OK(status);
tbl.attr("names") = names;
- tbl.attr("class") = CharacterVector::create("tbl_df", "tbl", "data.frame");
+ tbl.attr("class") = Rcpp::CharacterVector::create("tbl_df", "tbl", "data.frame");
tbl.attr("row.names") = IntegerVector::create(NA_INTEGER, -nr);
return tbl;
@@ -663,12 +674,12 @@ SEXP ChunkedArray__as_vector(const std::shared_ptr<arrow::ChunkedArray>& chunked
}
// [[Rcpp::export]]
-List RecordBatch__to_dataframe(const std::shared_ptr<arrow::RecordBatch>& batch,
- bool use_threads) {
+Rcpp::List RecordBatch__to_dataframe(const std::shared_ptr<arrow::RecordBatch>& batch,
+ bool use_threads) {
int64_t nc = batch->num_columns();
int64_t nr = batch->num_rows();
- CharacterVector names(nc);
- std::vector<ArrayVector> arrays(nc);
+ Rcpp::CharacterVector names(nc);
+ std::vector<arrow::ArrayVector> arrays(nc);
std::vector<std::shared_ptr<arrow::r::Converter>> converters(nc);
for (int64_t i = 0; i < nc; i++) {
@@ -685,10 +696,11 @@ List RecordBatch__to_dataframe(const std::shared_ptr<arrow::RecordBatch>& batch,
}
// [[Rcpp::export]]
-List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table, bool use_threads) {
+Rcpp::List Table__to_dataframe(const std::shared_ptr<arrow::Table>& table,
+ bool use_threads) {
int64_t nc = table->num_columns();
int64_t nr = table->num_rows();
- CharacterVector names(nc);
+ Rcpp::CharacterVector names(nc);
std::vector<std::shared_ptr<arrow::r::Converter>> converters(nc);
for (int64_t i = 0; i < nc; i++) {
diff --git a/r/src/array_from_vector.cpp b/r/src/array_from_vector.cpp
index d02ce64..9e61e75 100644
--- a/r/src/array_from_vector.cpp
+++ b/r/src/array_from_vector.cpp
@@ -15,15 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
-
-using namespace Rcpp;
-using namespace arrow;
+#include "./arrow_types.h"
namespace arrow {
namespace r {
-std::shared_ptr<Array> MakeStringArray(StringVector_ vec) {
+std::shared_ptr<Array> MakeStringArray(Rcpp::StringVector_ vec) {
R_xlen_t n = vec.size();
std::shared_ptr<Buffer> null_buffer;
@@ -90,12 +87,13 @@ std::shared_ptr<Array> MakeStringArray(StringVector_ vec) {
}
auto data = ArrayData::Make(arrow::utf8(), n,
- {null_buffer, offset_buffer, value_buffer}, null_count, 0);
+ {null_buffer, offset_buffer, value_buffer}, null_count, 0);
return MakeArray(data);
}
template <typename Type>
-std::shared_ptr<Array> MakeFactorArrayImpl(Rcpp::IntegerVector_ factor, const std::shared_ptr<arrow::DataType>& type) {
+std::shared_ptr<Array> MakeFactorArrayImpl(Rcpp::IntegerVector_ factor,
+ const std::shared_ptr<arrow::DataType>& type) {
using value_type = typename arrow::TypeTraits<Type>::ArrayType::value_type;
auto n = factor.size();
@@ -140,7 +138,7 @@ std::shared_ptr<Array> MakeFactorArrayImpl(Rcpp::IntegerVector_ factor, const st
}
auto array_indices_data =
- ArrayData::Make(std::make_shared<Type>(), n, std::move(buffers), null_count, 0);
+ ArrayData::Make(std::make_shared<Type>(), n, std::move(buffers), null_count, 0);
auto array_indices = MakeArray(array_indices_data);
std::shared_ptr<Array> out;
@@ -148,7 +146,8 @@ std::shared_ptr<Array> MakeFactorArrayImpl(Rcpp::IntegerVector_ factor, const st
return out;
}
-std::shared_ptr<Array> MakeFactorArray(Rcpp::IntegerVector_ factor, const std::shared_ptr<arrow::DataType>& type) {
+std::shared_ptr<Array> MakeFactorArray(Rcpp::IntegerVector_ factor,
+ const std::shared_ptr<arrow::DataType>& type) {
SEXP levels = factor.attr("levels");
int n = Rf_length(levels);
if (n < 128) {
@@ -173,19 +172,15 @@ inline int64_t time_cast<double>(double value) {
return static_cast<int64_t>(value * 1000);
}
-}
-}
+} // namespace r
+} // namespace arrow
// ---------------- new api
-
-
-
-
-namespace arrow{
+namespace arrow {
using internal::checked_cast;
-namespace internal{
+namespace internal {
template <typename T, typename Target>
Status int_cast(T x, Target* out) {
@@ -209,7 +204,7 @@ Status double_cast<int64_t>(int64_t x, double* out) {
if (x < kDoubleMin || x > kDoubleMax) {
return Status::Invalid("integer value ", x, " is outside of the range exactly",
- " representable by a IEEE 754 double precision value");
+ " representable by a IEEE 754 double precision value");
}
*out = static_cast<double>(x);
return Status::OK();
@@ -224,7 +219,7 @@ Status float_cast(T x, float* out) {
int64_t x64 = static_cast<int64_t>(x);
if (x64 < kHalfFloatMin || x64 > kHalfFloatMax) {
return Status::Invalid("integer value ", x, " is outside of the range exactly",
- " representable by a IEEE 754 half precision value");
+ " representable by a IEEE 754 half precision value");
}
*out = static_cast<float>(x);
@@ -233,21 +228,22 @@ Status float_cast(T x, float* out) {
template <>
Status float_cast<double>(double x, float* out) {
- // TODO: is there some sort of floating point overflow ?
+ // TODO: is there some sort of floating point overflow ?
*out = static_cast<float>(x);
return Status::OK();
}
-}
+} // namespace internal
-namespace r{
+namespace r {
class VectorConverter;
-Status GetConverter(const std::shared_ptr<DataType>& type, std::unique_ptr<VectorConverter>* out);
+Status GetConverter(const std::shared_ptr<DataType>& type,
+ std::unique_ptr<VectorConverter>* out);
class VectorConverter {
-public:
+ public:
virtual ~VectorConverter() = default;
virtual Status Init(ArrayBuilder* builder) = 0;
@@ -261,7 +257,7 @@ public:
ArrayBuilder* builder() const { return builder_; }
-protected:
+ protected:
ArrayBuilder* builder_;
};
@@ -270,35 +266,35 @@ struct Unbox {};
// unboxer for int type
template <typename Type>
-struct Unbox<Type, enable_if_integer<Type>> {
+struct Unbox<Type, enable_if_integer<Type>> {
using BuilderType = typename TypeTraits<Type>::BuilderType;
using ArrayType = typename TypeTraits<Type>::ArrayType;
using CType = typename ArrayType::value_type;
static inline Status Ingest(BuilderType* builder, SEXP obj) {
- switch(TYPEOF(obj)) {
- case INTSXP:
- return IngestRange<int>(builder, INTEGER(obj), XLENGTH(obj), NA_INTEGER);
- case REALSXP:
- if (Rf_inherits(obj, "integer64")) {
- return IngestRange<int64_t>(builder, reinterpret_cast<int64_t*>(REAL(obj)), XLENGTH(obj), NA_INT64);
- }
- // TODO: handle aw and logical
- default:
- break;
+ switch (TYPEOF(obj)) {
+ case INTSXP:
+ return IngestRange<int>(builder, INTEGER(obj), XLENGTH(obj), NA_INTEGER);
+ case REALSXP:
+ if (Rf_inherits(obj, "integer64")) {
+ return IngestRange<int64_t>(builder, reinterpret_cast<int64_t*>(REAL(obj)),
+ XLENGTH(obj), NA_INT64);
+ }
+ // TODO: handle aw and logical
+ default:
+ break;
}
return Status::Invalid(
- tfm::format("Cannot convert R vector of type %s to integer Arrow array", type2name(obj))
- );
-
+ tfm::format("Cannot convert R vector of type %s to integer Arrow array",
+ Rcpp::type2name(obj)));
}
template <typename T>
static inline Status IngestRange(BuilderType* builder, T* p, R_xlen_t n, T na) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(*p == na) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (*p == na) {
builder->UnsafeAppendNull();
} else {
CType value;
@@ -310,19 +306,19 @@ struct Unbox<Type, enable_if_integer<Type>> {
}
};
-template<>
+template <>
struct Unbox<DoubleType> {
-
static inline Status Ingest(DoubleBuilder* builder, SEXP obj) {
- switch(TYPEOF(obj)) {
- // TODO: handle RAW
- case INTSXP:
- return IngestIntRange<int>(builder, INTEGER(obj), XLENGTH(obj), NA_INTEGER);
- case REALSXP:
- if(Rf_inherits(obj, "integer64")) {
- return IngestIntRange<int64_t>(builder, reinterpret_cast<int64_t*>(REAL(obj)), XLENGTH(obj), NA_INT64);
- }
- return IngestDoubleRange(builder, REAL(obj), XLENGTH(obj));
+ switch (TYPEOF(obj)) {
+ // TODO: handle RAW
+ case INTSXP:
+ return IngestIntRange<int>(builder, INTEGER(obj), XLENGTH(obj), NA_INTEGER);
+ case REALSXP:
+ if (Rf_inherits(obj, "integer64")) {
+ return IngestIntRange<int64_t>(builder, reinterpret_cast<int64_t*>(REAL(obj)),
+ XLENGTH(obj), NA_INT64);
+ }
+ return IngestDoubleRange(builder, REAL(obj), XLENGTH(obj));
}
return Status::Invalid("Cannot convert R object to double type");
}
@@ -330,8 +326,8 @@ struct Unbox<DoubleType> {
template <typename T>
static inline Status IngestIntRange(DoubleBuilder* builder, T* p, R_xlen_t n, T na) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(*p == NA_INTEGER) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (*p == NA_INTEGER) {
builder->UnsafeAppendNull();
} else {
double value;
@@ -344,8 +340,8 @@ struct Unbox<DoubleType> {
static inline Status IngestDoubleRange(DoubleBuilder* builder, double* p, R_xlen_t n) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(ISNA(*p)) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (ISNA(*p)) {
builder->UnsafeAppendNull();
} else {
builder->UnsafeAppend(*p);
@@ -353,22 +349,21 @@ struct Unbox<DoubleType> {
}
return Status::OK();
}
-
};
-template<>
+template <>
struct Unbox<FloatType> {
-
static inline Status Ingest(FloatBuilder* builder, SEXP obj) {
- switch(TYPEOF(obj)) {
- // TODO: handle RAW
- case INTSXP:
- return IngestIntRange<int>(builder, INTEGER(obj), XLENGTH(obj), NA_INTEGER);
- case REALSXP:
- if(Rf_inherits(obj, "integer64")) {
- return IngestIntRange<int64_t>(builder, reinterpret_cast<int64_t*>(REAL(obj)), XLENGTH(obj), NA_INT64);
- }
- return IngestDoubleRange(builder, REAL(obj), XLENGTH(obj));
+ switch (TYPEOF(obj)) {
+ // TODO: handle RAW
+ case INTSXP:
+ return IngestIntRange<int>(builder, INTEGER(obj), XLENGTH(obj), NA_INTEGER);
+ case REALSXP:
+ if (Rf_inherits(obj, "integer64")) {
+ return IngestIntRange<int64_t>(builder, reinterpret_cast<int64_t*>(REAL(obj)),
+ XLENGTH(obj), NA_INT64);
+ }
+ return IngestDoubleRange(builder, REAL(obj), XLENGTH(obj));
}
return Status::Invalid("Cannot convert R object to double type");
}
@@ -376,8 +371,8 @@ struct Unbox<FloatType> {
template <typename T>
static inline Status IngestIntRange(FloatBuilder* builder, T* p, R_xlen_t n, T na) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(*p == NA_INTEGER) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (*p == NA_INTEGER) {
builder->UnsafeAppendNull();
} else {
float value;
@@ -390,8 +385,8 @@ struct Unbox<FloatType> {
static inline Status IngestDoubleRange(FloatBuilder* builder, double* p, R_xlen_t n) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(ISNA(*p)) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (ISNA(*p)) {
builder->UnsafeAppendNull();
} else {
float value;
@@ -401,63 +396,59 @@ struct Unbox<FloatType> {
}
return Status::OK();
}
-
};
template <>
struct Unbox<BooleanType> {
-
static inline Status Ingest(BooleanBuilder* builder, SEXP obj) {
- switch(TYPEOF(obj)) {
- case LGLSXP:
- {
- R_xlen_t n = XLENGTH(obj);
- RETURN_NOT_OK(builder->Resize(n));
- int* p = LOGICAL(obj);
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(*p == NA_LOGICAL) {
- builder->UnsafeAppendNull();
- } else {
- builder->UnsafeAppend(*p == 1);
+ switch (TYPEOF(obj)) {
+ case LGLSXP: {
+ R_xlen_t n = XLENGTH(obj);
+ RETURN_NOT_OK(builder->Resize(n));
+ int* p = LOGICAL(obj);
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (*p == NA_LOGICAL) {
+ builder->UnsafeAppendNull();
+ } else {
+ builder->UnsafeAppend(*p == 1);
+ }
}
+ return Status::OK();
}
- return Status::OK();
- }
- default: break;
+ default:
+ break;
}
// TODO: include more information about the R object and the target type
return Status::Invalid("Cannot convert R object to boolean type");
}
-
};
template <>
struct Unbox<Date32Type> {
-
static inline Status Ingest(Date32Builder* builder, SEXP obj) {
- switch(TYPEOF(obj)) {
- case INTSXP:
- if (Rf_inherits(obj, "Date")) {
- return IngestIntRange(builder, INTEGER(obj), XLENGTH(obj));
- }
- break;
- case REALSXP:
- if (Rf_inherits(obj, "Date")) {
- return IngestDoubleRange(builder, REAL(obj), XLENGTH(obj));
- }
- break;
- default:
- break;
+ switch (TYPEOF(obj)) {
+ case INTSXP:
+ if (Rf_inherits(obj, "Date")) {
+ return IngestIntRange(builder, INTEGER(obj), XLENGTH(obj));
+ }
+ break;
+ case REALSXP:
+ if (Rf_inherits(obj, "Date")) {
+ return IngestDoubleRange(builder, REAL(obj), XLENGTH(obj));
+ }
+ break;
+ default:
+ break;
}
return Status::Invalid("Cannot convert R object to date32 type");
}
static inline Status IngestIntRange(Date32Builder* builder, int* p, R_xlen_t n) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(*p == NA_INTEGER) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (*p == NA_INTEGER) {
builder->UnsafeAppendNull();
} else {
builder->UnsafeAppend(*p);
@@ -468,8 +459,8 @@ struct Unbox<Date32Type> {
static inline Status IngestDoubleRange(Date32Builder* builder, double* p, R_xlen_t n) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(ISNA(*p)) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (ISNA(*p)) {
builder->UnsafeAppendNull();
} else {
builder->UnsafeAppend(static_cast<int>(*p));
@@ -477,33 +468,32 @@ struct Unbox<Date32Type> {
}
return Status::OK();
}
-
};
template <>
struct Unbox<Date64Type> {
-
constexpr static int64_t kMillisecondsPerDay = 86400000;
static inline Status Ingest(Date64Builder* builder, SEXP obj) {
- switch(TYPEOF(obj)) {
- case INTSXP:
- // number of days since epoch
- if (Rf_inherits(obj, "Date")) {
- return IngestDateInt32Range(builder, INTEGER(obj), XLENGTH(obj));
- }
- break;
+ switch (TYPEOF(obj)) {
+ case INTSXP:
+ // number of days since epoch
+ if (Rf_inherits(obj, "Date")) {
+ return IngestDateInt32Range(builder, INTEGER(obj), XLENGTH(obj));
+ }
+ break;
- case REALSXP:
- // (fractional number of days since epoch)
- if (Rf_inherits(obj, "Date")) {
- return IngestDateDoubleRange<kMillisecondsPerDay>(builder, REAL(obj), XLENGTH(obj));
- }
+ case REALSXP:
+ // (fractional number of days since epoch)
+ if (Rf_inherits(obj, "Date")) {
+ return IngestDateDoubleRange<kMillisecondsPerDay>(builder, REAL(obj),
+ XLENGTH(obj));
+ }
- // number of seconds since epoch
- if (Rf_inherits(obj, "POSIXct")) {
- return IngestDateDoubleRange<1000>(builder, REAL(obj), XLENGTH(obj));
- }
+ // number of seconds since epoch
+ if (Rf_inherits(obj, "POSIXct")) {
+ return IngestDateDoubleRange<1000>(builder, REAL(obj), XLENGTH(obj));
+ }
}
return Status::Invalid("Cannot convert R object to date64 type");
}
@@ -511,8 +501,8 @@ struct Unbox<Date64Type> {
// ingest a integer vector that represents number of days since epoch
static inline Status IngestDateInt32Range(Date64Builder* builder, int* p, R_xlen_t n) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(*p == NA_INTEGER) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (*p == NA_INTEGER) {
builder->UnsafeAppendNull();
} else {
builder->UnsafeAppend(*p * kMillisecondsPerDay);
@@ -523,11 +513,12 @@ struct Unbox<Date64Type> {
// ingest a numeric vector that represents (fractional) number of days since epoch
template <int64_t MULTIPLIER>
- static inline Status IngestDateDoubleRange(Date64Builder* builder, double* p, R_xlen_t n) {
+ static inline Status IngestDateDoubleRange(Date64Builder* builder, double* p,
+ R_xlen_t n) {
RETURN_NOT_OK(builder->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(ISNA(*p)) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (ISNA(*p)) {
builder->UnsafeAppendNull();
} else {
builder->UnsafeAppend(static_cast<int64_t>(*p * MULTIPLIER));
@@ -535,12 +526,11 @@ struct Unbox<Date64Type> {
}
return Status::OK();
}
-
};
template <typename Type, class Derived>
class TypedVectorConverter : public VectorConverter {
-public:
+ public:
using BuilderType = typename TypeTraits<Type>::BuilderType;
Status Init(ArrayBuilder* builder) override {
@@ -549,28 +539,32 @@ public:
return Status::OK();
}
- Status Ingest(SEXP obj) override {
- return Unbox<Type>::Ingest(typed_builder_, obj);
- }
+ Status Ingest(SEXP obj) override { return Unbox<Type>::Ingest(typed_builder_, obj); }
-protected:
+ protected:
BuilderType* typed_builder_;
};
template <typename Type>
-class NumericVectorConverter : public TypedVectorConverter<Type, NumericVectorConverter<Type>>{};
+class NumericVectorConverter
+ : public TypedVectorConverter<Type, NumericVectorConverter<Type>> {};
-class BooleanVectorConverter : public TypedVectorConverter<BooleanType, BooleanVectorConverter>{};
+class BooleanVectorConverter
+ : public TypedVectorConverter<BooleanType, BooleanVectorConverter> {};
class Date32Converter : public TypedVectorConverter<Date32Type, Date32Converter> {};
class Date64Converter : public TypedVectorConverter<Date64Type, Date64Converter> {};
-inline int64_t get_time_multiplier(TimeUnit::type unit){
- switch(unit){
- case TimeUnit::SECOND: return 1;
- case TimeUnit::MILLI: return 1000;
- case TimeUnit::MICRO: return 1000000;
- case TimeUnit::NANO: return 1000000000;
+inline int64_t get_time_multiplier(TimeUnit::type unit) {
+ switch (unit) {
+ case TimeUnit::SECOND:
+ return 1;
+ case TimeUnit::MILLI:
+ return 1000;
+ case TimeUnit::MICRO:
+ return 1000000;
+ case TimeUnit::NANO:
+ return 1000000000;
}
}
@@ -578,8 +572,9 @@ template <typename Type>
class TimeConverter : public VectorConverter {
using BuilderType = typename TypeTraits<Type>::BuilderType;
-public:
- TimeConverter(TimeUnit::type unit) : unit_(unit), multiplier_(get_time_multiplier(unit)){}
+ public:
+ explicit TimeConverter(TimeUnit::type unit)
+ : unit_(unit), multiplier_(get_time_multiplier(unit)) {}
Status Init(ArrayBuilder* builder) override {
builder_ = builder;
@@ -588,8 +583,7 @@ public:
}
Status Ingest(SEXP obj) override {
-
- if(valid_R_object(obj)) {
+ if (valid_R_object(obj)) {
int difftime_multiplier;
RETURN_NOT_OK(GetDifftimeMultiplier(obj, &difftime_multiplier));
return Ingest_POSIXct(REAL(obj), XLENGTH(obj), difftime_multiplier);
@@ -598,7 +592,7 @@ public:
return Status::Invalid("Cannot convert R object to timestamp type");
}
-protected:
+ protected:
TimeUnit::type unit_;
BuilderType* typed_builder_;
int64_t multiplier_;
@@ -606,17 +600,18 @@ protected:
Status Ingest_POSIXct(double* p, R_xlen_t n, int difftime_multiplier) {
RETURN_NOT_OK(typed_builder_->Resize(n));
- for (R_xlen_t i=0; i<n; i++, ++p) {
- if(ISNA(*p)) {
+ for (R_xlen_t i = 0; i < n; i++, ++p) {
+ if (ISNA(*p)) {
typed_builder_->UnsafeAppendNull();
} else {
- typed_builder_->UnsafeAppend(static_cast<int64_t>(*p * multiplier_ * difftime_multiplier));
+ typed_builder_->UnsafeAppend(
+ static_cast<int64_t>(*p * multiplier_ * difftime_multiplier));
}
}
return Status::OK();
}
- virtual bool valid_R_object(SEXP obj) = 0 ;
+ virtual bool valid_R_object(SEXP obj) = 0;
// only used for Time32 and Time64
virtual Status GetDifftimeMultiplier(SEXP obj, int* res) {
@@ -639,101 +634,99 @@ protected:
};
class TimestampConverter : public TimeConverter<TimestampType> {
-public:
- TimestampConverter(TimeUnit::type unit) : TimeConverter<TimestampType>(unit){}
+ public:
+ explicit TimestampConverter(TimeUnit::type unit) : TimeConverter<TimestampType>(unit) {}
-protected:
- virtual bool valid_R_object(SEXP obj) override {
+ protected:
+ bool valid_R_object(SEXP obj) override {
return TYPEOF(obj) == REALSXP && Rf_inherits(obj, "POSIXct");
}
- virtual Status GetDifftimeMultiplier(SEXP obj, int* res) override {
+ Status GetDifftimeMultiplier(SEXP obj, int* res) override {
*res = 1;
return Status::OK();
}
-
};
class Time32Converter : public TimeConverter<Time32Type> {
-public:
- Time32Converter(TimeUnit::type unit) : TimeConverter<Time32Type>(unit){}
+ public:
+ explicit Time32Converter(TimeUnit::type unit) : TimeConverter<Time32Type>(unit) {}
-protected:
- virtual bool valid_R_object(SEXP obj) override {
+ protected:
+ bool valid_R_object(SEXP obj) override {
return TYPEOF(obj) == REALSXP && Rf_inherits(obj, "difftime");
}
};
class Time64Converter : public TimeConverter<Time64Type> {
-public:
- Time64Converter(TimeUnit::type unit) : TimeConverter<Time64Type>(unit){}
+ public:
+ explicit Time64Converter(TimeUnit::type unit) : TimeConverter<Time64Type>(unit) {}
-protected:
- virtual bool valid_R_object(SEXP obj) override {
+ protected:
+ bool valid_R_object(SEXP obj) override {
return TYPEOF(obj) == REALSXP && Rf_inherits(obj, "difftime");
}
-
};
+#define NUMERIC_CONVERTER(TYPE_ENUM, TYPE) \
+ case Type::TYPE_ENUM: \
+ *out = \
+ std::unique_ptr<NumericVectorConverter<TYPE>>(new NumericVectorConverter<TYPE>); \
+ return Status::OK()
+
+#define SIMPLE_CONVERTER_CASE(TYPE_ENUM, TYPE) \
+ case Type::TYPE_ENUM: \
+ *out = std::unique_ptr<TYPE>(new TYPE); \
+ return Status::OK()
+
+#define TIME_CONVERTER_CASE(TYPE_ENUM, DATA_TYPE, TYPE) \
+ case Type::TYPE_ENUM: \
+ *out = \
+ std::unique_ptr<TYPE>(new TYPE(checked_cast<DATA_TYPE*>(type.get())->unit())); \
+ return Status::OK()
+
+Status GetConverter(const std::shared_ptr<DataType>& type,
+ std::unique_ptr<VectorConverter>* out) {
+ switch (type->id()) {
+ SIMPLE_CONVERTER_CASE(BOOL, BooleanVectorConverter);
+ NUMERIC_CONVERTER(INT8, Int8Type);
+ NUMERIC_CONVERTER(INT16, Int16Type);
+ NUMERIC_CONVERTER(INT32, Int32Type);
+ NUMERIC_CONVERTER(INT64, Int64Type);
+ NUMERIC_CONVERTER(UINT8, UInt8Type);
+ NUMERIC_CONVERTER(UINT16, UInt16Type);
+ NUMERIC_CONVERTER(UINT32, UInt32Type);
+ NUMERIC_CONVERTER(UINT64, UInt64Type);
+
+ // TODO: not sure how to handle half floats
+ // the python code uses npy_half
+ // NUMERIC_CONVERTER(HALF_FLOAT, HalfFloatType);
+ NUMERIC_CONVERTER(FLOAT, FloatType);
+ NUMERIC_CONVERTER(DOUBLE, DoubleType);
+
+ SIMPLE_CONVERTER_CASE(DATE32, Date32Converter);
+ SIMPLE_CONVERTER_CASE(DATE64, Date64Converter);
+
+ // TODO: probably after we merge ARROW-3628
+ // case Type::DECIMAL:
+
+ case Type::DICTIONARY:
+
+ TIME_CONVERTER_CASE(TIME32, Time32Type, Time32Converter);
+ TIME_CONVERTER_CASE(TIME64, Time64Type, Time64Converter);
+ TIME_CONVERTER_CASE(TIMESTAMP, TimestampType, TimestampConverter);
-#define NUMERIC_CONVERTER(TYPE_ENUM, TYPE) \
-case Type::TYPE_ENUM: \
- *out = std::unique_ptr<NumericVectorConverter<TYPE>>(new NumericVectorConverter<TYPE>); \
- return Status::OK()
-
-#define SIMPLE_CONVERTER_CASE(TYPE_ENUM, TYPE) \
-case Type::TYPE_ENUM: \
- *out = std::unique_ptr<TYPE>(new TYPE); \
- return Status::OK()
-
-#define TIME_CONVERTER_CASE(TYPE_ENUM, DATA_TYPE, TYPE) \
-case Type::TYPE_ENUM: \
- *out = std::unique_ptr<TYPE>(new TYPE(checked_cast<DATA_TYPE*>(type.get())->unit())); \
- return Status::OK()
-
-Status GetConverter(const std::shared_ptr<DataType>& type, std::unique_ptr<VectorConverter>* out) {
-
- switch(type->id()){
- SIMPLE_CONVERTER_CASE(BOOL, BooleanVectorConverter);
- NUMERIC_CONVERTER(INT8 , Int8Type);
- NUMERIC_CONVERTER(INT16 , Int16Type);
- NUMERIC_CONVERTER(INT32 , Int32Type);
- NUMERIC_CONVERTER(INT64 , Int64Type);
- NUMERIC_CONVERTER(UINT8 , UInt8Type);
- NUMERIC_CONVERTER(UINT16, UInt16Type);
- NUMERIC_CONVERTER(UINT32, UInt32Type);
- NUMERIC_CONVERTER(UINT64, UInt64Type);
-
- // TODO: not sure how to handle half floats
- // the python code uses npy_half
- // NUMERIC_CONVERTER(HALF_FLOAT, HalfFloatType);
- NUMERIC_CONVERTER(FLOAT, FloatType);
- NUMERIC_CONVERTER(DOUBLE, DoubleType);
-
- SIMPLE_CONVERTER_CASE(DATE32, Date32Converter);
- SIMPLE_CONVERTER_CASE(DATE64, Date64Converter);
-
- // TODO: probably after we merge ARROW-3628
- // case Type::DECIMAL:
-
- case Type::DICTIONARY:
-
- TIME_CONVERTER_CASE(TIME32, Time32Type, Time32Converter);
- TIME_CONVERTER_CASE(TIME64, Time64Type, Time64Converter);
- TIME_CONVERTER_CASE(TIMESTAMP, TimestampType, TimestampConverter);
-
- default:
- break;
+ default:
+ break;
}
return Status::NotImplemented("type not implemented");
}
-
template <typename Type>
std::shared_ptr<arrow::DataType> GetFactorTypeImpl(Rcpp::IntegerVector_ factor) {
auto dict_values = MakeStringArray(Rf_getAttrib(factor, R_LevelsSymbol));
auto dict_type =
- dictionary(std::make_shared<Type>(), dict_values, Rf_inherits(factor, "ordered"));
+ dictionary(std::make_shared<Type>(), dict_values, Rf_inherits(factor, "ordered"));
return dict_type;
}
@@ -751,39 +744,39 @@ std::shared_ptr<arrow::DataType> GetFactorType(SEXP factor) {
std::shared_ptr<arrow::DataType> InferType(SEXP x) {
switch (TYPEOF(x)) {
- case LGLSXP:
- return boolean();
- case INTSXP:
- if (Rf_isFactor(x)) {
- return GetFactorType(x);
- }
- if (Rf_inherits(x, "Date")) {
- return date32();
- }
- if (Rf_inherits(x, "POSIXct")) {
- return timestamp(TimeUnit::MICRO, "GMT");
- }
- return int32();
- case REALSXP:
- if (Rf_inherits(x, "Date")) {
- return date32();
- }
- if (Rf_inherits(x, "POSIXct")) {
- return timestamp(TimeUnit::MICRO, "GMT");
- }
- if (Rf_inherits(x, "integer64")) {
- return int64();
- }
- if (Rf_inherits(x, "difftime")) {
- return time32(TimeUnit::SECOND);
- }
- return float64();
- case RAWSXP:
- return int8();
- case STRSXP:
- return utf8();
- default:
- break;
+ case LGLSXP:
+ return boolean();
+ case INTSXP:
+ if (Rf_isFactor(x)) {
+ return GetFactorType(x);
+ }
+ if (Rf_inherits(x, "Date")) {
+ return date32();
+ }
+ if (Rf_inherits(x, "POSIXct")) {
+ return timestamp(TimeUnit::MICRO, "GMT");
+ }
+ return int32();
+ case REALSXP:
+ if (Rf_inherits(x, "Date")) {
+ return date32();
+ }
+ if (Rf_inherits(x, "POSIXct")) {
+ return timestamp(TimeUnit::MICRO, "GMT");
+ }
+ if (Rf_inherits(x, "integer64")) {
+ return int64();
+ }
+ if (Rf_inherits(x, "difftime")) {
+ return time32(TimeUnit::SECOND);
+ }
+ return float64();
+ case RAWSXP:
+ return int8();
+ case STRSXP:
+ return utf8();
+ default:
+ break;
}
Rcpp::stop("cannot infer type from data");
@@ -792,13 +785,17 @@ std::shared_ptr<arrow::DataType> InferType(SEXP x) {
// in some situations we can just use the memory of the R object in an RBuffer
// instead of going through ArrayBuilder, etc ...
bool can_reuse_memory(SEXP x, const std::shared_ptr<arrow::DataType>& type) {
- switch(type->id()) {
- case Type::INT32: return TYPEOF(x) == INTSXP && !OBJECT(x);
- case Type::DOUBLE: return TYPEOF(x) == REALSXP && !OBJECT(x);
- case Type::INT8: return TYPEOF(x) == RAWSXP && !OBJECT(x);
- case Type::INT64: return TYPEOF(x) == REALSXP && Rf_inherits(x, "integer64");
- default:
- break;
+ switch (type->id()) {
+ case Type::INT32:
+ return TYPEOF(x) == INTSXP && !OBJECT(x);
+ case Type::DOUBLE:
+ return TYPEOF(x) == REALSXP && !OBJECT(x);
+ case Type::INT8:
+ return TYPEOF(x) == RAWSXP && !OBJECT(x);
+ case Type::INT64:
+ return TYPEOF(x) == REALSXP && Rf_inherits(x, "integer64");
+ default:
+ break;
}
return false;
}
@@ -809,30 +806,30 @@ inline bool is_na(T value) {
}
template <>
-inline bool is_na<int64_t>(int64_t value){
+inline bool is_na<int64_t>(int64_t value) {
return value == NA_INT64;
}
template <>
-inline bool is_na<double>(double value){
+inline bool is_na<double>(double value) {
return ISNA(value);
}
template <>
-inline bool is_na<int>(int value){
+inline bool is_na<int>(int value) {
return value == NA_INTEGER;
}
-// this is only used on some special cases when the arrow Array can just use the memory of the R
-// object, via an RBuffer, hence be zero copy
+// this is only used on some special cases when the arrow Array can just use the memory of
+// the R object, via an RBuffer, hence be zero copy
template <int RTYPE, typename Type>
std::shared_ptr<Array> MakeSimpleArray(SEXP x) {
using value_type = typename arrow::TypeTraits<Type>::ArrayType::value_type;
- Rcpp::Vector<RTYPE, NoProtectStorage> vec(x);
+ Rcpp::Vector<RTYPE, Rcpp::NoProtectStorage> vec(x);
auto n = vec.size();
auto p_vec_start = reinterpret_cast<value_type*>(vec.begin());
auto p_vec_end = p_vec_start + n;
std::vector<std::shared_ptr<Buffer>> buffers{nullptr,
- std::make_shared<RBuffer<RTYPE>>(vec)};
+ std::make_shared<RBuffer<RTYPE>>(vec)};
int null_count = 0;
std::shared_ptr<Buffer> null_bitmap;
@@ -864,27 +861,26 @@ std::shared_ptr<Array> MakeSimpleArray(SEXP x) {
buffers[0] = std::move(null_bitmap);
}
- auto data = ArrayData::Make(
- std::make_shared<Type>(), LENGTH(x), std::move(buffers), null_count, 0 /*offset*/
- );
+ auto data = ArrayData::Make(std::make_shared<Type>(), LENGTH(x), std::move(buffers),
+ null_count, 0);
// return the right Array class
return std::make_shared<typename TypeTraits<Type>::ArrayType>(data);
}
std::shared_ptr<arrow::Array> Array__from_vector_reuse_memory(SEXP x) {
- switch(TYPEOF(x)) {
- case INTSXP:
- return MakeSimpleArray<INTSXP, Int32Type>(x);
- case REALSXP:
- if (Rf_inherits(x, "integer64")) {
- return MakeSimpleArray<REALSXP, Int64Type>(x);
- }
- return MakeSimpleArray<REALSXP, DoubleType>(x);
- case RAWSXP:
- return MakeSimpleArray<RAWSXP, Int8Type>(x);
- default:
- break;
+ switch (TYPEOF(x)) {
+ case INTSXP:
+ return MakeSimpleArray<INTSXP, Int32Type>(x);
+ case REALSXP:
+ if (Rf_inherits(x, "integer64")) {
+ return MakeSimpleArray<REALSXP, Int64Type>(x);
+ }
+ return MakeSimpleArray<REALSXP, DoubleType>(x);
+ case RAWSXP:
+ return MakeSimpleArray<RAWSXP, Int8Type>(x);
+ default:
+ break;
}
Rcpp::stop("not implemented");
@@ -893,9 +889,10 @@ std::shared_ptr<arrow::Array> Array__from_vector_reuse_memory(SEXP x) {
bool CheckCompatibleFactor(SEXP obj, const std::shared_ptr<arrow::DataType>& type) {
if (!Rf_inherits(obj, "factor")) return false;
- arrow::DictionaryType* dict_type = arrow::checked_cast<arrow::DictionaryType*>(type.get());
+ arrow::DictionaryType* dict_type =
+ arrow::checked_cast<arrow::DictionaryType*>(type.get());
auto dictionary = dict_type->dictionary();
- if(dictionary->type() != utf8()) return false;
+ if (dictionary->type() != utf8()) return false;
// then compare levels
auto typed_dict = checked_cast<arrow::StringArray*>(dictionary.get());
@@ -904,14 +901,15 @@ bool CheckCompatibleFactor(SEXP obj, const std::shared_ptr<arrow::DataType>& typ
R_xlen_t n = XLENGTH(levels);
if (n != typed_dict->length()) return false;
- for( R_xlen_t i=0; i<n; i++) {
- if(typed_dict->GetString(i) != CHAR(STRING_ELT(levels, i))) return false;
+ for (R_xlen_t i = 0; i < n; i++) {
+ if (typed_dict->GetString(i) != CHAR(STRING_ELT(levels, i))) return false;
}
return true;
}
-std::shared_ptr<arrow::Array> Array__from_vector(SEXP x, const std::shared_ptr<arrow::DataType>& type, bool type_infered){
+std::shared_ptr<arrow::Array> Array__from_vector(
+ SEXP x, const std::shared_ptr<arrow::DataType>& type, bool type_infered) {
// special case when we can just use the data from the R vector
// directly. This still needs to handle the null bitmap
if (arrow::r::can_reuse_memory(x, type)) {
@@ -930,7 +928,7 @@ std::shared_ptr<arrow::Array> Array__from_vector(SEXP x, const std::shared_ptr<a
return arrow::r::MakeFactorArray(x, type);
}
- stop("Object incompatible with dictionary type");
+ Rcpp::stop("Object incompatible with dictionary type");
}
// general conversion with converter and builder
@@ -974,7 +972,8 @@ std::shared_ptr<arrow::Array> Array__from_vector(SEXP x, SEXP s_type) {
}
// [[Rcpp::export]]
-std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(List chunks, SEXP s_type) {
+std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(Rcpp::List chunks,
+ SEXP s_type) {
std::vector<std::shared_ptr<arrow::Array>> vec;
// the type might be NULL, in which case we need to infer it from the data
@@ -985,7 +984,7 @@ std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(List chunks, SEXP s
std::shared_ptr<arrow::DataType> type;
if (type_infered) {
if (n == 0) {
- stop("type must be specified for empty list");
+ Rcpp::stop("type must be specified for empty list");
}
type = arrow::r::InferType(VECTOR_ELT(chunks, 0));
} else {
@@ -1003,9 +1002,10 @@ std::shared_ptr<arrow::ChunkedArray> ChunkedArray__from_list(List chunks, SEXP s
// because we might have infered the type from the first element of the list
//
// this only really matters for dictionary arrays
- vec.push_back(arrow::r::Array__from_vector(VECTOR_ELT(chunks, 0), type, type_infered));
+ vec.push_back(
+ arrow::r::Array__from_vector(VECTOR_ELT(chunks, 0), type, type_infered));
- for (R_xlen_t i=1; i<n; i++) {
+ for (R_xlen_t i = 1; i < n; i++) {
vec.push_back(arrow::r::Array__from_vector(VECTOR_ELT(chunks, i), type, false));
}
}
diff --git a/r/src/arraydata.cpp b/r/src/arraydata.cpp
index ef1d020..52367c5 100644
--- a/r/src/arraydata.cpp
+++ b/r/src/arraydata.cpp
@@ -15,9 +15,10 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
-using namespace Rcpp;
+using Rcpp::List;
+using Rcpp::wrap;
// [[Rcpp::export]]
std::shared_ptr<arrow::DataType> ArrayData__get_type(
diff --git a/r/src/buffer.cpp b/r/src/buffer.cpp
index b4f003b..bc52e69 100644
--- a/r/src/buffer.cpp
+++ b/r/src/buffer.cpp
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
// [[Rcpp::export]]
bool Buffer__is_mutable(const std::shared_ptr<arrow::Buffer>& buffer) {
diff --git a/r/src/chunkedarray.cpp b/r/src/chunkedarray.cpp
index 6d51267..dab1f68 100644
--- a/r/src/chunkedarray.cpp
+++ b/r/src/chunkedarray.cpp
@@ -15,10 +15,10 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
-using namespace Rcpp;
-using namespace arrow;
+using Rcpp::List;
+using Rcpp::wrap;
// [[Rcpp::export]]
int ChunkedArray__length(const std::shared_ptr<arrow::ChunkedArray>& chunked_array) {
diff --git a/r/src/column.cpp b/r/src/column.cpp
index a4e1a5d..b6eff6b 100644
--- a/r/src/column.cpp
+++ b/r/src/column.cpp
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
// [[Rcpp::export]]
int Column__length(const std::shared_ptr<arrow::Column>& column) {
diff --git a/r/src/compression.cpp b/r/src/compression.cpp
index 4c522d8..c9dadc3 100644
--- a/r/src/compression.cpp
+++ b/r/src/compression.cpp
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
// [[Rcpp::export]]
std::unique_ptr<arrow::util::Codec> util___Codec__Create(arrow::Compression::type codec) {
diff --git a/r/src/compute.cpp b/r/src/compute.cpp
index 0f55f56..42b73ce 100644
--- a/r/src/compute.cpp
+++ b/r/src/compute.cpp
@@ -15,10 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
-
-using namespace Rcpp;
-using namespace arrow;
+#include "./arrow_types.h"
// [[Rcpp::export]]
std::shared_ptr<arrow::compute::CastOptions> compute___CastOptions__initialize(
diff --git a/r/src/csv.cpp b/r/src/csv.cpp
index 0e1d09f..09580be 100644
--- a/r/src/csv.cpp
+++ b/r/src/csv.cpp
@@ -15,9 +15,10 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
-using namespace Rcpp;
+using Rcpp::CharacterVector;
+using Rcpp::List_;
// [[Rcpp::export]]
std::shared_ptr<arrow::csv::ReadOptions> csv___ReadOptions__initialize(List_ options) {
diff --git a/r/src/datatype.cpp b/r/src/datatype.cpp
index 47d0eed..e392f09 100644
--- a/r/src/datatype.cpp
+++ b/r/src/datatype.cpp
@@ -15,9 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
-using namespace Rcpp;
+using Rcpp::CharacterVector;
+using Rcpp::List;
+using Rcpp::stop;
+using Rcpp::wrap;
// [[Rcpp::export]]
bool shared_ptr_is_null(SEXP xp) {
diff --git a/r/src/feather.cpp b/r/src/feather.cpp
index 8389156..d981b4d 100644
--- a/r/src/feather.cpp
+++ b/r/src/feather.cpp
@@ -15,9 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
-
-using namespace Rcpp;
+#include "./arrow_types.h"
// ---------- TableWriter
@@ -144,7 +142,7 @@ std::shared_ptr<arrow::Table> ipc___feather___TableReader__Read(
default:
Rcpp::stop("incompatible column specification");
break;
- };
+ }
return table;
}
diff --git a/r/src/field.cpp b/r/src/field.cpp
index 1c44e8b..e864bac 100644
--- a/r/src/field.cpp
+++ b/r/src/field.cpp
@@ -15,9 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
-
-using namespace Rcpp;
+#include "./arrow_types.h"
// [[Rcpp::export]]
std::shared_ptr<arrow::Field> Field__initialize(
diff --git a/r/src/io.cpp b/r/src/io.cpp
index 2f9fe30..82c2b20 100644
--- a/r/src/io.cpp
+++ b/r/src/io.cpp
@@ -15,9 +15,9 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
-using namespace Rcpp;
+using Rcpp::RawVector_;
// ------ arrow::io::Readable
diff --git a/r/src/memorypool.cpp b/r/src/memorypool.cpp
index 76f1b57..fa0bb4a 100644
--- a/r/src/memorypool.cpp
+++ b/r/src/memorypool.cpp
@@ -15,9 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
-
-using namespace Rcpp;
+#include "./arrow_types.h"
// [[Rcpp::export]]
std::shared_ptr<arrow::MemoryPool> MemoryPool__default() {
diff --git a/r/src/message.cpp b/r/src/message.cpp
index 9cfa24b..3aec1be 100644
--- a/r/src/message.cpp
+++ b/r/src/message.cpp
@@ -15,9 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
-
-using namespace Rcpp;
+#include "./arrow_types.h"
// [[Rcpp::export]]
int64_t ipc___Message__body_length(const std::unique_ptr<arrow::ipc::Message>& message) {
diff --git a/r/src/recordbatch.cpp b/r/src/recordbatch.cpp
index 1889143..f2bec01 100644
--- a/r/src/recordbatch.cpp
+++ b/r/src/recordbatch.cpp
@@ -19,10 +19,7 @@
#include <arrow/io/memory.h>
#include <arrow/ipc/reader.h>
#include <arrow/ipc/writer.h>
-#include "arrow_types.h"
-
-using namespace Rcpp;
-using namespace arrow;
+#include "./arrow_types.h"
// [[Rcpp::export]]
int RecordBatch__num_columns(const std::shared_ptr<arrow::RecordBatch>& x) {
@@ -44,7 +41,7 @@ std::shared_ptr<arrow::Schema> RecordBatch__schema(
arrow::ArrayVector RecordBatch__columns(
const std::shared_ptr<arrow::RecordBatch>& batch) {
auto nc = batch->num_columns();
- ArrayVector res(nc);
+ arrow::ArrayVector res(nc);
for (int i = 0; i < nc; i++) {
res[i] = batch->column(i);
}
@@ -58,8 +55,8 @@ std::shared_ptr<arrow::Array> RecordBatch__column(
}
// [[Rcpp::export]]
-std::shared_ptr<arrow::RecordBatch> RecordBatch__from_dataframe(DataFrame tbl) {
- CharacterVector names = tbl.names();
+std::shared_ptr<arrow::RecordBatch> RecordBatch__from_dataframe(Rcpp::DataFrame tbl) {
+ Rcpp::CharacterVector names = tbl.names();
std::vector<std::shared_ptr<arrow::Field>> fields;
std::vector<std::shared_ptr<arrow::Array>> arrays;
@@ -96,9 +93,10 @@ std::string RecordBatch__column_name(const std::shared_ptr<arrow::RecordBatch>&
}
// [[Rcpp::export]]
-CharacterVector RecordBatch__names(const std::shared_ptr<arrow::RecordBatch>& batch) {
+Rcpp::CharacterVector RecordBatch__names(
+ const std::shared_ptr<arrow::RecordBatch>& batch) {
int n = batch->num_columns();
- CharacterVector names(n);
+ Rcpp::CharacterVector names(n);
for (int i = 0; i < n; i++) {
names[i] = batch->column_name(i);
}
@@ -118,17 +116,17 @@ std::shared_ptr<arrow::RecordBatch> RecordBatch__Slice2(
}
// [[Rcpp::export]]
-RawVector ipc___SerializeRecordBatch__Raw(
+Rcpp::RawVector ipc___SerializeRecordBatch__Raw(
const std::shared_ptr<arrow::RecordBatch>& batch) {
// how many bytes do we need ?
int64_t size;
STOP_IF_NOT_OK(arrow::ipc::GetRecordBatchSize(*batch, &size));
// allocate the result raw vector
- RawVector out(no_init(size));
+ Rcpp::RawVector out(Rcpp::no_init(size));
// serialize into the bytes of the raw vector
- auto buffer = std::make_shared<arrow::r::RBuffer<RAWSXP, RawVector>>(out);
+ auto buffer = std::make_shared<arrow::r::RBuffer<RAWSXP, Rcpp::RawVector>>(out);
arrow::io::FixedSizeBufferWriter stream(buffer);
STOP_IF_NOT_OK(
arrow::ipc::SerializeRecordBatch(*batch, arrow::default_memory_pool(), &stream));
diff --git a/r/src/recordbatchreader.cpp b/r/src/recordbatchreader.cpp
index f3e9022..d88abe6 100644
--- a/r/src/recordbatchreader.cpp
+++ b/r/src/recordbatchreader.cpp
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
// [[Rcpp::export]]
std::shared_ptr<arrow::Schema> RecordBatchReader__schema(
diff --git a/r/src/recordbatchwriter.cpp b/r/src/recordbatchwriter.cpp
index d4dd212..c4f0aca 100644
--- a/r/src/recordbatchwriter.cpp
+++ b/r/src/recordbatchwriter.cpp
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
// [[Rcpp::export]]
void ipc___RecordBatchWriter__WriteRecordBatch(
diff --git a/r/src/symbols.cpp b/r/src/symbols.cpp
index 5b4e44e..de3fcf9 100644
--- a/r/src/symbols.cpp
+++ b/r/src/symbols.cpp
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-#include "arrow_types.h"
+#include "./arrow_types.h"
namespace arrow {
namespace r {
diff --git a/r/src/table.cpp b/r/src/table.cpp
index fcf2a03..c04e1d3 100644
--- a/r/src/table.cpp
+++ b/r/src/table.cpp
@@ -18,10 +18,9 @@
#include <arrow/io/file.h>
#include <arrow/ipc/reader.h>
#include <arrow/ipc/writer.h>
-#include "arrow_types.h"
+#include "./arrow_types.h"
-using namespace Rcpp;
-using namespace arrow;
+using Rcpp::DataFrame;
// [[Rcpp::export]]
std::shared_ptr<arrow::Table> Table__from_dataframe(DataFrame tbl) {
diff --git a/r/src/threadpool.cpp b/r/src/threadpool.cpp
index 1ce0451..ef1cdc9 100644
--- a/r/src/threadpool.cpp
+++ b/r/src/threadpool.cpp
@@ -16,7 +16,7 @@
// under the License.
#include <arrow/util/parallel.h>
-#include "arrow_types.h"
+#include "./arrow_types.h"
//' Get the capacity of the global thread pool
//'