From 270633c1406a32e787df4941c3fba44e922dc095 Mon Sep 17 00:00:00 2001 From: defector221 Date: Tue, 26 Nov 2024 15:29:24 +0530 Subject: [PATCH] updated TypeHandler --- .../teleport/v2/templates/dml/TypeHandler.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/v2/spanner-to-sourcedb/src/main/java/com/google/cloud/teleport/v2/templates/dml/TypeHandler.java b/v2/spanner-to-sourcedb/src/main/java/com/google/cloud/teleport/v2/templates/dml/TypeHandler.java index 5cbe14fa01..f8a67da28e 100644 --- a/v2/spanner-to-sourcedb/src/main/java/com/google/cloud/teleport/v2/templates/dml/TypeHandler.java +++ b/v2/spanner-to-sourcedb/src/main/java/com/google/cloud/teleport/v2/templates/dml/TypeHandler.java @@ -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); } @@ -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) { @@ -210,7 +209,6 @@ private static Set handleFloatSetType(String colName, JSONObject valuesJs return handleFloat64SetType(colName, valuesJson).stream().map(Double::floatValue).collect(Collectors.toSet()); } - // Handler for ARRAY (also serves as Set) private static List handleDateArrayType(String colName, JSONObject valuesJson) { return valuesJson.getJSONArray(colName).toList().stream() .map(obj -> parseDate(colName, obj, "yyyy-MM-dd")) @@ -221,7 +219,6 @@ private static Set handleDateSetType(String colName, JSONObject valuesJson return new HashSet<>(handleDateArrayType(colName, valuesJson)); } - // Handler for ARRAY (also serves as Set) private static List handleTimestampArrayType(String colName, JSONObject valuesJson) { return valuesJson.getJSONArray(colName).toList().stream() .map(value -> { @@ -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;