-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DeSerializer.java
245 lines (209 loc) · 9.4 KB
/
DeSerializer.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* 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.hadoop.hive.metastore.messaging.json.gzip;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.hive.metastore.messaging.AbortTxnMessage;
import org.apache.hadoop.hive.metastore.messaging.AcidWriteMessage;
import org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage;
import org.apache.hadoop.hive.metastore.messaging.AddDefaultConstraintMessage;
import org.apache.hadoop.hive.metastore.messaging.AddForeignKeyMessage;
import org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage;
import org.apache.hadoop.hive.metastore.messaging.AddPartitionMessage;
import org.apache.hadoop.hive.metastore.messaging.AddPrimaryKeyMessage;
import org.apache.hadoop.hive.metastore.messaging.AddUniqueConstraintMessage;
import org.apache.hadoop.hive.metastore.messaging.AllocWriteIdMessage;
import org.apache.hadoop.hive.metastore.messaging.AlterDatabaseMessage;
import org.apache.hadoop.hive.metastore.messaging.AlterPartitionMessage;
import org.apache.hadoop.hive.metastore.messaging.AlterTableMessage;
import org.apache.hadoop.hive.metastore.messaging.CommitTxnMessage;
import org.apache.hadoop.hive.metastore.messaging.CommitCompactionMessage;
import org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage;
import org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage;
import org.apache.hadoop.hive.metastore.messaging.CreateTableMessage;
import org.apache.hadoop.hive.metastore.messaging.DropConstraintMessage;
import org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage;
import org.apache.hadoop.hive.metastore.messaging.DropFunctionMessage;
import org.apache.hadoop.hive.metastore.messaging.DropPartitionMessage;
import org.apache.hadoop.hive.metastore.messaging.DropTableMessage;
import org.apache.hadoop.hive.metastore.messaging.InsertMessage;
import org.apache.hadoop.hive.metastore.messaging.OpenTxnMessage;
import org.apache.hadoop.hive.metastore.messaging.UpdateTableColumnStatMessage;
import org.apache.hadoop.hive.metastore.messaging.UpdatePartitionColumnStatMessage;
import org.apache.hadoop.hive.metastore.messaging.DeleteTableColumnStatMessage;
import org.apache.hadoop.hive.metastore.messaging.DeletePartitionColumnStatMessage;
import org.apache.hadoop.hive.metastore.messaging.json.JSONMessageDeserializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.zip.GZIPInputStream;
public class DeSerializer extends JSONMessageDeserializer {
private static final Logger LOG = LoggerFactory.getLogger(Serializer.class.getName());
private static String deCompress(String messageBody) {
byte[] decodedBytes = Base64.getDecoder().decode(messageBody.getBytes(StandardCharsets.UTF_8));
try (
ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes);
GZIPInputStream is = new GZIPInputStream(in)
) {
byte[] bytes = IOUtils.toByteArray(is);
return new String(bytes, StandardCharsets.UTF_8);
} catch (IOException e) {
LOG.error("cannot decode the stream", e);
LOG.debug("base64 encoded String", messageBody);
throw new RuntimeException("cannot decode the stream ", e);
}
}
/**
* this is mainly as a utility to allow debugging of messages for developers by providing the
* message in a file and getting an actual message out.
* This class on a deployed hive instance will also be bundled in hive-exec jar.
*
*/
public static void main(String[] args) throws IOException {
if(args.length != 1) {
System.out.println("Usage:");
System.out.println("java -cp [classpath] "+DeSerializer.class.getCanonicalName() +" [file_location]");
}
System.out.print(
deCompress(FileUtils.readFileToString(new File(args[0]), StandardCharsets.UTF_8)));
}
@Override
public CreateDatabaseMessage getCreateDatabaseMessage(String messageBody) {
return super.getCreateDatabaseMessage(deCompress(messageBody));
}
@Override
public AlterDatabaseMessage getAlterDatabaseMessage(String messageBody) {
return super.getAlterDatabaseMessage(deCompress(messageBody));
}
@Override
public DropDatabaseMessage getDropDatabaseMessage(String messageBody) {
return super.getDropDatabaseMessage(deCompress(messageBody));
}
@Override
public CreateTableMessage getCreateTableMessage(String messageBody) {
return super.getCreateTableMessage(deCompress(messageBody));
}
@Override
public AlterTableMessage getAlterTableMessage(String messageBody) {
return super.getAlterTableMessage(deCompress(messageBody));
}
@Override
public DropTableMessage getDropTableMessage(String messageBody) {
return super.getDropTableMessage(deCompress(messageBody));
}
@Override
public AddPartitionMessage getAddPartitionMessage(String messageBody) {
return super.getAddPartitionMessage(deCompress(messageBody));
}
@Override
public AlterPartitionMessage getAlterPartitionMessage(String messageBody) {
return super.getAlterPartitionMessage(deCompress(messageBody));
}
@Override
public DropPartitionMessage getDropPartitionMessage(String messageBody) {
return super.getDropPartitionMessage(deCompress(messageBody));
}
@Override
public CreateFunctionMessage getCreateFunctionMessage(String messageBody) {
return super.getCreateFunctionMessage(deCompress(messageBody));
}
@Override
public DropFunctionMessage getDropFunctionMessage(String messageBody) {
return super.getDropFunctionMessage(deCompress(messageBody));
}
@Override
public InsertMessage getInsertMessage(String messageBody) {
return super.getInsertMessage(deCompress(messageBody));
}
@Override
public AddPrimaryKeyMessage getAddPrimaryKeyMessage(String messageBody) {
return super.getAddPrimaryKeyMessage(deCompress(messageBody));
}
@Override
public AddForeignKeyMessage getAddForeignKeyMessage(String messageBody) {
return super.getAddForeignKeyMessage(deCompress(messageBody));
}
@Override
public AddUniqueConstraintMessage getAddUniqueConstraintMessage(String messageBody) {
return super.getAddUniqueConstraintMessage(deCompress(messageBody));
}
@Override
public AddDefaultConstraintMessage getAddDefaultConstraintMessage(String messageBody) {
return super.getAddDefaultConstraintMessage(deCompress(messageBody));
}
@Override
public AddNotNullConstraintMessage getAddNotNullConstraintMessage(String messageBody) {
return super.getAddNotNullConstraintMessage(deCompress(messageBody));
}
@Override
public AddCheckConstraintMessage getAddCheckConstraintMessage(String messageBody) {
return super.getAddCheckConstraintMessage(deCompress(messageBody));
}
@Override
public DropConstraintMessage getDropConstraintMessage(String messageBody) {
return super.getDropConstraintMessage(deCompress(messageBody));
}
@Override
public OpenTxnMessage getOpenTxnMessage(String messageBody) {
return super.getOpenTxnMessage(deCompress(messageBody));
}
@Override
public CommitTxnMessage getCommitTxnMessage(String messageBody) {
return super.getCommitTxnMessage(deCompress(messageBody));
}
@Override
public AbortTxnMessage getAbortTxnMessage(String messageBody) {
return super.getAbortTxnMessage(deCompress(messageBody));
}
@Override
public AllocWriteIdMessage getAllocWriteIdMessage(String messageBody) {
return super.getAllocWriteIdMessage(deCompress(messageBody));
}
@Override
public CommitCompactionMessage getCommitCompactionMessage(String messageBody) {
return super.getCommitCompactionMessage(deCompress(messageBody));
}
@Override
public AcidWriteMessage getAcidWriteMessage(String messageBody) {
return super.getAcidWriteMessage(deCompress(messageBody));
}
@Override
public UpdateTableColumnStatMessage getUpdateTableColumnStatMessage(String messageBody) {
return super.getUpdateTableColumnStatMessage(deCompress(messageBody));
}
@Override
public UpdatePartitionColumnStatMessage getUpdatePartitionColumnStatMessage(String messageBody) {
return super.getUpdatePartitionColumnStatMessage(deCompress(messageBody));
}
@Override
public DeleteTableColumnStatMessage getDeleteTableColumnStatMessage(String messageBody) {
return super.getDeleteTableColumnStatMessage(deCompress(messageBody));
}
@Override
public DeletePartitionColumnStatMessage getDeletePartitionColumnStatMessage(String messageBody) {
return super.getDeletePartitionColumnStatMessage(deCompress(messageBody));
}
public String deSerializeGenericString(String messageBody) {
return deCompress(messageBody);
}
}