-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHiveShell.java
More file actions
175 lines (150 loc) · 5.64 KB
/
Copy pathHiveShell.java
File metadata and controls
175 lines (150 loc) · 5.64 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
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
/*
* Copyright 2013 Klarna AB
*
* Licensed 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.klarna.hiverunner;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.service.HiveServer;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.List;
/**
* Test handle to the hive server.
*
* Please refer to test class {@link com.klarna.hiverunner.HelloHiveRunner} for usage examples.
*/
public interface HiveShell {
/**
* Executes a single query.
* <p/>
* May only be called post #start()
*/
List<String> executeQuery(String script);
/**
* Executes a hive script. The script may contain multiple statements delimited by ';'
* <p/>
* May only be called post #start()
*/
void execute(String script);
/**
* Direct access to hive client.
* <p/>
* May only be called post #start()
*/
HiveServer.HiveServerHandler getClient();
/**
* Start the shell. May only be called once. The test engine will by default call this method,
* Set {@link com.klarna.hiverunner.annotations.HiveSQL#autoStart()} to false to explicitly control
* when to start from the test case.
* <p/>
* This might be useful for test methods that needs additional setup not catered for with the provided annotations.
*/
void start();
/**
* Set a HiveConf property.
* <p/>
* May only be called pre #start()
*/
void setProperty(String key, String value);
/**
* Get the current HiveConf from hive
*/
HiveConf getHiveConf();
/**
* Copy test data into hdfs
* May only be called pre #start()
* <p/>
* {@see com.klarna.hiverunner.MethodLevelResourceTest#resourceLoadingAsFileTest()}
* and {@see com.klarna.hiverunner.MethodLevelResourceTest#resourceLoadingAsStringTest()}
*/
void addResource(String targetFile, File sourceFile);
/**
* Copy test data into hdfs
* May only be called pre #start()
* <p/>
* {@see com.klarna.hiverunner.MethodLevelResourceTest#resourceLoadingAsFileTest()}
* and {@see com.klarna.hiverunner.MethodLevelResourceTest#resourceLoadingAsStringTest()}
*/
void addResource(String targetFile, Path sourceFile);
/**
* Copy test data into hdfs
* May only be called pre #start()
* <p/>
* {@see com.klarna.hiverunner.MethodLevelResourceTest#resourceLoadingAsFileTest()}
* and {@see com.klarna.hiverunner.MethodLevelResourceTest#resourceLoadingAsStringTest()}
*/
void addResource(String targetFile, String data);
/**
* Add a hive script that will be executed when the hive shell is started
* Scripts will be executed in the order they are added.
*
* Note that execution order is not guaranteed with
* fields annotated with {@link com.klarna.hiverunner.annotations.HiveSetupScript}
*/
void addSetupScript(String script);
/**
* Add hive scripts that will be executed when the hive shell is started. Scripts will be executed in given order.
*
* Note that execution order is not guaranteed with
* fields annotated with {@link com.klarna.hiverunner.annotations.HiveSetupScript}
*/
void addSetupScripts(Charset charset, File... scripts);
/**
* Add hive scripts that will be executed when the hive shell is started. Scripts will be executed in given order.
*
* Note that execution order is not guaranteed with
* fields annotated with {@link com.klarna.hiverunner.annotations.HiveSetupScript}
*/
void addSetupScripts(Charset charset, Path... scripts);
/**
* Add hive scripts that will be executed when the hive shell is started. Scripts will be executed in given order.
*
* Default charset will be used to read the given files
*
* Note that execution order is not guaranteed with
* fields annotated with {@link com.klarna.hiverunner.annotations.HiveSetupScript}
*/
void addSetupScripts(File... scripts);
/**
* Add hive scripts that will be executed when the hive shell is started. Scripts will be executed in given order.
*
* Default charset will be used to read the given files
*
* Note that execution order is not guaranteed with
* fields annotated with {@link com.klarna.hiverunner.annotations.HiveSetupScript}
*/
void addSetupScripts(Path... scripts);
/**
* Get the test case sand box base dir
*/
TemporaryFolder getBaseDir();
/**
* Resolve all substituted variables with the hive conf.
* @throws IllegalArgumentException if not all substitutes could be resolved
* @throws IllegalStateException if the HiveShell was not started yet.
*/
String expandVariableSubstitutes(String expression);
/**
* Open up a stream to write test data into hdfs.
*
* May only be called pre #start()
* No writes to the stream will be allowed post #start()
*
* @param targetFile The path to the target file relative to the hive work space
*/
OutputStream getResourceOutputStream(String targetFile);
}