Skip to content

Commit

Permalink
updated TypeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
defector221 committed Nov 26, 2024
1 parent a63b04b commit 270633c
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ private static ByteBuffer handleCassandraBlobType(String colName, JSONObject val

}

private static ByteBuffer parseBlobType(String colName, Object colValue){
private static ByteBuffer parseBlobType(String colName, Object colValue) {
byte[] byteArray;

if (colValue instanceof byte[]) {
byteArray = (byte[]) colValue;
} else if (colValue instanceof String) {
byteArray = java.util.Base64.getDecoder().decode((String) colValue);
}
else {
} else {
throw new IllegalArgumentException("Unsupported type for column " + colName);
}

Expand All @@ -67,14 +66,14 @@ private static Date handleCassandraGenericDateType(String colName, JSONObject va
return null;
}

if(formatter == null){
if (formatter == null) {
formatter = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
}

return parseDate(colName, colValue, formatter);
}

private static Date parseDate(String colName, Object colValue, String formatter){
private static Date parseDate(String colName, Object colValue, String formatter) {
Date date;

if (colValue instanceof String) {
Expand Down Expand Up @@ -210,7 +209,6 @@ private static Set<Float> handleFloatSetType(String colName, JSONObject valuesJs
return handleFloat64SetType(colName, valuesJson).stream().map(Double::floatValue).collect(Collectors.toSet());
}

// Handler for ARRAY<Date> (also serves as Set<Date>)
private static List<Date> handleDateArrayType(String colName, JSONObject valuesJson) {
return valuesJson.getJSONArray(colName).toList().stream()
.map(obj -> parseDate(colName, obj, "yyyy-MM-dd"))
Expand All @@ -221,7 +219,6 @@ private static Set<Date> handleDateSetType(String colName, JSONObject valuesJson
return new HashSet<>(handleDateArrayType(colName, valuesJson));
}

// Handler for ARRAY<Timestamp> (also serves as Set<Timestamp>)
private static List<Timestamp> handleTimestampArrayType(String colName, JSONObject valuesJson) {
return valuesJson.getJSONArray(colName).toList().stream()
.map(value -> {
Expand Down Expand Up @@ -307,14 +304,14 @@ public static Object getColumnValueByType(
case "decimal":
case "blob":
case "boolean":
response = colValue;
response = colValue;
break;
case "date":
response = convertToCassandraDate((Date) colValue);
break;

default:
throw new IllegalArgumentException("Invalid column " + colName + " do not have mapping created for "+columnType);
throw new IllegalArgumentException("Invalid column " + colName + " do not have mapping created for " + columnType);
}

return response;
Expand Down

0 comments on commit 270633c

Please sign in to comment.