This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathContext.java
99 lines (90 loc) · 2.99 KB
/
Context.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
/*
* 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 com.facebook.hiveio.tailer;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.mapreduce.InputSplit;
import com.facebook.hiveio.common.HiveStats;
import com.facebook.hiveio.input.HiveApiInputFormat;
import com.facebook.hiveio.schema.HiveTableSchema;
import javax.annotation.concurrent.ThreadSafe;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicLong;
/**
* Context for computation
*/
@ThreadSafe
class Context {
// CHECKSTYLE: stop VisibilityModifier
/** Hadoop InputFormat */
public final HiveApiInputFormat hiveApiInputFormat;
/** HiveConf */
public final HiveConf hiveConf;
/** schema */
public final HiveTableSchema schema;
/** stats about table */
public final HiveStats hiveStats;
/** Queue of input splits to process */
public Queue<InputSplit> splitsQueue;
/** stats tracking */
public final Stats stats;
/** Number of rows parsed */
public final AtomicLong rowsParsed;
/** Per-thread context */
public final ThreadLocal<ThreadContext> perThread = new ThreadLocal<ThreadContext>() {
@Override protected ThreadContext initialValue() {
return new ThreadContext();
}
};
// CHECKSTYLE: resume VisibilityModifier
/**
* Constructor
*
* @param hiveApiInputFormat Hadoop InputFormat
* @param hiveConf HiveConf
* @param schema table schema
* @param hiveStats table stats
* @param stats overall stats
*/
Context(HiveApiInputFormat hiveApiInputFormat, HiveConf hiveConf,
HiveTableSchema schema, HiveStats hiveStats, Stats stats) {
this.hiveApiInputFormat = hiveApiInputFormat;
this.hiveConf = hiveConf;
this.schema = schema;
this.hiveStats = hiveStats;
this.stats = stats;
this.rowsParsed = new AtomicLong();
}
/**
* Do we have more input splits to read
*
* @param limit on how many to read
* @return true if there are more input splits
*/
public boolean hasMoreSplitsToRead(long limit) {
return !splitsQueue.isEmpty() && !limitReached(limit);
}
/**
* Have we reached the limit on input splits
*
* @param limit upper bound
* @return true if limit reached
*/
public boolean limitReached(long limit) {
return rowsParsed.get() >= limit;
}
}