Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ private Map<String, List<Map<String, Object>>> getExpectedData() {
"-1.9876542E38", "1.9876542E38", "NaN", "-Infinity", "Infinity", "2.34", "NULL"));
// float4_to_float32 is commented out to avoid failing the test case; data is not migrated at
// all
// result.put(
// "float4_to_float32",
// createRows(
// "-1.9876542E38", "1.9876542E38", "NaN", "-Infinity", "Infinity", "2.34", "NULL"));
result.put(
Comment thread
jsuhani-2026 marked this conversation as resolved.
"float4_to_float32",
createRows(
"-1.9876542E38", "1.9876542E38", "NaN", "-Infinity", "Infinity", "2.34", "NULL"));
result.put(
"float4_to_string",
createRows(
Expand Down Expand Up @@ -304,10 +304,10 @@ private Map<String, List<Map<String, Object>>> getExpectedData() {
"-1.9876542E38", "1.9876542E38", "NaN", "-Infinity", "Infinity", "5.67", "NULL"));
// float4_to_float32 is commented out to avoid failing the test case; data is not migrated at
// all
// result.put(
// "real_to_float32",
// createRows(
// "-1.9876542E38", "1.9876542E38", "NaN", "-Infinity", "Infinity", "5.67", "NULL"));
result.put(
"real_to_float32",
createRows(
"-1.9876542E38", "1.9876542E38", "NaN", "-Infinity", "Infinity", "5.67", "NULL"));
result.put(
"real_to_string",
createRows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ static Map<Type, AvroToValueFunction> getPgMap() {
pgFunctions.put(
Type.pgInt8(),
(recordValue, fieldSchema) -> Value.int64(avroFieldToLong(recordValue, fieldSchema)));
pgFunctions.put(
Type.pgFloat4(),
(recordValue, fieldSchema) -> Value.float32(avroFieldToFloat32(recordValue, fieldSchema)));
pgFunctions.put(
Type.pgFloat8(),
(recordValue, fieldSchema) -> Value.float64(avroFieldToDouble(recordValue, fieldSchema)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.google.cloud.teleport.v2.spanner.migrations.avro.AvroToValueMapper.avroArrayFieldToSpannerArray;
import static com.google.cloud.teleport.v2.spanner.migrations.avro.AvroToValueMapper.getGsqlMap;
import static com.google.cloud.teleport.v2.spanner.migrations.avro.AvroToValueMapper.getPgMap;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -198,10 +199,16 @@ public void testAvroFieldToFloat_ValidFloat32Input() {
AvroToValueMapper.avroFieldToFloat32((Double) 3.14, SchemaBuilder.builder().floatType());
assertEquals("Test float input", (Float) 3.14f, result);

// Test a valid GSQL float32 to float32 mapping
Value value =
getGsqlMap().get(Type.float32()).apply(3.14f, SchemaBuilder.builder().floatType());
assertEquals("Test float input", Value.float32(3.14f), value);

// Test a valid PostgreSQL float4/real to float32 mapping
Value pgValue =
getPgMap().get(Type.pgFloat4()).apply(5.75f, SchemaBuilder.builder().floatType());
assertEquals("Test float input", Value.float32(5.75f), pgValue);

result = AvroToValueMapper.avroFieldToFloat32("456.346", SchemaBuilder.builder().doubleType());
assertEquals("Test string input", (Float) 456.346f, result);

Expand Down
Loading