-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new class to store column overrides
- Loading branch information
Showing
4 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
sink-connector/src/main/java/com/altinity/clickhouse/sink/connector/db/ColumnOverrides.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.altinity.clickhouse.sink.connector.db; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Class that maps overrides of column data types. | ||
*/ | ||
public class ColumnOverrides { | ||
|
||
static Map<String, String> columnOverridesMap = new HashMap<>(); | ||
|
||
static { | ||
columnOverridesMap.put("DateTime", "String"); | ||
columnOverridesMap.put("Nullable(DateTime", "Nullable(String)"); | ||
} | ||
public ColumnOverrides() { | ||
|
||
} | ||
|
||
public static String getColumnOverride(String dataType) { | ||
for(String key: columnOverridesMap.keySet()){ | ||
if(dataType.contains(key)) { | ||
return columnOverridesMap.get(key); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...onnector/src/test/java/com/altinity/clickhouse/sink/connector/db/ColumnOverridesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.altinity.clickhouse.sink.connector.db; | ||
|
||
import com.clickhouse.data.ClickHouseDataType; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ColumnOverridesTest { | ||
|
||
@Test | ||
public void testMapping() { | ||
String dateTime64Type = "DateTime64(3)"; | ||
String dataTime64OverrideType = ColumnOverrides.getColumnOverride(dateTime64Type); | ||
Assert.assertTrue(dataTime64OverrideType.equalsIgnoreCase("String")); | ||
|
||
String nullableDateTime64Type = "Nullable(DateTime64)"; | ||
String nullableDataTime64OverrideType = ColumnOverrides.getColumnOverride(nullableDateTime64Type); | ||
Assert.assertTrue(nullableDataTime64OverrideType.equalsIgnoreCase("Nullable(String)")); | ||
|
||
Assert.assertTrue(ColumnOverrides.getColumnOverride(ClickHouseDataType.DateTime.name()).equalsIgnoreCase("String")); | ||
Assert.assertNull(ColumnOverrides.getColumnOverride(ClickHouseDataType.Decimal.name())); | ||
|
||
|
||
Assert.assertNull(ColumnOverrides.getColumnOverride(ClickHouseDataType.Int16.name())); | ||
Assert.assertTrue(ColumnOverrides.getColumnOverride(ClickHouseDataType.DateTime32.name()).equalsIgnoreCase(ClickHouseDataType.String.name())); | ||
} | ||
} |