Skip to content

Commit f2dc607

Browse files
committed
wire up date converter
1 parent 95e2e8c commit f2dc607

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

r/src/vctr_builder.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "vctr_builder_base.h"
3232
#include "vctr_builder_blob.h"
3333
#include "vctr_builder_chr.h"
34+
#include "vctr_builder_date.h"
3435
#include "vctr_builder_dbl.h"
3536
#include "vctr_builder_int.h"
3637
#include "vctr_builder_int64.h"

r/src/vctr_builder_date.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#ifndef R_NANOARROW_VCTR_BUILDER_DATE_H_INCLUDED
19+
#define R_NANOARROW_VCTR_BUILDER_DATE_H_INCLUDED
20+
21+
#define R_NO_REMAP
22+
#include <R.h>
23+
#include <Rinternals.h>
24+
25+
#include "vctr_builder_dbl.h"
26+
27+
class DateBuilder : public DblBuilder {
28+
public:
29+
explicit DateBuilder(SEXP ptype_sexp) : DblBuilder(ptype_sexp, VECTOR_TYPE_DATE) {}
30+
31+
ArrowErrorCode Init(const ArrowSchema* schema, VctrBuilderOptions options,
32+
ArrowError* error) {
33+
NANOARROW_RETURN_NOT_OK(DblBuilder::Init(schema, options, error));
34+
switch (schema_view_.type) {
35+
case NANOARROW_TYPE_NA:
36+
case NANOARROW_TYPE_DATE32:
37+
break;
38+
default:
39+
StopCantConvert();
40+
}
41+
42+
return NANOARROW_OK;
43+
}
44+
};
45+
46+
#endif

r/src/vctr_builder_dbl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
class DblBuilder : public VctrBuilder {
3131
public:
32-
explicit DblBuilder(SEXP ptype_sexp) : VctrBuilder(VECTOR_TYPE_DBL, ptype_sexp) {}
32+
explicit DblBuilder(SEXP ptype_sexp, VectorType vector_type = VECTOR_TYPE_DBL)
33+
: VctrBuilder(vector_type, ptype_sexp) {}
3334

3435
SEXP GetPtype() override { return Rf_allocVector(REALSXP, 0); }
3536

@@ -123,8 +124,8 @@ class DblBuilder : public VctrBuilder {
123124
}
124125

125126
if (n_bad_values > 0) {
126-
warn_lossy_conversion(
127-
n_bad_values, "may have incurred loss of precision in conversion to double()");
127+
WarnLossyConvert("may have incurred loss of precision in conversion to double()",
128+
n_bad_values);
128129
}
129130

130131
return NANOARROW_OK;

r/src/vctr_builder_primitive.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
#include "vctr_builder_base.h"
2626

27-
class DateBuilder : public VctrBuilder {
28-
public:
29-
explicit DateBuilder(SEXP ptype_sexp) : VctrBuilder(VECTOR_TYPE_DATE, ptype_sexp) {}
30-
};
31-
3227
class HmsBuilder : public VctrBuilder {
3328
public:
3429
explicit HmsBuilder(SEXP ptype_sexp) : VctrBuilder(VECTOR_TYPE_HMS, ptype_sexp) {}

0 commit comments

Comments
 (0)