Skip to content

Commit

Permalink
[Feature][Jdbc] Add junit test for jdbc-iris
Browse files Browse the repository at this point in the history
  • Loading branch information
dailai committed May 8, 2024
1 parent 147b913 commit 4a7ffb4
Show file tree
Hide file tree
Showing 3 changed files with 566 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public class IrisCatalog extends AbstractJdbcCatalog {

private static final String LIST_TABLES_SQL_TEMPLATE =
"SELECT TABLE_SCHEMA,TABLE_NAME FROM INFORMATION_SCHEMA.Tables WHERE TABLE_SCHEMA='%s' and TABLE_TYPE != 'SYSTEM TABLE' and TABLE_TYPE != 'SYSTEM VIEW';";
// private static final String SELECT_COLUMNS_SQL_TEMPLATE =
// "select * from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME
// = '%s';";

public IrisCatalog(
String catalogName, String username, String password, JdbcUrlUtil.UrlInfo urlInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.seatunnel.common.exception.CommonError;
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.DatabaseIdentifier;

import com.google.auto.service.AutoService;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;
Expand All @@ -37,6 +38,7 @@
* https://docs.intersystems.com/iris20241/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_datatype#RSQL_datatype_view_data_type_mappings_to_intersyst
*/
@Slf4j
@AutoService(TypeConverter.class)
public class IrisTypeConverter implements TypeConverter<BasicTypeDefine> {
// ============================data types=====================
public static final String IRIS_NULL = "NULL";
Expand Down Expand Up @@ -132,16 +134,19 @@ public String identifier() {

@Override
public Column convert(BasicTypeDefine typeDefine) {
Long typeDefineLength = typeDefine.getLength();
PhysicalColumn.PhysicalColumnBuilder builder =
PhysicalColumn.builder()
.name(typeDefine.getName())
.sourceType(typeDefine.getColumnType())
.columnLength(typeDefine.getLength())
.columnLength(typeDefineLength)
.scale(typeDefine.getScale())
.nullable(typeDefine.isNullable())
.defaultValue(typeDefine.getDefaultValue())
.comment(typeDefine.getComment());
String irisDataType = typeDefine.getDataType().toUpperCase();
long charOrBinaryLength =
Objects.nonNull(typeDefineLength) && typeDefineLength > 0 ? typeDefineLength : 1;
switch (irisDataType) {
case IRIS_NULL:
builder.dataType(BasicType.VOID_TYPE);
Expand Down Expand Up @@ -208,7 +213,7 @@ public Column convert(BasicTypeDefine typeDefine) {
case IRIS_GUID:
case IRIS_CHARACTER:
builder.dataType(BasicType.STRING_TYPE);
builder.columnLength(typeDefine.getLength() > 0 ? typeDefine.getLength() : 1);
builder.columnLength(charOrBinaryLength);
break;
case IRIS_NTEXT:
case IRIS_CLOB:
Expand Down Expand Up @@ -240,7 +245,7 @@ public Column convert(BasicTypeDefine typeDefine) {
case IRIS_RAW:
case IRIS_VARBINARY:
builder.dataType(PrimitiveByteArrayType.INSTANCE);
builder.columnLength(typeDefine.getLength() > 0 ? typeDefine.getLength() : 1);
builder.columnLength(charOrBinaryLength);
break;
case IRIS_LONGVARBINARY:
case IRIS_BLOB:
Expand All @@ -262,8 +267,11 @@ public BasicTypeDefine reconvert(Column column) {
BasicTypeDefine.BasicTypeDefineBuilder builder =
BasicTypeDefine.builder()
.name(column.getName())
.precision(column.getColumnLength())
.length(column.getColumnLength())
.nullable(column.isNullable())
.comment(column.getComment())
.scale(column.getScale())
.defaultValue(column.getDefaultValue());
switch (column.getDataType().getSqlType()) {
case NULL:
Expand Down

0 comments on commit 4a7ffb4

Please sign in to comment.