Skip to content

Commit b44feef

Browse files
committed
wire up posixct
1 parent 05f7234 commit b44feef

File tree

4 files changed

+92
-7
lines changed

4 files changed

+92
-7
lines changed

Diff for: r/src/vctr_builder.cc

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "vctr_builder_int64.h"
4040
#include "vctr_builder_lgl.h"
4141
#include "vctr_builder_list_of.h"
42+
#include "vctr_builder_posixct.h"
4243
#include "vctr_builder_primitive.h"
4344
#include "vctr_builder_rcrd.h"
4445
#include "vctr_builder_unspecified.h"

Diff for: r/src/vctr_builder_difftime.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class DifftimeBuilder : public DblBuilder {
8080
return NANOARROW_OK;
8181
}
8282

83-
virtual ArrowErrorCode PushNext(const ArrowArray* array, ArrowError* error) override {
83+
ArrowErrorCode PushNext(const ArrowArray* array, ArrowError* error) override {
8484
R_xlen_t value_size0 = value_size_;
8585
NANOARROW_RETURN_NOT_OK(DblBuilder::PushNext(array, error));
8686

Diff for: r/src/vctr_builder_posixct.h

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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_POSIXCT_H_INCLUDED
19+
#define R_NANOARROW_VCTR_BUILDER_POSIXCT_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 PosixctBuilder : public DblBuilder {
28+
public:
29+
explicit PosixctBuilder(SEXP ptype_sexp)
30+
: DblBuilder(ptype_sexp, VECTOR_TYPE_POSIXCT), scale_(0) {}
31+
32+
ArrowErrorCode Init(const ArrowSchema* schema, VctrBuilderOptions options,
33+
ArrowError* error) override {
34+
NANOARROW_RETURN_NOT_OK(DblBuilder::Init(schema, options, error));
35+
36+
ArrowTimeUnit time_unit = NANOARROW_TIME_UNIT_SECOND;
37+
switch (schema_view_.type) {
38+
case NANOARROW_TYPE_NA:
39+
break;
40+
case NANOARROW_TYPE_DATE64:
41+
time_unit = NANOARROW_TIME_UNIT_MILLI;
42+
break;
43+
case NANOARROW_TYPE_TIMESTAMP:
44+
time_unit = schema_view_.time_unit;
45+
break;
46+
default:
47+
StopCantConvert();
48+
}
49+
50+
scale_ = 1;
51+
52+
switch (time_unit) {
53+
case NANOARROW_TIME_UNIT_SECOND:
54+
scale_ *= 1;
55+
break;
56+
case NANOARROW_TIME_UNIT_MILLI:
57+
scale_ *= 1e-3;
58+
break;
59+
case NANOARROW_TIME_UNIT_MICRO:
60+
scale_ *= 1e-6;
61+
break;
62+
case NANOARROW_TIME_UNIT_NANO:
63+
scale_ *= 1e-9;
64+
break;
65+
default:
66+
return EINVAL;
67+
}
68+
69+
return NANOARROW_OK;
70+
}
71+
72+
ArrowErrorCode PushNext(const ArrowArray* array, ArrowError* error) override {
73+
R_xlen_t value_size0 = value_size_;
74+
NANOARROW_RETURN_NOT_OK(DblBuilder::PushNext(array, error));
75+
76+
if (scale_ != 1) {
77+
double* result = REAL(value_);
78+
for (int64_t i = 0; i < array_view_.length; i++) {
79+
result[value_size0 + i] = result[value_size0 + i] * scale_;
80+
}
81+
}
82+
83+
return NANOARROW_OK;
84+
}
85+
86+
private:
87+
double scale_;
88+
};
89+
90+
#endif

Diff for: r/src/vctr_builder_primitive.h

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424

2525
#include "vctr_builder_base.h"
2626

27-
class PosixctBuilder : public VctrBuilder {
28-
public:
29-
explicit PosixctBuilder(SEXP ptype_sexp)
30-
: VctrBuilder(VECTOR_TYPE_POSIXCT, ptype_sexp) {}
31-
};
32-
3327
class OtherBuilder : public VctrBuilder {
3428
public:
3529
explicit OtherBuilder(SEXP ptype_sexp) : VctrBuilder(VECTOR_TYPE_OTHER, ptype_sexp) {}

0 commit comments

Comments
 (0)