HIVE-18192: Introduce WriteID per table rather than using global transaction ID ...
[hive.git] / hcatalog / streaming / src / test / org / apache / hive / hcatalog / streaming / mutate / ReflectiveMutatorFactory.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hive.hcatalog.streaming.mutate;
19
20 import java.io.IOException;
21
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.fs.Path;
24 import org.apache.hadoop.hive.ql.io.AcidOutputFormat;
25 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
26 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
27 import org.apache.hive.hcatalog.streaming.mutate.worker.BucketIdResolver;
28 import org.apache.hive.hcatalog.streaming.mutate.worker.BucketIdResolverImpl;
29 import org.apache.hive.hcatalog.streaming.mutate.worker.Mutator;
30 import org.apache.hive.hcatalog.streaming.mutate.worker.MutatorFactory;
31 import org.apache.hive.hcatalog.streaming.mutate.worker.MutatorImpl;
32 import org.apache.hive.hcatalog.streaming.mutate.worker.RecordInspector;
33 import org.apache.hive.hcatalog.streaming.mutate.worker.RecordInspectorImpl;
34
35 public class ReflectiveMutatorFactory implements MutatorFactory {
36
37 private final int recordIdColumn;
38 private final ObjectInspector objectInspector;
39 private final Configuration configuration;
40 private final int[] bucketColumnIndexes;
41
42 public ReflectiveMutatorFactory(Configuration configuration, Class<?> recordClass, int recordIdColumn,
43 int[] bucketColumnIndexes) {
44 this.configuration = configuration;
45 this.recordIdColumn = recordIdColumn;
46 this.bucketColumnIndexes = bucketColumnIndexes;
47 objectInspector = ObjectInspectorFactory.getReflectionObjectInspector(recordClass,
48 ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
49 }
50
51 @Override
52 public Mutator newMutator(AcidOutputFormat<?, ?> outputFormat, long writeId, Path partitionPath, int bucketId)
53 throws IOException {
54 return new MutatorImpl(configuration, recordIdColumn, objectInspector, outputFormat, writeId, partitionPath,
55 bucketId);
56 }
57
58 @Override
59 public RecordInspector newRecordInspector() {
60 return new RecordInspectorImpl(objectInspector, recordIdColumn);
61 }
62
63 @Override
64 public BucketIdResolver newBucketIdResolver(int totalBuckets) {
65 return new BucketIdResolverImpl(objectInspector, recordIdColumn, totalBuckets, bucketColumnIndexes);
66 }
67
68 }