-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathDataMask.java
More file actions
142 lines (127 loc) · 4.36 KB
/
DataMask.java
File metadata and controls
142 lines (127 loc) · 4.36 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* 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.
*/
package org.apache.orc;
import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
import org.apache.orc.impl.MaskDescriptionImpl;
import java.util.ServiceLoader;
/**
* The API for masking data during column encryption for ORC.
* <p>
* They apply to an individual column (via ColumnVector) instead of a
* VectorRowBatch.
*
* @since 1.5.0
*/
public interface DataMask {
/**
* The standard DataMasks can be created using this short cut.
*
* For example, DataMask.Standard.NULLIFY.build(schema) will build a
* nullify DataMask.
*/
enum Standard {
NULLIFY("nullify"),
REDACT("redact"),
SHA256("sha256");
Standard(String name) {
this.name = name;
}
private final String name;
/**
* Get the name of the predefined data mask.
* @return the standard name
*/
public String getName() {
return name;
}
/**
* Build a DataMaskDescription given the name and a set of parameters.
* @param params the parameters
* @return a MaskDescription with the given parameters
*/
public DataMaskDescription getDescription(String... params) {
return new MaskDescriptionImpl(name, params);
}
}
/**
* Mask the given range of values
* @param original the original input data
* @param masked the masked output data
* @param start the first data element to mask
* @param length the number of data elements to mask
*/
void maskData(ColumnVector original, ColumnVector masked,
int start, int length);
/**
* An interface to provide override data masks for sub-columns.
*/
interface MaskOverrides {
/**
* Should the current mask be overridden on a sub-column?
* @param type the subfield
* @return the new mask description or null to continue using the same one
*/
DataMaskDescription hasOverride(TypeDescription type);
}
/**
* Providers can provide one or more kinds of data masks.
* Because they are discovered using a service loader, they may be added
* by third party jars.
*/
interface Provider {
/**
* Build a mask with the given parameters.
* @param description the description of the data mask
* @param schema the type of the field
* @param overrides a function to override this mask on a sub-column
* @return the new data mask or null if this name is unknown
*/
DataMask build(DataMaskDescription description,
TypeDescription schema,
MaskOverrides overrides);
}
/**
* To create a DataMask, the users should come through this API.
*
* It supports extension via additional DataMask.Provider implementations
* that are accessed through Java's ServiceLoader API.
*/
class Factory {
/**
* Build a new DataMask instance.
* @param mask the description of the data mask
* @param schema the type of the field
* @param overrides sub-columns where the mask is overridden
* @return a new DataMask
* @throws IllegalArgumentException if no such kind of data mask was found
*
* @see org.apache.orc.impl.mask.MaskProvider for the standard provider
*/
public static DataMask build(DataMaskDescription mask,
TypeDescription schema,
MaskOverrides overrides) {
for(Provider provider: ServiceLoader.load(Provider.class)) {
DataMask result = provider.build(mask, schema, overrides);
if (result != null) {
return result;
}
}
throw new IllegalArgumentException("Can't find data mask - " + mask);
}
}
}