Skip to content

Commit

Permalink
<feat>: support visibility columns (#3976)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoma20082008 committed May 13, 2022
1 parent 8804647 commit bac016f
Showing 1 changed file with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.taobao.tddl.dbsync.binlog.event;

import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

import com.taobao.tddl.dbsync.binlog.LogBuffer;
import com.taobao.tddl.dbsync.binlog.LogEvent;

/**
* In row-based mode, every row operation event is preceded by a
* Table_map_log_event which maps a table definition to a number. The table
Expand Down Expand Up @@ -343,6 +342,7 @@ public static final class ColumnInfo {
public int charset; // 可以通过CharsetUtil进行转化
public int geoType;
public boolean nullable;
public boolean visibility;

@Override
public String toString() {
Expand Down Expand Up @@ -382,6 +382,12 @@ public String toString() {
public static final int SIMPLE_PRIMARY_KEY = 8;
// Primary key with prefix
public static final int PRIMARY_KEY_WITH_PREFIX = 9;
// Character set of enum and set columns, optimized to minimize space when many columns have the same charset.
public static final int ENUM_AND_SET_DEFAULT_CHARSET = 10;
// Character set of enum and set columns, optimized to minimize space when many columns have the same charset.
public static final int ENUM_AND_SET_COLUMN_CHARSET = 11;
// Flag to indicate column visibility attribute
public static final int COLUMN_VISIBILITY = 12;

private int default_charset;
private boolean existOptionalMetaData = false;
Expand Down Expand Up @@ -484,6 +490,15 @@ public TableMapLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLog
case PRIMARY_KEY_WITH_PREFIX:
parse_pk_with_prefix(buffer, len);
break;
case ENUM_AND_SET_DEFAULT_CHARSET:
parse_default_charset(buffer, len);
break;
case ENUM_AND_SET_COLUMN_CHARSET:
parse_column_charset(buffer, len);
break;
case COLUMN_VISIBILITY:
parse_column_visibility(buffer, len);
break;
default:
throw new IllegalArgumentException("unknow type : " + type);
}
Expand Down Expand Up @@ -648,6 +663,20 @@ private List<Integer> parse_column_charset(LogBuffer buffer, int length) {
return datas;
}


private void parse_column_visibility(LogBuffer buffer, int length) {
List<Boolean> data = new ArrayList<>(columnInfo.length);
for (int i = 0; i < length; i++) {
int ut = buffer.getUint8();
for (int c = 0x80; c != 0; c >>= 1) {
data.add((ut & c) > 0);
}
}
for (int i = 0; i < columnCnt; i++) {
columnInfo[i].visibility = data.get(i);
}
}

private void parse_column_name(LogBuffer buffer, int length) {
// stores column names extracted from field
int limit = buffer.position() + length;
Expand Down

0 comments on commit bac016f

Please sign in to comment.