|
45 | 45 | import org.apache.calcite.sql.parser.SqlParseException; |
46 | 46 | import org.apache.calcite.sql.parser.SqlParserPos; |
47 | 47 | import org.apache.commons.collections.CollectionUtils; |
| 48 | +import org.apache.flink.api.common.typeinfo.SqlTimeTypeInfo; |
48 | 49 | import org.apache.flink.api.common.typeinfo.TypeInformation; |
49 | 50 | import org.apache.flink.api.java.functions.KeySelector; |
50 | 51 | import org.apache.flink.api.java.tuple.Tuple2; |
|
55 | 56 | import org.apache.flink.streaming.api.datastream.DataStream; |
56 | 57 | import org.apache.flink.table.api.Table; |
57 | 58 | import org.apache.flink.table.api.java.StreamTableEnvironment; |
| 59 | +import org.apache.flink.table.typeutils.TimeIndicatorTypeInfo; |
58 | 60 | import org.apache.flink.types.Row; |
59 | 61 | import org.slf4j.Logger; |
60 | 62 | import org.slf4j.LoggerFactory; |
61 | 63 |
|
62 | 64 | import java.io.Serializable; |
| 65 | +import java.sql.Timestamp; |
63 | 66 | import java.util.*; |
64 | 67 | import java.util.stream.Collectors; |
65 | 68 |
|
@@ -241,6 +244,28 @@ public RowTypeInfo buildOutRowTypeInfo(List<FieldInfo> sideJoinFieldInfo, HashBa |
241 | 244 | return new RowTypeInfo(sideOutTypes, sideOutNames); |
242 | 245 | } |
243 | 246 |
|
| 247 | + /** |
| 248 | + * 对时间类型进行类型转换 |
| 249 | + * @param leftTypeInfo |
| 250 | + * @return |
| 251 | + */ |
| 252 | + private RowTypeInfo buildLeftTableOutType(RowTypeInfo leftTypeInfo) { |
| 253 | + TypeInformation[] sideOutTypes = new TypeInformation[leftTypeInfo.getFieldNames().length]; |
| 254 | + TypeInformation<?>[] fieldTypes = leftTypeInfo.getFieldTypes(); |
| 255 | + for (int i = 0; i < sideOutTypes.length; i++) { |
| 256 | + sideOutTypes[i] = convertTimeAttributeType(fieldTypes[i]); |
| 257 | + } |
| 258 | + RowTypeInfo rowTypeInfo = new RowTypeInfo(sideOutTypes, leftTypeInfo.getFieldNames()); |
| 259 | + return rowTypeInfo; |
| 260 | + } |
| 261 | + |
| 262 | + private TypeInformation convertTimeAttributeType(TypeInformation typeInformation) { |
| 263 | + if (typeInformation instanceof TimeIndicatorTypeInfo) { |
| 264 | + return TypeInformation.of(Timestamp.class); |
| 265 | + } |
| 266 | + return typeInformation; |
| 267 | + } |
| 268 | + |
244 | 269 | //需要考虑更多的情况 |
245 | 270 | private void replaceFieldName(SqlNode sqlNode, HashBasedTable<String, String, String> mappingTable, String targetTableName, String tableAlias) { |
246 | 271 | SqlKind sqlKind = sqlNode.getKind(); |
@@ -746,7 +771,8 @@ private void joinFun(Object pollObj, Map<String, Table> localTableCache, |
746 | 771 | DataStream adaptStream = tableEnv.toRetractStream(targetTable, org.apache.flink.types.Row.class) |
747 | 772 | .map((Tuple2<Boolean, Row> f0) -> { return f0.f1; }) |
748 | 773 | .returns(Row.class); |
749 | | - adaptStream.getTransformation().setOutputType(leftTypeInfo); |
| 774 | + RowTypeInfo leftTableOutType = buildLeftTableOutType(leftTypeInfo); |
| 775 | + adaptStream.getTransformation().setOutputType(leftTableOutType); |
750 | 776 |
|
751 | 777 | //join side table before keyby ===> Reducing the size of each dimension table cache of async |
752 | 778 | if(sideTableInfo.isPartitionedJoin()){ |
@@ -780,6 +806,8 @@ private void joinFun(Object pollObj, Map<String, Table> localTableCache, |
780 | 806 | } |
781 | 807 | } |
782 | 808 |
|
| 809 | + |
| 810 | + |
783 | 811 | private boolean checkFieldsInfo(CreateTmpTableParser.SqlParserResult result, Table table) { |
784 | 812 | List<String> fieldNames = new LinkedList<>(); |
785 | 813 | String fieldsInfo = result.getFieldsInfoStr(); |
|
0 commit comments