laskoviymishka commented on code in PR #2745:
URL: https://github.com/apache/iceberg-go/pull/2745#discussion_r4730169084


##########
literal_set_internal_test.go:
##########
@@ -80,3 +81,79 @@ func TestLiteralSetVariant(t *testing.T) {
                assert.True(t, set.Contains(VariantLiteral(right)))
        })
 }
+
+func TestLiteralSetKeepsDifferentByteLiteralTypes(t *testing.T) {
+       // These four literals have identical payloads, but Equals distinguishes
+       // binary, fixed, geometry and geography values.
+       payload := []byte("1234567890abcdef")
+       geometry, err := LiteralFromBytes(GeometryType{}, payload)
+       require.NoError(t, err)
+       geography, err := LiteralFromBytes(GeographyType{}, payload)
+       require.NoError(t, err)
+
+       binary := BinaryLiteral(payload)
+       fixed := FixedLiteral(payload)
+       literals := []Literal{binary, fixed, geometry, geography}

Review Comment:
   Could a `VariantLiteral` join this mix too? Nothing puts a variant next to 
the other byte-backed kinds, so the `variantLiteralHash` wrap in `addliteral` 
has no test behind it if the key types get reshuffled later.



##########
utils.go:
##########
@@ -122,6 +122,36 @@ var lzseed = maphash.MakeSeed()
 
 type literalSet map[any]struct{ orig Literal }
 
+// Using distinct named types keeps byte-identical literals of different
+// Iceberg types from replacing one another in the interface-keyed map.
+// Geo keys also include the logical type because CRS and edge interpolation
+// are part of GeoLiteral.Equals.
+type (
+       binaryLiteralHash  uint64
+       fixedLiteralHash   uint64
+       variantLiteralHash uint64
+       geoLiteralHash     struct {
+               geography bool
+               crs       string
+               algorithm string
+               hash      uint64
+       }
+)
+
+func geoSetKey(v GeoLiteral) geoLiteralHash {
+       key := geoLiteralHash{hash: maphash.Bytes(lzseed, v.Value())}
+       switch typ := v.Type().(type) {
+       case GeometryType:
+               key.crs = typ.CRS()
+       case GeographyType:
+               key.geography = true
+               key.crs = typ.CRS()
+               key.algorithm = typ.Algorithm()
+       }

Review Comment:
   Could we note here that only the two spatial types reach this switch? The 
only constructor, 
[`LiteralFromBytes`](https://github.com/apache/iceberg-go/blob/cbdb5b42b7284a06fca1896e18c7b637f5828a7a/literals.go#L189-L204),
 sets one of them, so a hash-only key can't happen today.
   
   ```suggestion
        default:
                // unreachable: GeoLiteral is only built with GeometryType or 
GeographyType
        }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to