kwonder0926 commented on code in PR #573: URL: https://github.com/apache/doris-flink-connector/pull/573#discussion_r1990714808
########## flink-doris-connector/src/main/java/org/apache/doris/flink/tools/cdc/mongodb/serializer/MongoJsonDebeziumSchemaChange.java: ########## @@ -118,6 +159,45 @@ public boolean schemaChange(JsonNode recordRoot) { } } + public static <K, V> V getRandomValue(Map<K, V> map) { + Collection<V> values = map.values(); + return values.stream().findAny().orElse(null); + } + + private void tryCreateTableIfAbsent( + DorisSystem dorisSystem, String targetDb, String dorisTable, SourceSchema schema) { + if (!dorisSystem.tableExists(targetDb, dorisTable)) { + if (changeContext.getDorisTableConf().isConvertUniqToPk() + && CollectionUtil.isNullOrEmpty(schema.primaryKeys) + && !CollectionUtil.isNullOrEmpty(schema.uniqueIndexs)) { + schema.primaryKeys = new ArrayList<>(schema.uniqueIndexs); + } + TableSchema dorisSchema = + DorisSchemaFactory.createTableSchema( + targetDb, + dorisTable, + schema.getFields(), + schema.getPrimaryKeys(), + changeContext.getDorisTableConf(), + schema.getTableComment()); + try { + dorisSystem.createTable(dorisSchema); + } catch (Exception ex) { + handleTableCreationFailure(ex); + } + } + } + + private void handleTableCreationFailure(Exception ex) throws DorisSystemException { + if (ex.getCause() instanceof SQLSyntaxErrorException) { + LOG.warn( + "Doris schema and source table schema are not compatible. Error: {} ", + ex.getCause().toString()); + } else { + throw new DorisSystemException("Failed to create table due to: ", ex); + } + } + Review Comment: My apologies, I assumed both methods were overloads of existing ones and test cases could be omitted, even though I've run the synchronization process locally multiple times. I'll add unit tests shortly. This is my first time submitting code, so I hesitated to modify existing code to avoid disrupting functionality. I'll try to refactor it into a reusable component later to prevent code duplication. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org