-
Notifications
You must be signed in to change notification settings - Fork 65
/
CastStrings.java
125 lines (112 loc) · 4.76 KB
/
CastStrings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
*
* Licensed 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.
*/
package com.nvidia.spark.rapids.jni;
import ai.rapids.cudf.*;
/** Utility class for casting between string columns and native type columns */
public class CastStrings {
static {
NativeDepsLoader.loadNativeDeps();
}
/**
* Convert a string column to an integer column of a specified type stripping away leading and
* trailing spaces.
*
* @param cv the column data to process.
* @param ansiMode true if invalid data are errors, false if they should be nulls.
* @param type the type of the return column.
* @return the converted column.
*/
public static ColumnVector toInteger(ColumnView cv, boolean ansiMode, DType type) {
return toInteger(cv, ansiMode, true, type);
}
/**
* Convert a string column to an integer column of a specified type.
*
* @param cv the column data to process.
* @param ansiMode true if invalid data are errors, false if they should be nulls.
* @param strip true if leading and trailing spaces should be ignored when parsing.
* @param type the type of the return column.
* @return the converted column.
*/
public static ColumnVector toInteger(ColumnView cv, boolean ansiMode, boolean strip, DType type) {
return new ColumnVector(toInteger(cv.getNativeView(), ansiMode, strip,
type.getTypeId().getNativeId()));
}
/**
* Convert a string column to an integer column of a specified type stripping away leading and
* trailing whitespace.
*
* @param cv the column data to process.
* @param ansiMode true if invalid data are errors, false if they should be nulls.
* @param precision the output precision.
* @param scale the output scale.
* @return the converted column.
*/
public static ColumnVector toDecimal(ColumnView cv, boolean ansiMode, int precision, int scale) {
return toDecimal(cv, ansiMode, true, precision, scale);
}
/**
* Convert a string column to an integer column of a specified type.
*
* @param cv the column data to process.
* @param ansiMode true if invalid data are errors, false if they should be nulls.
* @param strip true if leading and trailing white space should be stripped.
* @param precision the output precision.
* @param scale the output scale.
* @return the converted column.
*/
public static ColumnVector toDecimal(ColumnView cv, boolean ansiMode, boolean strip,
int precision, int scale) {
return new ColumnVector(toDecimal(cv.getNativeView(), ansiMode, strip, precision, scale));
}
/**
* Convert a decimal column to a string column.
*
* @param cv the column data to process
* @return the converted column
*/
public static ColumnVector fromDecimal(ColumnView cv) {
return new ColumnVector(fromDecimal(cv.getNativeView()));
}
/**
* Convert a string column to a given floating-point type column.
*
* @param cv the column data to process.
* @param ansiMode true if invalid data are errors, false if they should be nulls.
* @param type the type of the return column.
* @return the converted column.
*/
public static ColumnVector toFloat(ColumnView cv, boolean ansiMode, DType type) {
return new ColumnVector(toFloat(cv.getNativeView(), ansiMode, type.getTypeId().getNativeId()));
}
public static ColumnVector toIntegersWithBase(ColumnView cv, int base,
boolean ansiEnabled, DType type) {
return new ColumnVector(toIntegersWithBase(cv.getNativeView(), base, ansiEnabled,
type.getTypeId().getNativeId()));
}
public static ColumnVector fromIntegersWithBase(ColumnView cv, int base) {
return new ColumnVector(fromIntegersWithBase(cv.getNativeView(), base));
}
private static native long toInteger(long nativeColumnView, boolean ansi_enabled, boolean strip,
int dtype);
private static native long toDecimal(long nativeColumnView, boolean ansi_enabled, boolean strip,
int precision, int scale);
private static native long toFloat(long nativeColumnView, boolean ansi_enabled, int dtype);
private static native long fromDecimal(long nativeColumnView);
private static native long toIntegersWithBase(long nativeColumnView, int base,
boolean ansiEnabled, int dtype);
private static native long fromIntegersWithBase(long nativeColumnView, int base);
}