Skip to content

Commit b220954

Browse files
committed
Cut out hive-common deps in beeline module
1 parent 6043dcc commit b220954

18 files changed

+912
-467
lines changed

NOTICE-binary

-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ JUnit (4.12)
189189

190190
* License: Eclipse Public License
191191

192-
Hive Common
193-
Copyright 2022 The Apache Software Foundation
194-
195192
Apache HttpClient
196193
Copyright 1999-2020 The Apache Software Foundation
197194

kyuubi-hive-beeline/pom.xml

-12
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@
4646
<version>${project.version}</version>
4747
</dependency>
4848

49-
<dependency>
50-
<groupId>org.apache.hive</groupId>
51-
<artifactId>hive-common</artifactId>
52-
<version>${hive.version}</version>
53-
<exclusions>
54-
<exclusion>
55-
<groupId>*</groupId>
56-
<artifactId>*</artifactId>
57-
</exclusion>
58-
</exclusions>
59-
</dependency>
60-
6149
<dependency>
6250
<groupId>org.apache.hadoop</groupId>
6351
<artifactId>hadoop-client-api</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
* <p/>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p/>
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.hadoop.hive.common.cli;
19+
20+
public class EscapeCRLFHelper {
21+
22+
private static final char CARRIAGE_RETURN = '\r';
23+
private static final char LINE_FEED = '\n';
24+
25+
public EscapeCRLFHelper() {}
26+
27+
/*
28+
* Substitute for any carriage return or line feed characters in line with the escaped
29+
* 2-character sequences \r or \n.
30+
*
31+
* @param line the string for the CRLF substitution.
32+
* @return If there were no replacements, then just return line. Otherwise, a new String with
33+
* escaped CRLF.
34+
*/
35+
public static String escapeCRLF(String line) {
36+
37+
StringBuilder sb = null;
38+
int lastNonCRLFIndex = 0;
39+
int index = 0;
40+
final int length = line.length();
41+
while (index < length) {
42+
char ch = line.charAt(index);
43+
if (ch == CARRIAGE_RETURN || ch == LINE_FEED) {
44+
if (sb == null) {
45+
46+
// We defer allocation until we really need it since in the common case there is
47+
// no CRLF substitution.
48+
sb = new StringBuilder();
49+
}
50+
if (lastNonCRLFIndex < index) {
51+
52+
// Copy an intervening non-CRLF characters up to but not including current 'index'.
53+
sb.append(line.substring(lastNonCRLFIndex, index));
54+
}
55+
lastNonCRLFIndex = ++index;
56+
if (ch == CARRIAGE_RETURN) {
57+
sb.append("\\r");
58+
} else {
59+
sb.append("\\n");
60+
}
61+
} else {
62+
index++;
63+
}
64+
}
65+
if (sb == null) {
66+
67+
// No CRLF substitution -- return original line.
68+
return line;
69+
} else {
70+
if (lastNonCRLFIndex < index) {
71+
72+
// Copy an intervening non-CRLF characters up to but not including current 'index'.
73+
sb.append(line.substring(lastNonCRLFIndex, index));
74+
}
75+
return sb.toString();
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
19+
package org.apache.hadoop.hive.common.cli;
20+
21+
import java.io.IOException;
22+
import java.io.PrintStream;
23+
import org.apache.hive.common.util.StreamPrinter;
24+
25+
public class ShellCmdExecutor {
26+
private String cmd;
27+
private PrintStream out;
28+
private PrintStream err;
29+
30+
public ShellCmdExecutor(String cmd, PrintStream out, PrintStream err) {
31+
this.cmd = cmd;
32+
this.out = out;
33+
this.err = err;
34+
}
35+
36+
public int execute() throws Exception {
37+
try {
38+
Process executor = Runtime.getRuntime().exec(cmd);
39+
StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, out);
40+
StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, err);
41+
42+
outPrinter.start();
43+
errPrinter.start();
44+
45+
int ret = executor.waitFor();
46+
outPrinter.join();
47+
errPrinter.join();
48+
return ret;
49+
} catch (IOException ex) {
50+
throw new Exception("Failed to execute " + cmd, ex);
51+
}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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.hadoop.hive.common.log;
19+
20+
import static org.fusesource.jansi.Ansi.ansi;
21+
22+
import com.google.common.base.Function;
23+
import com.google.common.collect.Lists;
24+
import java.io.PrintStream;
25+
import java.io.StringWriter;
26+
import java.text.DecimalFormat;
27+
import java.util.List;
28+
import javax.annotation.Nullable;
29+
import org.apache.commons.lang3.StringUtils;
30+
import org.fusesource.jansi.Ansi;
31+
32+
/** Renders information from ProgressMonitor to the stream provided. */
33+
public class InPlaceUpdate {
34+
35+
public static final int MIN_TERMINAL_WIDTH = 94;
36+
37+
// keep this within 80 chars width. If more columns needs to be added then update min terminal
38+
// width requirement and SEPARATOR width accordingly
39+
private static final String HEADER_FORMAT = "%16s%10s %13s %5s %9s %7s %7s %6s %6s ";
40+
private static final String VERTEX_FORMAT = "%-16s%10s %13s %5s %9s %7s %7s %6s %6s ";
41+
private static final String FOOTER_FORMAT = "%-15s %-30s %-4s %-25s";
42+
43+
private static final int PROGRESS_BAR_CHARS = 30;
44+
private static final String SEPARATOR =
45+
new String(new char[MIN_TERMINAL_WIDTH]).replace("\0", "-");
46+
47+
/* Pretty print the values */
48+
private final DecimalFormat secondsFormatter = new DecimalFormat("#0.00");
49+
private int lines = 0;
50+
private PrintStream out;
51+
52+
public InPlaceUpdate(PrintStream out) {
53+
this.out = out;
54+
}
55+
56+
public InPlaceUpdate() {
57+
this(System.out);
58+
}
59+
60+
public static void reprintLine(PrintStream out, String line) {
61+
out.print(ansi().eraseLine(Ansi.Erase.ALL).a(line).a('\n').toString());
62+
out.flush();
63+
}
64+
65+
public static void rePositionCursor(PrintStream ps) {
66+
ps.print(ansi().cursorUp(0).toString());
67+
ps.flush();
68+
}
69+
70+
/**
71+
* NOTE: Use this method only if isUnixTerminal is true. Erases the current line and prints the
72+
* given line.
73+
*
74+
* @param line - line to print
75+
*/
76+
private void reprintLine(String line) {
77+
reprintLine(out, line);
78+
lines++;
79+
}
80+
81+
/**
82+
* NOTE: Use this method only if isUnixTerminal is true. Erases the current line and prints the
83+
* given line with the specified color.
84+
*
85+
* @param line - line to print
86+
* @param color - color for the line
87+
*/
88+
private void reprintLineWithColorAsBold(String line, Ansi.Color color) {
89+
out.print(
90+
ansi()
91+
.eraseLine(Ansi.Erase.ALL)
92+
.fg(color)
93+
.bold()
94+
.a(line)
95+
.a('\n')
96+
.boldOff()
97+
.reset()
98+
.toString());
99+
out.flush();
100+
lines++;
101+
}
102+
103+
/**
104+
* NOTE: Use this method only if isUnixTerminal is true. Erases the current line and prints the
105+
* given multiline. Make sure the specified line is not terminated by linebreak.
106+
*
107+
* @param line - line to print
108+
*/
109+
private void reprintMultiLine(String line) {
110+
int numLines = line.split("\r\n|\r|\n").length;
111+
out.print(ansi().eraseLine(Ansi.Erase.ALL).a(line).a('\n').toString());
112+
out.flush();
113+
lines += numLines;
114+
}
115+
116+
/**
117+
* NOTE: Use this method only if isUnixTerminal is true. Repositions the cursor back to line 0.
118+
*/
119+
private void repositionCursor() {
120+
if (lines > 0) {
121+
out.print(ansi().cursorUp(lines).toString());
122+
out.flush();
123+
lines = 0;
124+
}
125+
}
126+
127+
// [==================>>-----]
128+
private String getInPlaceProgressBar(double percent) {
129+
StringWriter bar = new StringWriter();
130+
bar.append("[");
131+
int remainingChars = PROGRESS_BAR_CHARS - 4;
132+
int completed = (int) (remainingChars * percent);
133+
int pending = remainingChars - completed;
134+
for (int i = 0; i < completed; i++) {
135+
bar.append("=");
136+
}
137+
bar.append(">>");
138+
for (int i = 0; i < pending; i++) {
139+
bar.append("-");
140+
}
141+
bar.append("]");
142+
return bar.toString();
143+
}
144+
145+
public void render(ProgressMonitor monitor) {
146+
if (monitor == null) return;
147+
// position the cursor to line 0
148+
repositionCursor();
149+
150+
// print header
151+
// -------------------------------------------------------------------------------
152+
// VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
153+
// -------------------------------------------------------------------------------
154+
reprintLine(SEPARATOR);
155+
reprintLineWithColorAsBold(
156+
String.format(HEADER_FORMAT, monitor.headers().toArray()), Ansi.Color.CYAN);
157+
reprintLine(SEPARATOR);
158+
159+
// Map 1 .......... container SUCCEEDED 7 7 0 0 0 0
160+
List<String> printReady =
161+
Lists.transform(
162+
monitor.rows(),
163+
new Function<List<String>, String>() {
164+
@Nullable
165+
@Override
166+
public String apply(@Nullable List<String> row) {
167+
return String.format(VERTEX_FORMAT, row.toArray());
168+
}
169+
});
170+
reprintMultiLine(StringUtils.join(printReady, "\n"));
171+
172+
// -------------------------------------------------------------------------------
173+
// VERTICES: 03/04 [=================>>-----] 86% ELAPSED TIME: 1.71 s
174+
// -------------------------------------------------------------------------------
175+
String progressStr = "" + (int) (monitor.progressedPercentage() * 100) + "%";
176+
float et = (float) (System.currentTimeMillis() - monitor.startTime()) / (float) 1000;
177+
String elapsedTime = "ELAPSED TIME: " + secondsFormatter.format(et) + " s";
178+
String footer =
179+
String.format(
180+
FOOTER_FORMAT,
181+
monitor.footerSummary(),
182+
getInPlaceProgressBar(monitor.progressedPercentage()),
183+
progressStr,
184+
elapsedTime);
185+
186+
reprintLine(SEPARATOR);
187+
reprintLineWithColorAsBold(footer, Ansi.Color.RED);
188+
reprintLine(SEPARATOR);
189+
}
190+
}

0 commit comments

Comments
 (0)