|
22 | 22 | import com.dtstack.flink.sql.table.TableInfo; |
23 | 23 | import com.dtstack.flink.sql.util.MathUtil; |
24 | 24 |
|
| 25 | +import java.math.BigDecimal; |
| 26 | +import java.sql.Timestamp; |
25 | 27 | import java.util.ArrayList; |
26 | 28 | import java.util.Arrays; |
27 | 29 | import java.util.List; |
@@ -55,37 +57,68 @@ public TableInfo getTableInfo(String tableName, String fieldsInfo, Map<String, O |
55 | 57 | impalaTableInfo.setSchema(MathUtil.getString(props.get(ImpalaTableInfo.SCHEMA_KEY.toLowerCase()))); |
56 | 58 |
|
57 | 59 | Integer authMech = MathUtil.getIntegerVal(props.get(ImpalaTableInfo.AUTHMECH_KEY.toLowerCase())); |
58 | | - authMech = authMech == null? 0 : authMech; |
| 60 | + authMech = authMech == null ? 0 : authMech; |
59 | 61 | impalaTableInfo.setAuthMech(authMech); |
60 | 62 | List authMechs = Arrays.asList(new Integer[]{0, 1, 2, 3}); |
61 | 63 |
|
62 | | - if (!authMechs.contains(authMech) ){ |
| 64 | + if (!authMechs.contains(authMech)) { |
63 | 65 | throw new IllegalArgumentException("The value of authMech is illegal, Please select 0, 1, 2, 3"); |
64 | 66 | } else if (authMech == 1) { |
65 | 67 | impalaTableInfo.setPrincipal(MathUtil.getString(props.get(ImpalaTableInfo.PRINCIPAL_KEY.toLowerCase()))); |
66 | 68 | impalaTableInfo.setKeyTabFilePath(MathUtil.getString(props.get(ImpalaTableInfo.KEYTABFILEPATH_KEY.toLowerCase()))); |
67 | 69 | impalaTableInfo.setKrb5FilePath(MathUtil.getString(props.get(ImpalaTableInfo.KRB5FILEPATH_KEY.toLowerCase()))); |
68 | 70 | String krbRealm = MathUtil.getString(props.get(ImpalaTableInfo.KRBREALM_KEY.toLowerCase())); |
69 | | - krbRealm = krbRealm == null? "HADOOP.COM" : krbRealm; |
| 71 | + krbRealm = krbRealm == null ? "HADOOP.COM" : krbRealm; |
70 | 72 | impalaTableInfo.setKrbRealm(krbRealm); |
71 | 73 | impalaTableInfo.setKrbHostFQDN(MathUtil.getString(props.get(impalaTableInfo.KRBHOSTFQDN_KEY.toLowerCase()))); |
72 | 74 | impalaTableInfo.setKrbServiceName(MathUtil.getString(props.get(impalaTableInfo.KRBSERVICENAME_KEY.toLowerCase()))); |
73 | | - } else if (authMech == 2 ) { |
| 75 | + } else if (authMech == 2) { |
74 | 76 | impalaTableInfo.setUserName(MathUtil.getString(props.get(ImpalaTableInfo.USER_NAME_KEY.toLowerCase()))); |
75 | 77 | } else if (authMech == 3) { |
76 | 78 | impalaTableInfo.setUserName(MathUtil.getString(props.get(ImpalaTableInfo.USER_NAME_KEY.toLowerCase()))); |
77 | 79 | impalaTableInfo.setPassword(MathUtil.getString(props.get(ImpalaTableInfo.PASSWORD_KEY.toLowerCase()))); |
78 | 80 | } |
79 | 81 |
|
80 | | - String enablePartitionStr = (String) props.get(ImpalaTableInfo.ENABLEPARITION_KEY.toLowerCase()); |
81 | | - boolean enablePartition = MathUtil.getBoolean(enablePartitionStr == null? "false":enablePartitionStr); |
| 82 | + String enablePartitionStr = (String) props.get(ImpalaTableInfo.ENABLEPARITION_KEY.toLowerCase()); |
| 83 | + boolean enablePartition = MathUtil.getBoolean(enablePartitionStr == null ? "false" : enablePartitionStr); |
82 | 84 | impalaTableInfo.setEnablePartition(enablePartition); |
83 | | - if(enablePartition){ |
| 85 | + if (enablePartition) { |
84 | 86 | String partitionFields = MathUtil.getString(props.get(ImpalaTableInfo.PARTITIONFIELDS_KEY.toLowerCase())); |
85 | 87 | impalaTableInfo.setPartitionFields(partitionFields); |
86 | 88 | } |
87 | 89 |
|
88 | 90 | impalaTableInfo.check(); |
89 | 91 | return impalaTableInfo; |
90 | 92 | } |
| 93 | + |
| 94 | + @Override |
| 95 | + public Class dbTypeConvertToJavaType(String fieldType) { |
| 96 | + switch (fieldType.toLowerCase()) { |
| 97 | + case "boolean": |
| 98 | + return Boolean.class; |
| 99 | + case "char": |
| 100 | + return Character.class; |
| 101 | + case "double": |
| 102 | + return Double.class; |
| 103 | + case "float": |
| 104 | + return Float.class; |
| 105 | + case "tinyint": |
| 106 | + return Byte.class; |
| 107 | + case "smallint": |
| 108 | + return Short.class; |
| 109 | + case "int": |
| 110 | + return Integer.class; |
| 111 | + case "bigint": |
| 112 | + return Long.class; |
| 113 | + case "decimal": |
| 114 | + return BigDecimal.class; |
| 115 | + case "string": |
| 116 | + case "varchar": |
| 117 | + return String.class; |
| 118 | + case "timestamp": |
| 119 | + return Timestamp.class; |
| 120 | + } |
| 121 | + |
| 122 | + throw new RuntimeException("不支持 " + fieldType + " 类型"); |
| 123 | + } |
91 | 124 | } |
0 commit comments