-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[connector] flink read support for fluss primary key table changelog auxiliary table/ cdc events #510
base: main
Are you sure you want to change the base?
[connector] flink read support for fluss primary key table changelog auxiliary table/ cdc events #510
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package com.alibaba.fluss.connector.flink.utils; | ||
|
||
import com.alibaba.fluss.client.table.scanner.ScanRecord; | ||
import com.alibaba.fluss.types.RowType; | ||
|
||
import org.apache.flink.table.data.GenericRowData; | ||
import org.apache.flink.table.data.RowData; | ||
|
||
public class ChangelogRowConverter extends FlussRowToFlinkRowConverter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to use the composite design pattern instead of extending in this case, as We can introduce a pure
|
||
public ChangelogRowConverter(RowType rowType) { | ||
super(rowType); | ||
} | ||
|
||
public RowData toFlinkRowData(ScanRecord scanRecord) { | ||
RowData baseRowData = super.toFlinkRowData(scanRecord); | ||
GenericRowData rowWithMetadata = new GenericRowData(baseRowData.getArity() + 3); | ||
rowWithMetadata.setRowKind(baseRowData.getRowKind()); | ||
|
||
for (int i = 0; i < baseRowData.getArity(); i++) { | ||
rowWithMetadata.setField(i, baseRowData.getRawValue(i)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
int baseArity = baseRowData.getArity(); | ||
String changeType; | ||
switch (scanRecord.getRowKind()) { | ||
case INSERT: | ||
changeType = "+I"; | ||
break; | ||
case UPDATE_BEFORE: | ||
changeType = "-U"; | ||
break; | ||
case UPDATE_AFTER: | ||
changeType = "+U"; | ||
break; | ||
case DELETE: | ||
changeType = "-D"; | ||
break; | ||
default: | ||
changeType = "+I"; | ||
break; | ||
} | ||
rowWithMetadata.setField(baseArity, changeType); | ||
rowWithMetadata.setField(baseArity + 1, scanRecord.logOffset()); | ||
rowWithMetadata.setField(baseArity + 2, scanRecord.timestamp()); | ||
|
||
return rowWithMetadata; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,8 @@ | |
import javax.annotation.Nullable; | ||
|
||
import java.io.UncheckedIOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Supplier; | ||
|
@@ -143,6 +145,17 @@ public CompletableFuture<CreateTableResponse> createTable(CreateTableRequest req | |
TableDescriptor tableDescriptor; | ||
try { | ||
tableDescriptor = TableDescriptor.fromJsonBytes(request.getTableJson()); | ||
// Validate reserved column names | ||
List<String> reservedColumns = | ||
Arrays.asList("_change_type", "_log_offset", "_commit_timestamp"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do the check in |
||
for (String columnName : tableDescriptor.getSchema().getColumnNames()) { | ||
if (reservedColumns.contains(columnName)) { | ||
throw new InvalidTableException( | ||
String.format( | ||
"Column name '%s' is reserved for system use.", columnName)); | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
if (e instanceof UncheckedIOException) { | ||
throw new InvalidTableException( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can call
column(..).withComment(..)
here to make the code clean and attach addition column comments.