Skip to content

Commit 0870d05

Browse files
committed
Make hash compatible with pyrel
1 parent fb56490 commit 0870d05

93 files changed

Lines changed: 793 additions & 787 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

meta/src/meta/templates/parser.go.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,9 @@ func (p *Parser) startFragment(fragmentID *pb.FragmentId) *pb.FragmentId {{
364364

365365
func (p *Parser) relationIdFromString(name string) *pb.RelationId {{
366366
hash := sha256.Sum256([]byte(name))
367-
low := binary.LittleEndian.Uint64(hash[:8])
368-
high := binary.LittleEndian.Uint64(hash[8:16])
367+
// Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
368+
high := binary.BigEndian.Uint64(hash[16:24])
369+
low := binary.BigEndian.Uint64(hash[24:32])
369370
relationId := &pb.RelationId{{IdLow: low, IdHigh: high}}
370371

371372
// Store the mapping for the current fragment if we're inside one

meta/src/meta/templates/parser.jl.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ end
228228
function relation_id_from_string(parser::ParserState, name::String)
229229
# Create RelationId from string and track mapping for debug info
230230
hash_bytes = sha256(name)
231-
# Use little-endian to match the Go and Python SDKs.
232-
id_low = htol(reinterpret(UInt64, hash_bytes[1:8])[1])
233-
id_high = htol(reinterpret(UInt64, hash_bytes[9:16])[1])
231+
# Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
232+
id_high = ntoh(reinterpret(UInt64, hash_bytes[17:24])[1])
233+
id_low = ntoh(reinterpret(UInt64, hash_bytes[25:32])[1])
234234
relation_id = Proto.RelationId(id_low, id_high)
235235

236236
# Store the mapping for the current fragment if we're inside one

meta/src/meta/templates/parser.py.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ class Parser:
214214
def relation_id_from_string(self, name: str) -> Any:
215215
"""Create RelationId from string and track mapping for debug info."""
216216
hash_bytes = hashlib.sha256(name.encode()).digest()
217-
id_low = int.from_bytes(hash_bytes[:8], byteorder='little')
218-
id_high = int.from_bytes(hash_bytes[8:16], byteorder='little')
217+
# Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
218+
id_high = int.from_bytes(hash_bytes[16:24], byteorder='big')
219+
id_low = int.from_bytes(hash_bytes[24:32], byteorder='big')
219220
relation_id = logic_pb2.RelationId(id_low=id_low, id_high=id_high)
220221

221222
# Store the mapping for the current fragment if we're inside one

sdks/go/src/hash_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import "testing"
77
func TestRelationIdFromString(t *testing.T) {
88
p := NewParser([]Token{})
99
rid := p.relationIdFromString("my_relation")
10-
if rid.IdLow != 0x5d33996702404f85 {
11-
t.Errorf("id_low: got 0x%016x, want 0x5d33996702404f85", rid.IdLow)
10+
if rid.IdLow != 0xf2fc83ec57cf8fbc {
11+
t.Errorf("id_low: got 0x%016x, want 0xf2fc83ec57cf8fbc", rid.IdLow)
1212
}
13-
if rid.IdHigh != 0x3b9af8e72af633f8 {
14-
t.Errorf("id_high: got 0x%016x, want 0x3b9af8e72af633f8", rid.IdHigh)
13+
if rid.IdHigh != 0x503f7dc862f367b7 {
14+
t.Errorf("id_high: got 0x%016x, want 0x503f7dc862f367b7", rid.IdHigh)
1515
}
1616
}

sdks/go/src/parser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,9 @@ func (p *Parser) startFragment(fragmentID *pb.FragmentId) *pb.FragmentId {
390390

391391
func (p *Parser) relationIdFromString(name string) *pb.RelationId {
392392
hash := sha256.Sum256([]byte(name))
393-
low := binary.LittleEndian.Uint64(hash[:8])
394-
high := binary.LittleEndian.Uint64(hash[8:16])
393+
// Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
394+
high := binary.BigEndian.Uint64(hash[16:24])
395+
low := binary.BigEndian.Uint64(hash[24:32])
395396
relationId := &pb.RelationId{IdLow: low, IdHigh: high}
396397

397398
// Store the mapping for the current fragment if we're inside one

sdks/julia/LogicalQueryProtocol.jl/src/parser.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ end
254254
function relation_id_from_string(parser::ParserState, name::String)
255255
# Create RelationId from string and track mapping for debug info
256256
hash_bytes = sha256(name)
257-
# Use little-endian to match the Go and Python SDKs.
258-
id_low = htol(reinterpret(UInt64, hash_bytes[1:8])[1])
259-
id_high = htol(reinterpret(UInt64, hash_bytes[9:16])[1])
257+
# Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
258+
id_high = ntoh(reinterpret(UInt64, hash_bytes[17:24])[1])
259+
id_low = ntoh(reinterpret(UInt64, hash_bytes[25:32])[1])
260260
relation_id = Proto.RelationId(id_low, id_high)
261261

262262
# Store the mapping for the current fragment if we're inside one

sdks/julia/LogicalQueryProtocol.jl/test/parser_tests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ end
118118
# All SDKs must produce the same id for the same string.
119119
parser = ParserState(Token[])
120120
rid = relation_id_from_string(parser, "my_relation")
121-
@test rid.id_low == 0x5d33996702404f85
122-
@test rid.id_high == 0x3b9af8e72af633f8
121+
@test rid.id_low == 0xf2fc83ec57cf8fbc
122+
@test rid.id_high == 0x503f7dc862f367b7
123123
end
124124

125125
@testitem "Parser - Lexer tokenization" setup=[ParserSetup] begin

sdks/python/src/lqp/gen/parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ def start_fragment(
242242
def relation_id_from_string(self, name: str) -> Any:
243243
"""Create RelationId from string and track mapping for debug info."""
244244
hash_bytes = hashlib.sha256(name.encode()).digest()
245-
id_low = int.from_bytes(hash_bytes[:8], byteorder='little')
246-
id_high = int.from_bytes(hash_bytes[8:16], byteorder='little')
245+
# Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
246+
id_high = int.from_bytes(hash_bytes[16:24], byteorder='big')
247+
id_low = int.from_bytes(hash_bytes[24:32], byteorder='big')
247248
relation_id = logic_pb2.RelationId(id_low=id_low, id_high=id_high)
248249

249250
# Store the mapping for the current fragment if we're inside one

sdks/python/tests/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def test_relation_id_from_string():
1212
"""All SDKs must produce the same id for the same string."""
1313
parser = Parser([])
1414
rid = parser.relation_id_from_string("my_relation")
15-
assert rid.id_low == 0x5D33996702404F85
16-
assert rid.id_high == 0x3B9AF8E72AF633F8
15+
assert rid.id_low == 0xF2FC83EC57CF8FBC
16+
assert rid.id_high == 0x503F7DC862F367B7
1717

1818

1919
@pytest.mark.parametrize("input_file", get_lqp_input_files())

tests/bin/arithmetic.bin

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)