Skip to content

Commit 774934f

Browse files
jiaoqingbopan3793
authored andcommitted
[KYUUBI #2994] Remove Hive common dependencies from Kyuubi Hive JDBC
### _Why are the changes needed?_ fix #2994 ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2995 from jiaoqingbo/kyuubi-2994. Closes #2994 c9c695b [jiaoqingbo] [KYUUBI #2994] Remove Hive common dependencies from Kyuubi Hive JDBC Authored-by: jiaoqingbo <1178404354@qq.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent c7e2b32 commit 774934f

File tree

16 files changed

+1152
-37
lines changed

16 files changed

+1152
-37
lines changed

kyuubi-hive-jdbc-shaded/pom.xml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@
6060
<artifactId>hive-service-rpc</artifactId>
6161
</dependency>
6262

63-
<dependency>
64-
<groupId>org.apache.hive</groupId>
65-
<artifactId>hive-common</artifactId>
66-
<version>${hive.version}</version>
67-
<optional>true</optional>
68-
<exclusions>
69-
<exclusion>
70-
<groupId>*</groupId>
71-
<artifactId>*</artifactId>
72-
</exclusion>
73-
</exclusions>
74-
</dependency>
75-
7663
<dependency>
7764
<groupId>commons-codec</groupId>
7865
<artifactId>commons-codec</artifactId>
@@ -160,12 +147,6 @@
160147
<include>**</include>
161148
</includes>
162149
</filter>
163-
<filter>
164-
<artifact>org.apache.hive:hive-common</artifact>
165-
<includes>
166-
<include>**</include>
167-
</includes>
168-
</filter>
169150
<filter>
170151
<artifact>*:*</artifact>
171152
<excludes>

kyuubi-hive-jdbc/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@
6464
<artifactId>hive-service-rpc</artifactId>
6565
</dependency>
6666

67-
<dependency>
68-
<groupId>org.apache.hive</groupId>
69-
<artifactId>hive-common</artifactId>
70-
<version>${hive.version}</version>
71-
<exclusions>
72-
<exclusion>
73-
<groupId>*</groupId>
74-
<artifactId>*</artifactId>
75-
</exclusion>
76-
</exclusions>
77-
</dependency>
78-
7967
<dependency>
8068
<groupId>commons-codec</groupId>
8169
<artifactId>commons-codec</artifactId>

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumn.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import java.sql.SQLException;
2525
import java.sql.Timestamp;
2626
import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
27-
import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
28-
import org.apache.hadoop.hive.common.type.TimestampTZ;
2927
import org.apache.hive.service.rpc.thrift.TTypeId;
28+
import org.apache.kyuubi.jdbc.hive.common.HiveIntervalYearMonth;
29+
import org.apache.kyuubi.jdbc.hive.common.TimestampTZ;
3030

3131
/** Column metadata. */
3232
public class JdbcColumn {

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import java.sql.*;
2626
import java.util.List;
2727
import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
28-
import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
29-
import org.apache.hadoop.hive.common.type.TimestampTZUtil;
3028
import org.apache.hive.service.rpc.thrift.TTableSchema;
3129
import org.apache.hive.service.rpc.thrift.TTypeId;
3230
import org.apache.kyuubi.jdbc.hive.adapter.SQLResultSet;
31+
import org.apache.kyuubi.jdbc.hive.common.HiveIntervalYearMonth;
32+
import org.apache.kyuubi.jdbc.hive.common.TimestampTZUtil;
3333

3434
/** Data independent base class which implements the common part of all Kyuubi result sets. */
3535
public abstract class KyuubiBaseResultSet implements SQLResultSet {

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import javax.security.sasl.Sasl;
4141
import javax.security.sasl.SaslException;
4242
import org.apache.commons.lang3.StringUtils;
43-
import org.apache.hadoop.hive.common.auth.HiveAuthUtils;
4443
import org.apache.hive.service.rpc.thrift.*;
4544
import org.apache.http.HttpRequestInterceptor;
4645
import org.apache.http.HttpResponse;
@@ -68,6 +67,7 @@
6867
import org.apache.kyuubi.jdbc.hive.cli.RowSet;
6968
import org.apache.kyuubi.jdbc.hive.cli.RowSetFactory;
7069
import org.apache.kyuubi.jdbc.hive.cli.SessionUtils;
70+
import org.apache.kyuubi.jdbc.hive.common.HiveAuthUtils;
7171
import org.apache.kyuubi.jdbc.hive.logs.KyuubiLoggable;
7272
import org.apache.thrift.TException;
7373
import org.apache.thrift.protocol.TBinaryProtocol;

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/cli/ColumnValue.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919

2020
import java.sql.Date;
2121
import java.sql.Timestamp;
22-
import org.apache.hadoop.hive.common.type.*;
22+
import org.apache.hadoop.hive.common.type.HiveDecimal;
23+
import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
2324
import org.apache.hive.service.rpc.thrift.*;
25+
import org.apache.kyuubi.jdbc.hive.common.HiveChar;
26+
import org.apache.kyuubi.jdbc.hive.common.HiveIntervalYearMonth;
27+
import org.apache.kyuubi.jdbc.hive.common.HiveVarchar;
28+
import org.apache.kyuubi.jdbc.hive.common.TimestampTZ;
2429

2530
/** Protocols before HIVE_CLI_SERVICE_PROTOCOL_V6 (used by RowBasedSet) */
2631
public class ColumnValue {
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.kyuubi.jdbc.hive.common;
19+
20+
import static java.time.temporal.ChronoField.*;
21+
22+
import java.time.Instant;
23+
import java.time.LocalDate;
24+
import java.time.LocalDateTime;
25+
import java.time.ZoneOffset;
26+
import java.time.format.*;
27+
28+
/** This is the internal type for Date. The full qualified input format of Date is "yyyy-MM-dd". */
29+
public class Date implements Comparable<Date> {
30+
31+
private static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
32+
private static final DateTimeFormatter PARSE_FORMATTER;
33+
private static final DateTimeFormatter PRINT_FORMATTER;
34+
35+
static {
36+
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
37+
builder
38+
.appendValue(YEAR, 1, 10, SignStyle.NORMAL)
39+
.appendLiteral('-')
40+
.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
41+
.appendLiteral('-')
42+
.appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NORMAL);
43+
PARSE_FORMATTER = builder.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
44+
builder = new DateTimeFormatterBuilder();
45+
builder.append(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
46+
PRINT_FORMATTER = builder.toFormatter();
47+
}
48+
49+
private LocalDate localDate;
50+
51+
private Date(LocalDate localDate) {
52+
this.localDate = localDate != null ? localDate : EPOCH;
53+
}
54+
55+
public Date() {
56+
this(EPOCH);
57+
}
58+
59+
public Date(Date d) {
60+
this(d.localDate);
61+
}
62+
63+
@Override
64+
public String toString() {
65+
return localDate.format(PRINT_FORMATTER);
66+
}
67+
68+
public int hashCode() {
69+
return localDate.hashCode();
70+
}
71+
72+
@Override
73+
public boolean equals(Object other) {
74+
if (other instanceof Date) {
75+
return compareTo((Date) other) == 0;
76+
}
77+
return false;
78+
}
79+
80+
@Override
81+
public int compareTo(Date o) {
82+
return localDate.compareTo(o.localDate);
83+
}
84+
85+
public int toEpochDay() {
86+
return (int) localDate.toEpochDay();
87+
}
88+
89+
public long toEpochSecond() {
90+
return localDate.atStartOfDay().toEpochSecond(ZoneOffset.UTC);
91+
}
92+
93+
public long toEpochMilli() {
94+
return localDate.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli();
95+
}
96+
97+
public void setYear(int year) {
98+
localDate = localDate.withYear(year);
99+
}
100+
101+
public void setMonth(int month) {
102+
localDate = localDate.withMonth(month);
103+
}
104+
105+
public void setDayOfMonth(int dayOfMonth) {
106+
localDate = localDate.withDayOfMonth(dayOfMonth);
107+
}
108+
109+
public void setTimeInDays(int epochDay) {
110+
localDate = LocalDate.ofEpochDay(epochDay);
111+
}
112+
113+
public void setTimeInMillis(long epochMilli) {
114+
localDate =
115+
LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC).toLocalDate();
116+
}
117+
118+
public static Date valueOf(String s) {
119+
s = s.trim();
120+
int idx = s.indexOf(" ");
121+
if (idx != -1) {
122+
s = s.substring(0, idx);
123+
}
124+
LocalDate localDate;
125+
try {
126+
localDate = LocalDate.parse(s, PARSE_FORMATTER);
127+
} catch (DateTimeParseException e) {
128+
throw new IllegalArgumentException("Cannot create date, parsing error");
129+
}
130+
return new Date(localDate);
131+
}
132+
133+
public static Date ofEpochDay(int epochDay) {
134+
return new Date(LocalDate.ofEpochDay(epochDay));
135+
}
136+
137+
public static Date ofEpochMilli(long epochMilli) {
138+
return new Date(
139+
LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC).toLocalDate());
140+
}
141+
142+
public static Date of(int year, int month, int dayOfMonth) {
143+
return new Date(LocalDate.of(year, month, dayOfMonth));
144+
}
145+
146+
public int getYear() {
147+
return localDate.getYear();
148+
}
149+
150+
public int getMonth() {
151+
return localDate.getMonthValue();
152+
}
153+
154+
public int getDay() {
155+
return localDate.getDayOfMonth();
156+
}
157+
158+
public int lengthOfMonth() {
159+
return localDate.lengthOfMonth();
160+
}
161+
162+
public int getDayOfWeek() {
163+
return localDate.getDayOfWeek().plus(1).getValue();
164+
}
165+
166+
/** Return a copy of this object. */
167+
public Object clone() {
168+
// LocalDateTime is immutable.
169+
return new Date(this.localDate);
170+
}
171+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.kyuubi.jdbc.hive.common;
19+
20+
/** DateUtils. Thread-safe class */
21+
public class DateUtils {
22+
public static int parseNumericValueWithRange(
23+
String fieldName, String strVal, int minValue, int maxValue) throws IllegalArgumentException {
24+
int result = 0;
25+
if (strVal != null) {
26+
result = Integer.parseInt(strVal);
27+
if (result < minValue || result > maxValue) {
28+
throw new IllegalArgumentException(
29+
String.format(
30+
"%s value %d outside range [%d, %d]", fieldName, result, minValue, maxValue));
31+
}
32+
}
33+
return result;
34+
}
35+
36+
// From java.util.Calendar
37+
private static final String[] FIELD_NAME = {
38+
"ERA",
39+
"YEAR",
40+
"MONTH",
41+
"WEEK_OF_YEAR",
42+
"WEEK_OF_MONTH",
43+
"DAY_OF_MONTH",
44+
"DAY_OF_YEAR",
45+
"DAY_OF_WEEK",
46+
"DAY_OF_WEEK_IN_MONTH",
47+
"AM_PM",
48+
"HOUR",
49+
"HOUR_OF_DAY",
50+
"MINUTE",
51+
"SECOND",
52+
"MILLISECOND",
53+
"ZONE_OFFSET",
54+
"DST_OFFSET"
55+
};
56+
57+
/**
58+
* Returns the name of the specified calendar field.
59+
*
60+
* @param field the calendar field
61+
* @return the calendar field name
62+
* @throws IndexOutOfBoundsException if <code>field</code> is negative, equal to or greater then
63+
* <code>FIELD_COUNT</code>.
64+
*/
65+
public static String getFieldName(int field) {
66+
return FIELD_NAME[field];
67+
}
68+
}

0 commit comments

Comments
 (0)