Skip to content

Commit

Permalink
fixed datatype issues in saphana connector (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jithendar12 authored Dec 17, 2022
1 parent 03d0b38 commit bb4fcc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,18 @@ private Schema getSchema(Connection jdbcConnection, TableName tableName, Schema
String dataType = hashMap.get(columnName.toLowerCase());
LOGGER.debug("columnName: " + columnName);
LOGGER.debug("dataType: " + dataType);

InferredColumnType inferredColumnType = InferredColumnType.fromType(dataType);
columnType = inferredColumnType.columnType;
isSpatialDataType = inferredColumnType.isSpatialType;

/**
* converting into VARCHAR not supported by Framework.
* Converting ST_POINT/ST_GEOMETRY data type into VARCHAR
*/
if (columnType == null) {
if (dataType != null
&& (dataType.contains("ST_POINT") || dataType.contains("ST_GEOMETRY"))) {
columnType = Types.MinorType.VARCHAR.getType();
isSpatialDataType = true;
}
if (columnType != null && !SupportedTypes.isSupported(columnType)) {
/*
* converting into VARCHAR for Unsupported data types.
*/
if ((columnType == null) || !SupportedTypes.isSupported(columnType)) {
columnType = Types.MinorType.VARCHAR.getType();
}

Expand Down Expand Up @@ -445,59 +445,6 @@ else if (schemaCase.equalsIgnoreCase(SaphanaConstants.CASE_UPPER) && tableCase.e
}
}

private static class InferredColumnType
{
private final ArrowType columnType;
private final boolean isSpatialType;
public InferredColumnType(ArrowType columnType, boolean isSpatialType)
{
this.columnType = columnType;
this.isSpatialType = isSpatialType;
}

private static InferredColumnType nullType()
{
return new InferredColumnType(null, false);
}

public static InferredColumnType fromType(String dataType)
{
if (dataType != null && (dataType.contains("DECIMAL"))) {
return new InferredColumnType(Types.MinorType.BIGINT.getType(), false);
}
if (dataType != null && (dataType.contains("INTEGER"))) {
return new InferredColumnType(Types.MinorType.INT.getType(), false);
}
if (dataType != null && (dataType.contains("date") || dataType.contains("DATE"))) {
return new InferredColumnType(Types.MinorType.DATEMILLI.getType(), false);
}
/**
* Converting TIMESTAMP data type into TIMESTAMPMILLI
*/
if (dataType != null && (dataType.contains("TIMESTAMP"))
) {
return new InferredColumnType(Types.MinorType.DATEMILLI.getType(), false);
}
/**
* Converting ST_POINT data type into VARBINARY
*/
if (dataType != null
&& (dataType.contains("ST_POINT") || dataType.contains("ST_GEOMETRY"))
) {
return new InferredColumnType(Types.MinorType.VARCHAR.getType(), true);
}
/**
* Converting DAYDATE data type into DATEDAY
*/
if (dataType != null
&& (dataType.contains("DAYDATE") || dataType.contains("DATE"))
) {
return new InferredColumnType(Types.MinorType.DATEDAY.getType(), true);
}
return nullType();
}
}

private String quoteColumnName(String columnName)
{
columnName = columnName.replace(SAPHANA_QUOTE_CHARACTER, SAPHANA_QUOTE_CHARACTER + SAPHANA_QUOTE_CHARACTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ public void doGetTable()
AtomicInteger rowNumber = new AtomicInteger(-1);
ResultSet resultSet = mockResultSet(schema, values, rowNumber);
SchemaBuilder expectedSchemaBuilder = SchemaBuilder.newBuilder();
expectedSchemaBuilder.addField(FieldBuilder.newBuilder("testCol1", org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build());
expectedSchemaBuilder.addField(FieldBuilder.newBuilder("testCol1", org.apache.arrow.vector.types.Types.MinorType.INT.getType()).build());
expectedSchemaBuilder.addField(FieldBuilder.newBuilder("testCol2", org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build());
expectedSchemaBuilder.addField(FieldBuilder.newBuilder("testCol3", org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build());
expectedSchemaBuilder.addField(FieldBuilder.newBuilder("testCol3", org.apache.arrow.vector.types.Types.MinorType.DATEMILLI.getType()).build());
expectedSchemaBuilder.addField(FieldBuilder.newBuilder("testCol4", org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build());

PARTITION_SCHEMA.getFields().forEach(expectedSchemaBuilder::addField);
Expand Down

0 comments on commit bb4fcc7

Please sign in to comment.