]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/r/R/field.R
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / r / R / field.R
CommitLineData
1d09f67e
TL
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#' @include arrow-package.R
19#' @title Field class
20#' @usage NULL
21#' @format NULL
22#' @docType class
23#' @description `field()` lets you create an `arrow::Field` that maps a
24#' [DataType][data-type] to a column name. Fields are contained in
25#' [Schemas][Schema].
26#' @section Methods:
27#'
28#' - `f$ToString()`: convert to a string
29#' - `f$Equals(other)`: test for equality. More naturally called as `f == other`
30#'
31#' @rdname Field
32#' @name Field
33#' @export
34Field <- R6Class("Field",
35 inherit = ArrowObject,
36 public = list(
37 ToString = function() {
38 prettier_dictionary_type(Field__ToString(self))
39 },
40 Equals = function(other, ...) {
41 inherits(other, "Field") && Field__Equals(self, other)
42 },
43 export_to_c = function(ptr) ExportField(self, ptr)
44 ),
45 active = list(
46 name = function() {
47 Field__name(self)
48 },
49 nullable = function() {
50 Field__nullable(self)
51 },
52 type = function() {
53 Field__type(self)
54 }
55 )
56)
57Field$create <- function(name, type, metadata, nullable = TRUE) {
58 assert_that(inherits(name, "character"), length(name) == 1L)
59 type <- as_type(type, name)
60 assert_that(missing(metadata), msg = "metadata= is currently ignored")
61 Field__initialize(enc2utf8(name), type, nullable)
62}
63#' @include arrowExports.R
64Field$import_from_c <- ImportField
65
66#' @param name field name
67#' @param type logical type, instance of [DataType]
68#' @param metadata currently ignored
69#' @param nullable TRUE if field is nullable
70#'
71#' @examplesIf arrow_available()
72#' field("x", int32())
73#' @rdname Field
74#' @export
75field <- Field$create
76
77.fields <- function(.list, nullable = TRUE) {
78 if (length(.list)) {
79 assert_that(!is.null(nms <- names(.list)))
80 map2(nms, .list, field)
81 } else {
82 list()
83 }
84}