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