|
43 | 43 | import org.apache.calcite.sql.parser.SqlParseException; |
44 | 44 | import org.apache.commons.collections.CollectionUtils; |
45 | 45 | import org.apache.commons.lang3.StringUtils; |
| 46 | +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; |
46 | 47 | import org.apache.flink.api.common.typeinfo.TypeInformation; |
47 | 48 | import org.apache.flink.api.java.typeutils.RowTypeInfo; |
48 | 49 | import org.apache.flink.streaming.api.datastream.DataStream; |
|
52 | 53 | import org.apache.flink.table.api.java.StreamTableEnvironment; |
53 | 54 | import org.apache.flink.table.catalog.ObjectIdentifier; |
54 | 55 | import org.apache.flink.table.runtime.typeutils.BaseRowTypeInfo; |
| 56 | +import org.apache.flink.table.runtime.typeutils.BigDecimalTypeInfo; |
| 57 | +import org.apache.flink.table.types.logical.DecimalType; |
| 58 | +import org.apache.flink.table.types.logical.LegacyTypeInformationType; |
55 | 59 | import org.apache.flink.table.types.logical.LogicalType; |
56 | 60 | import org.apache.flink.table.typeutils.TimeIndicatorTypeInfo; |
57 | 61 | import org.apache.flink.types.Row; |
58 | 62 | import org.slf4j.Logger; |
59 | 63 | import org.slf4j.LoggerFactory; |
60 | 64 |
|
61 | 65 | import java.time.LocalDateTime; |
62 | | -import java.util.*; |
63 | | - |
64 | | -import static org.apache.calcite.sql.SqlKind.*; |
| 66 | +import java.util.Arrays; |
| 67 | +import java.util.LinkedList; |
| 68 | +import java.util.List; |
| 69 | +import java.util.Map; |
| 70 | +import java.util.Queue; |
| 71 | +import java.util.Set; |
| 72 | + |
| 73 | +import static org.apache.calcite.sql.SqlKind.AS; |
| 74 | +import static org.apache.calcite.sql.SqlKind.INSERT; |
| 75 | +import static org.apache.calcite.sql.SqlKind.SELECT; |
| 76 | +import static org.apache.calcite.sql.SqlKind.WITH_ITEM; |
65 | 77 |
|
66 | 78 | /** |
67 | 79 | * Reason: |
@@ -284,10 +296,7 @@ private Table getTableFromCache(Map<String, Table> localTableCache, String table |
284 | 296 | */ |
285 | 297 | private boolean checkJoinCondition(SqlNode conditionNode, String sideTableAlias, AbstractSideTableInfo sideTableInfo) { |
286 | 298 | List<String> conditionFields = getConditionFields(conditionNode, sideTableAlias, sideTableInfo); |
287 | | - if (CollectionUtils.isEqualCollection(conditionFields, convertPrimaryAlias(sideTableInfo))) { |
288 | | - return true; |
289 | | - } |
290 | | - return false; |
| 299 | + return CollectionUtils.isEqualCollection(conditionFields, convertPrimaryAlias(sideTableInfo)); |
291 | 300 | } |
292 | 301 |
|
293 | 302 | private List<String> convertPrimaryAlias(AbstractSideTableInfo sideTableInfo) { |
@@ -372,8 +381,12 @@ private void joinFun(Object pollObj, |
372 | 381 |
|
373 | 382 | int length = leftTable.getSchema().getFieldDataTypes().length; |
374 | 383 | LogicalType[] logicalTypes = new LogicalType[length]; |
375 | | - for(int i=0; i<length; i++){ |
| 384 | + for (int i = 0; i < length; i++) { |
376 | 385 | logicalTypes[i] = leftTable.getSchema().getFieldDataTypes()[i].getLogicalType(); |
| 386 | + if (logicalTypes[i] instanceof LegacyTypeInformationType && |
| 387 | + ((LegacyTypeInformationType<?>) logicalTypes[i]).getTypeInformation().getClass().equals(BigDecimalTypeInfo.class)) { |
| 388 | + logicalTypes[i] = new DecimalType(38, 18); |
| 389 | + } |
377 | 390 | } |
378 | 391 |
|
379 | 392 | BaseRowTypeInfo leftBaseTypeInfo = new BaseRowTypeInfo(logicalTypes, leftTable.getSchema().getFieldNames()); |
@@ -412,7 +425,14 @@ private void joinFun(Object pollObj, |
412 | 425 | targetTable = localTableCache.get(joinInfo.getLeftTableName()); |
413 | 426 | } |
414 | 427 |
|
415 | | - RowTypeInfo typeInfo = new RowTypeInfo(targetTable.getSchema().getFieldTypes(), targetTable.getSchema().getFieldNames()); |
| 428 | + TypeInformation[] fieldDataTypes = targetTable.getSchema().getFieldTypes(); |
| 429 | + for (int i = 0; i < fieldDataTypes.length; i++) { |
| 430 | + if (fieldDataTypes[i].getClass().equals(BigDecimalTypeInfo.class)) { |
| 431 | + fieldDataTypes[i] = BasicTypeInfo.BIG_DEC_TYPE_INFO; |
| 432 | + } |
| 433 | + } |
| 434 | + |
| 435 | + RowTypeInfo typeInfo = new RowTypeInfo(fieldDataTypes, targetTable.getSchema().getFieldNames()); |
416 | 436 |
|
417 | 437 | DataStream adaptStream = tableEnv.toRetractStream(targetTable, typeInfo) |
418 | 438 | .filter(f -> f.f0) |
@@ -484,9 +504,7 @@ private boolean checkFieldsInfo(CreateTmpTableParser.SqlParserResult result, Tab |
484 | 504 | String fieldType = filed[filed.length - 1].trim(); |
485 | 505 | Class fieldClass = ClassUtil.stringConvertClass(fieldType); |
486 | 506 | Class tableField = table.getSchema().getFieldType(i).get().getTypeClass(); |
487 | | - if (fieldClass == tableField) { |
488 | | - continue; |
489 | | - } else { |
| 507 | + if (fieldClass != tableField) { |
490 | 508 | return false; |
491 | 509 | } |
492 | 510 | } |
|
0 commit comments