This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new e0b4e1711 [flink] ogg support compute_column (#1900)
e0b4e1711 is described below

commit e0b4e171115303bb22f75984190fab6ed7f35e5e
Author: monster <[email protected]>
AuthorDate: Mon Aug 28 22:24:04 2023 +0800

    [flink] ogg support compute_column (#1900)
---
 .../shortcodes/generated/compute_column.html       | 10 ++---
 .../cdc/kafka/formats/ogg/OggRecordParser.java     |  2 +-
 .../cdc/kafka/KafkaOggSyncTableActionITCase.java   | 45 ++++++++++++++++++++++
 .../kafka/ogg/table/computedcolumn/ogg-data-1.txt  | 19 +++++++++
 4 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/docs/layouts/shortcodes/generated/compute_column.html 
b/docs/layouts/shortcodes/generated/compute_column.html
index f9bf8697f..f086c65bc 100644
--- a/docs/layouts/shortcodes/generated/compute_column.html
+++ b/docs/layouts/shortcodes/generated/compute_column.html
@@ -27,23 +27,23 @@ under the License.
     <tbody>
     <tr>
         <td><h5>year(date-column)</h5></td>
-        <td>Extract year from a DATE, DATETIME or TIMESTAMP. Output is an INT 
value represent the year.</td>
+        <td>Extract year from a DATE, DATETIME or TIMESTAMP (or its 
corresponding string format). Output is an INT value represent the year.</td>
     </tr>
     <tr>
         <td><h5>month(date-column)</h5></td>
-        <td>Extract month of year from a DATE, DATETIME or TIMESTAMP. Output 
is an INT value represent the month of year.</td>
+        <td>Extract month of year from a DATE, DATETIME or TIMESTAMP (or its 
corresponding string format). Output is an INT value represent the month of 
year.</td>
     </tr>
     <tr>
         <td><h5>day(date-column)</h5></td>
-        <td>Extract day of month from a DATE, DATETIME or TIMESTAMP. Output is 
an INT value represent the day of month.</td>
+        <td>Extract day of month from a DATE, DATETIME or TIMESTAMP (or its 
corresponding string format). Output is an INT value represent the day of 
month.</td>
     </tr>
     <tr>
         <td><h5>hour(date-column)</h5></td>
-        <td>Extract hour from a DATE, DATETIME or TIMESTAMP. Output is an INT 
value represent the hour.</td>
+        <td>Extract hour from a DATE, DATETIME or TIMESTAMP (or its 
corresponding string format). Output is an INT value represent the hour.</td>
     </tr>
     <tr>
         <td><h5>date_format(date-column)</h5></td>
-        <td>Convert date format from a DATE, DATETIME or TIMESTAMP. Output is 
a string value in converted date format.</td>
+        <td>Convert date format from a DATE, DATETIME or TIMESTAMP (or its 
corresponding string format). Output is a string value in converted date 
format.</td>
     </tr>
     <tr>
         <td><h5>substring(column,beginInclusive)</h5></td>
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/kafka/formats/ogg/OggRecordParser.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/kafka/formats/ogg/OggRecordParser.java
index 9e7b67631..47a2a8cb6 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/kafka/formats/ogg/OggRecordParser.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/kafka/formats/ogg/OggRecordParser.java
@@ -213,7 +213,7 @@ public class OggRecordParser extends RecordParser {
                     resultMap.put(
                             computedColumn.columnName(),
                             
computedColumn.eval(resultMap.get(computedColumn.fieldReference())));
-                    paimonFieldTypes.put(computedColumn.columnName(), 
STRING_DATA_TYPE);
+                    paimonFieldTypes.put(computedColumn.columnName(), 
computedColumn.columnType());
                 });
 
         return resultMap;
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/kafka/KafkaOggSyncTableActionITCase.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/kafka/KafkaOggSyncTableActionITCase.java
index bf7dbdfc7..49fa85440 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/kafka/KafkaOggSyncTableActionITCase.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/kafka/KafkaOggSyncTableActionITCase.java
@@ -516,4 +516,49 @@ public class KafkaOggSyncTableActionITCase extends 
KafkaActionITCaseBase {
                                 "+I[104, hammer, 12oz carpenter's hammer, 
0.75]");
         waitForResult(expected, table, rowType, primaryKeys);
     }
+
+    @Test
+    @Timeout(60)
+    public void testComputedColumn() throws Exception {
+        String topic = "computed_column";
+        createTestTopic(topic, 1, 1);
+
+        List<String> lines = 
readLines("kafka/ogg/table/computedcolumn/ogg-data-1.txt");
+        try {
+            writeRecordsToKafka(topic, lines);
+        } catch (Exception e) {
+            throw new Exception("Failed to write canal data to Kafka.", e);
+        }
+        Map<String, String> kafkaConfig = getBasicKafkaConfig();
+        kafkaConfig.put("value.format", "ogg-json");
+        kafkaConfig.put("topic", topic);
+        KafkaSyncTableAction action =
+                new KafkaSyncTableAction(
+                        kafkaConfig,
+                        warehouse,
+                        database,
+                        tableName,
+                        Collections.singletonList("_year"),
+                        Arrays.asList("_id", "_year"),
+                        Collections.singletonList("_year=year(_date)"),
+                        Collections.emptyMap(),
+                        getBasicTableConfig());
+        action.build(env);
+        JobClient client = env.executeAsync();
+        waitJobRunning(client);
+
+        RowType rowType =
+                RowType.of(
+                        new DataType[] {
+                            DataTypes.STRING().notNull(),
+                            DataTypes.STRING(),
+                            DataTypes.INT().notNull()
+                        },
+                        new String[] {"_id", "_date", "_year"});
+        waitForResult(
+                Collections.singletonList("+I[101, 2023-03-23, 2023]"),
+                getFileStoreTable(tableName),
+                rowType,
+                Arrays.asList("_id", "_year"));
+    }
 }
diff --git 
a/paimon-flink/paimon-flink-common/src/test/resources/kafka/ogg/table/computedcolumn/ogg-data-1.txt
 
b/paimon-flink/paimon-flink-common/src/test/resources/kafka/ogg/table/computedcolumn/ogg-data-1.txt
new file mode 100644
index 000000000..7dead51ef
--- /dev/null
+++ 
b/paimon-flink/paimon-flink-common/src/test/resources/kafka/ogg/table/computedcolumn/ogg-data-1.txt
@@ -0,0 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+{"table":"OGG.TBL_TEST","pos":"00000000000000000000143","primary_keys":["_id"],"after":{"_id":101,"_date":"2023-03-23"},"op_type":"I",
 "current_ts":"2020-05-13T13:39:35.766000", "op_ts":"2020-05-13 
15:40:06.000000"}

Reply via email to