Skip to content

Commit 8c94d08

Browse files
committed
[hotfix-#1003][hive] Remove useless code of hive.
1 parent 5d502e8 commit 8c94d08

File tree

2 files changed

+32
-436
lines changed
  • chunjun-connectors/chunjun-connector-hive/src/main/java/com/dtstack/chunjun/connector/hive/util
  • flinkx-connectors/flinkx-connector-hive/src/main/java/com/dtstack/flinkx/connector/hive/util

2 files changed

+32
-436
lines changed

chunjun-connectors/chunjun-connector-hive/src/main/java/com/dtstack/chunjun/connector/hive/util/HiveUtil.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@
5151
import java.util.Date;
5252
import java.util.HashMap;
5353
import java.util.List;
54+
import java.util.Locale;
5455
import java.util.Map;
5556
import java.util.TreeMap;
57+
import java.util.regex.Matcher;
58+
import java.util.regex.Pattern;
5659

5760
/**
5861
* Date: 2021/06/22 Company: www.dtstack.com
@@ -62,6 +65,10 @@
6265
public class HiveUtil {
6366
public static final String TABLE_COLUMN_KEY = "key";
6467
public static final String TABLE_COLUMN_TYPE = "type";
68+
public static final String DECIMAL_KEY = "DECIMAL";
69+
public static final String DECIMAL_FORMAT = "DECIMAL(%s, %s)";
70+
public static final String DECIMAL_PATTERN_STR = "DECIMAL(\\((\\s*\\d+\\s*),(\\s*\\d+\\s*)\\))";
71+
public static final Pattern DECIMAL_PATTERN = Pattern.compile(DECIMAL_PATTERN_STR);
6572
public static final String PARTITION_TEMPLATE = "%s=%s";
6673
private static final Logger logger = LoggerFactory.getLogger(HiveUtil.class);
6774
private static final String CREATE_PARTITION_TEMPLATE =
@@ -168,8 +175,7 @@ private static void fillTableInfo(Connection connection, TableInfo tableInfo) {
168175
metadataParser.fillTableInfo(tableInfo, result);
169176
} catch (Exception e) {
170177
if (e.getMessage().contains(NO_SUCH_TABLE_EXCEPTION)) {
171-
throw new ChunJunRuntimeException(
172-
String.format("表%s不存在", tableInfo.getTablePath()));
178+
throw new ChunJunRuntimeException(String.format("表%s不存在", tableInfo.getTablePath()));
173179
} else {
174180
throw e;
175181
}
@@ -360,11 +366,34 @@ private static String convertType(String type) {
360366
type = "TIMESTAMP";
361367
break;
362368
default:
363-
type = "STRING";
369+
type = convertDefaultType(type);
364370
}
365371
return type;
366372
}
367373

374+
/**
375+
* 转化decimal类型,带上精度
376+
*
377+
* @param type type 类型
378+
* @return 有精度的decimal
379+
*/
380+
private static String convertDefaultType(String type) {
381+
String toUpperCase = type.toUpperCase(Locale.ROOT);
382+
if (toUpperCase.contains(DECIMAL_KEY)) {
383+
Matcher matcher = DECIMAL_PATTERN.matcher(toUpperCase);
384+
if (matcher.matches()) {
385+
final int precision = Integer.parseInt(matcher.group(2).trim());
386+
final int scale = Integer.parseInt(matcher.group(3).trim());
387+
return String.format(DECIMAL_FORMAT, precision, scale);
388+
} else {
389+
throw new IllegalArgumentException(
390+
"Get wrong type of decimal, the type is: " + type);
391+
}
392+
}
393+
394+
return "STRING";
395+
}
396+
368397
public static AbstractBaseColumn parseDataFromMap(Object data) {
369398
if (data == null) {
370399
return new NullColumn();

0 commit comments

Comments
 (0)