-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathDictionary.java
More file actions
140 lines (121 loc) · 3.75 KB
/
Dictionary.java
File metadata and controls
140 lines (121 loc) · 3.75 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
/*
* 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.impl;
import org.apache.hadoop.io.Text;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
/**
* Interface to define the dictionary used for encoding value in columns
* of specific types like string, char, varchar, etc.
* @since 1.7.0
*/
public interface Dictionary {
enum IMPL {
RBTREE,
HASH
}
int INITIAL_DICTIONARY_SIZE = 4096;
/**
* Traverse the whole dictionary and apply the action.
*/
void visit(Visitor visitor) throws IOException;
/**
* Clear the dictionary.
*/
void clear();
/**
* Given the position index, return the original string before being encoded.
* The value of the Text in the Dictionary is copied into {@code result}.
*
* @param result the holder to copy the dictionary text into
* @param position the position where the key was added
*/
void getText(Text result, int position);
/**
* Given the position index, return the original string before being encoded.
* @param position the position where the key was added
* @return the original string
*/
ByteBuffer getText(int position);
/**
* Given the position index, write the original string, before being encoded,
* to the OutputStream.
*
* @param out the output stream to which to write the data
* @param position the position where the key was originally added
* @return the number of byte written to the stream
* @throws IOException if an I/O error occurs
*/
int writeTo(OutputStream out, int position) throws IOException;
/**
* Add a new key to the dictionary.
* @param bytes the bytes of the string to add
* @param offset the offset of the string
* @param length the length of the string
* @return the position of the key in the dictionary
*/
int add(byte[] bytes, int offset, int length);
/**
* Get the number of entries in the dictionary.
* @return the number of entries
*/
int size();
/**
* Get the size of the dictionary in bytes.
* @return the size in bytes
*/
long getSizeInBytes();
/**
* The information about each node.
*/
interface VisitorContext {
/**
* Get the position where the key was originally added.
* @return the number returned by add.
*/
int getOriginalPosition();
/**
* Write the bytes for the string to the given output stream.
* @param out the stream to write to.
* @throws IOException
*/
void writeBytes(OutputStream out) throws IOException;
/**
* Get the original string.
* @return the string
*/
Text getText();
/**
* Get the number of bytes.
* @return the string's length in bytes
*/
int getLength();
}
/**
* The interface for visitors.
*/
interface Visitor {
/**
* Called once for each node of the tree in sort order.
* @param context the information about each node
* @throws IOException
*/
void visit(VisitorContext context) throws IOException;
}
}