Skip to content
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

[BitSail][Feature] Support byte in type system #382

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@

package com.bytedance.bitsail.conector.legacy.fake.source;

import com.bytedance.bitsail.common.model.ColumnInfo;
import com.bytedance.bitsail.common.type.BitSailTypeInfoConverter;
import com.bytedance.bitsail.connector.legacy.fake.source.FakeSource;
import com.bytedance.bitsail.flink.core.typeinfo.PrimitiveColumnTypeInfo;
import com.bytedance.bitsail.flink.core.typeutils.ColumnFlinkTypeInfoUtil;

import org.apache.flink.api.java.typeutils.RowTypeInfo;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -61,4 +68,13 @@ public void testConstructRandomValueWithUniqueCheck() {
Assert.assertEquals(5678, actualValue);
Assert.assertTrue(existValues.contains("5678"));
}

@Test
public void testSupportByteType() {
List<ColumnInfo> columnInfos = new ArrayList<>();
ColumnInfo age = new ColumnInfo("age", "byte");
columnInfos.add(age);
RowTypeInfo rowTypeInfo = ColumnFlinkTypeInfoUtil.getRowTypeInformation(new BitSailTypeInfoConverter(), columnInfos);
Assert.assertTrue(rowTypeInfo.getFieldTypes()[0] instanceof PrimitiveColumnTypeInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ public Object convert(Schema schema, Object object) {
return object;
}
};
} else if (BasicTypeInfo.BYTE_TYPE_INFO.getTypeClass().equals(typeClass)) {
converter =
new RowToAvroConverter() {
private static final long serialVersionUID = 1L;

@Override
public Object convert(Schema schema, Object object) {
return Integer.valueOf(Long.toString((Long) object));
}
};
} else if (BasicTypeInfo.BIG_INT_TYPE_INFO.getTypeClass().equals(typeClass)) {
converter =
new RowToAvroConverter() {
Expand Down Expand Up @@ -255,4 +265,3 @@ public interface RowToAvroConverter extends Serializable {
Object convert(Schema schema, Object object);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private static DataType baseType2DataType(String type) {
case "tinyint":
case "int":
return DataTypes.INT();
case "byte":
return DataTypes.TINYINT();
case "long":
case "bigint":
return DataTypes.BIGINT();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class TypeInfoColumnBridge {
PrimitiveColumnTypeInfo.LONG_COLUMN_TYPE_INFO);
COLUMN_BRIDGE_TYPE_INFO_MAPPING.put(TypeInfos.LONG_TYPE_INFO,
PrimitiveColumnTypeInfo.LONG_COLUMN_TYPE_INFO);
COLUMN_BRIDGE_TYPE_INFO_MAPPING.put(TypeInfos.BYTE_TYPE_INFO,
PrimitiveColumnTypeInfo.LONG_COLUMN_TYPE_INFO);
COLUMN_BRIDGE_TYPE_INFO_MAPPING.put(TypeInfos.BIG_INTEGER_TYPE_INFO,
PrimitiveColumnTypeInfo.LONG_COLUMN_TYPE_INFO);

Expand Down