Go to h3 v4, Add initial h3 aggregation work

This calculates the summary information of data in h3 nodes and puts it
in the database for fast lookup.
This commit is contained in:
Eli Ribble 2025-11-13 23:48:41 +00:00
parent 7919f0da66
commit e48abb09c0
No known key found for this signature in database
120 changed files with 8516 additions and 1539 deletions

View file

@ -0,0 +1,26 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dberrors
var H3AggregationErrors = &h3AggregationErrors{
ErrUniqueH3AggregationPkey: &UniqueConstraintError{
schema: "",
table: "h3_aggregation",
columns: []string{"id"},
s: "h3_aggregation_pkey",
},
ErrUniqueH3AggregationCellOrganizationIdType_Key: &UniqueConstraintError{
schema: "",
table: "h3_aggregation",
columns: []string{"cell", "organization_id", "type_"},
s: "h3_aggregation_cell_organization_id_type__key",
},
}
type h3AggregationErrors struct {
ErrUniqueH3AggregationPkey *UniqueConstraintError
ErrUniqueH3AggregationCellOrganizationIdType_Key *UniqueConstraintError
}

View file

@ -0,0 +1,110 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dberrors
import (
"context"
"errors"
"testing"
factory "github.com/Gleipnir-Technology/nidus-sync/factory"
models "github.com/Gleipnir-Technology/nidus-sync/models"
"github.com/stephenafamo/bob"
)
func TestH3AggregationUniqueConstraintErrors(t *testing.T) {
if testDB == nil {
t.Skip("No database connection provided")
}
f := factory.New()
tests := []struct {
name string
expectedErr *UniqueConstraintError
conflictMods func(context.Context, *testing.T, bob.Executor, *models.H3Aggregation) factory.H3AggregationModSlice
}{
{
name: "ErrUniqueH3AggregationPkey",
expectedErr: H3AggregationErrors.ErrUniqueH3AggregationPkey,
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.H3Aggregation) factory.H3AggregationModSlice {
shouldUpdate := false
updateMods := make(factory.H3AggregationModSlice, 0, 1)
if shouldUpdate {
if err := obj.Update(ctx, exec, f.NewH3AggregationWithContext(ctx, updateMods...).BuildSetter()); err != nil {
t.Fatalf("Error updating object: %v", err)
}
}
return factory.H3AggregationModSlice{
factory.H3AggregationMods.ID(obj.ID),
}
},
},
{
name: "ErrUniqueH3AggregationCellOrganizationIdType_Key",
expectedErr: H3AggregationErrors.ErrUniqueH3AggregationCellOrganizationIdType_Key,
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.H3Aggregation) factory.H3AggregationModSlice {
shouldUpdate := false
updateMods := make(factory.H3AggregationModSlice, 0, 3)
if shouldUpdate {
if err := obj.Update(ctx, exec, f.NewH3AggregationWithContext(ctx, updateMods...).BuildSetter()); err != nil {
t.Fatalf("Error updating object: %v", err)
}
}
return factory.H3AggregationModSlice{
factory.H3AggregationMods.Cell(obj.Cell),
factory.H3AggregationMods.OrganizationID(obj.OrganizationID),
factory.H3AggregationMods.Type(obj.Type),
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(t.Context())
t.Cleanup(cancel)
tx, err := testDB.Begin(ctx)
if err != nil {
t.Fatalf("Couldn't start database transaction: %v", err)
}
defer func() {
if err := tx.Rollback(ctx); err != nil {
t.Fatalf("Error rolling back transaction: %v", err)
}
}()
var exec bob.Executor = tx
obj, err := f.NewH3AggregationWithContext(ctx, factory.H3AggregationMods.WithParentsCascading()).Create(ctx, exec)
if err != nil {
t.Fatal(err)
}
obj2, err := f.NewH3AggregationWithContext(ctx).Create(ctx, exec)
if err != nil {
t.Fatal(err)
}
err = obj2.Update(ctx, exec, f.NewH3AggregationWithContext(ctx, tt.conflictMods(ctx, t, exec, obj)...).BuildSetter())
if !errors.Is(ErrUniqueConstraint, err) {
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
}
if !errors.Is(tt.expectedErr, err) {
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
}
if !ErrUniqueConstraint.Is(err) {
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
}
if !tt.expectedErr.Is(err) {
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
}
})
}
}

View file

@ -0,0 +1,17 @@
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dberrors
var SpatialRefSyErrors = &spatialRefSyErrors{
ErrUniqueSpatialRefSysPkey: &UniqueConstraintError{
schema: "",
table: "spatial_ref_sys",
columns: []string{"srid"},
s: "spatial_ref_sys_pkey",
},
}
type spatialRefSyErrors struct {
ErrUniqueSpatialRefSysPkey *UniqueConstraintError
}